diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-19 15:10:07 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-19 15:10:07 +0800 |
commit | 2c07a7a12bf840e1a90abc117fd5e69866f76fdb (patch) | |
tree | e3283b21e345a5d6a3fa062bd1ccb5503888b61f | |
parent | a1c4ebfb23152e23bf556811aad39bf917c5cb60 (diff) | |
download | lua-language-server-2c07a7a12bf840e1a90abc117fd5e69866f76fdb.zip |
自动完成和全局变量相关的一些bug
-rw-r--r-- | script-beta/core/completion.lua | 12 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 6 | ||||
-rw-r--r-- | test-beta/completion/init.lua | 31 |
3 files changed, 44 insertions, 5 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index 479d6ab4..610279db 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -425,6 +425,9 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res if isSameSource(ast, src, start) then -- 由于fastGlobal的优化,全局变量只会找出一个值,有可能找出自己 -- 所以遇到自己的时候重新找一下有没有其他定义 + if not guide.isGlobal(src) then + goto CONTINUE + end if #vm.getGlobals(key) <= 1 then goto CONTINUE end @@ -438,14 +441,19 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res end local last = fields[name] if not last then - fields[name] = src + if guide.isGlobal(src) then + fields[name] = vm.getDefs(src, 'deep')[1] or src + else + fields[name] = src + end goto CONTINUE end if src.type == 'tablefield' or src.type == 'setfield' or src.type == 'tableindex' or src.type == 'setindex' - or src.type == 'setmethod' then + or src.type == 'setmethod' + or src.type == 'setglobal' then fields[name] = src goto CONTINUE end diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 3cbdf4d8..1de15a3b 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -1215,7 +1215,11 @@ function m.isGlobal(source) end end if source.type == 'field' then - local node = source.parent.node + source = source.parent + end + if source.type == 'getfield' + or source.type == 'setfield' then + local node = source.node if node and node.special == '_G' then return true end diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua index 7d1ca368..50afb137 100644 --- a/test-beta/completion/init.lua +++ b/test-beta/completion/init.lua @@ -1201,9 +1201,36 @@ io$ (EXISTS) TEST [[ -loadfile$ +loadstring$ ]] -(EXISTS) +{ + { + label = 'loadstring', + kind = define.CompletionItemKind.Function, + deprecated = true, + }, + { + label = 'loadstring()', + kind = define.CompletionItemKind.Snippet, + deprecated = true, + }, +} + +TEST [[ +function loadstring() +end +loadstring$ +]] +{ + { + label = 'loadstring', + kind = define.CompletionItemKind.Function, + }, + { + label = 'loadstring()', + kind = define.CompletionItemKind.Snippet, + }, +} TEST [[ debug.setcsta$ |