diff options
author | sumneko <sumneko@hotmail.com> | 2021-12-21 22:49:59 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2021-12-21 22:49:59 +0800 |
commit | b7344640a0ab9a07551ee5ebc435657b45659553 (patch) | |
tree | 0fef08a7dbb0a115e0e1249b6123fd529cf1fc58 /script/core/completion | |
parent | c47baf932309a05673b7931fdf6a1be207fb7bc4 (diff) | |
parent | ec4f497aa2624d9dce29e1de0cfd28ecd85e7df3 (diff) | |
download | lua-language-server-b7344640a0ab9a07551ee5ebc435657b45659553.zip |
Merge remote-tracking branch 'origin/master' into multi-workspace
Diffstat (limited to 'script/core/completion')
-rw-r--r-- | script/core/completion/completion.lua | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index dc005b52..d0bf5164 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1064,14 +1064,14 @@ local function tryLabelInString(label, source) if not source or source.type ~= 'string' then return label end - local str = parser.grammar(label, 'String') - if not str then + local state = parser.parse(label, 'String') + if not state or not state.ast then return label end - if not matchKey(source[1], str[1]) then + if not matchKey(source[1], state.ast[1]) then return nil end - return util.viewString(str[1], source[2]) + return util.viewString(state.ast[1], source[2]) end local function mergeEnums(a, b, source) @@ -1354,20 +1354,6 @@ local function getCallEnumsAndFuncs(source, index, oop, call) end end if source.type == 'doc.type.function' then - --[[ - always use literal index, that is: - ``` - ---@class Class - ---@field f(x: number, y: boolean) - local c - - c.f(1, true) -- correct - c:f(1, true) -- also correct - ``` - --]] - if oop then - index = index - 1 - end local arg = source.args[index] if arg and arg.extends then return pushCallEnumsAndFuncs(vm.getDefs(arg.extends)) @@ -1959,6 +1945,7 @@ local function makeCache(uri, position, results) cache.position= position cache.word = word:lower() cache.length = #word + cache.uri = uri end local function isValidCache(word, result) @@ -1983,6 +1970,9 @@ local function getCache(uri, position) if not cache.results then return nil end + if cache.uri ~= uri then + return nil + end local text = files.getText(uri) local state = files.getState(uri) local word = lookBackward.findWord(text, guide.positionToOffset(state, position)) @@ -2058,6 +2048,9 @@ local function completion(uri, position, triggerCharacter) await.delay() tracy.ZoneBeginN 'completion #1' local state = files.getState(uri) + if not state then + return nil + end results = {} clearStack() tracy.ZoneEnd() |