diff options
author | sumneko <sumneko@hotmail.com> | 2022-02-08 21:39:52 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2022-02-08 21:39:52 +0800 |
commit | ee476c7f4fb29ab6cf6e77205745428c0e2a8601 (patch) | |
tree | cb9d2b2b63b30cb55f030b463baee45acb42d683 | |
parent | 01fbaf633deb9494c0b72906e71bac9f73b318ae (diff) | |
download | lua-language-server-ee476c7f4fb29ab6cf6e77205745428c0e2a8601.zip |
fix #937
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | script/core/completion/completion.lua | 41 | ||||
-rw-r--r-- | test/completion/common.lua | 7 | ||||
-rw-r--r-- | test/completion/init.lua | 10 |
4 files changed, 42 insertions, 19 deletions
diff --git a/changelog.md b/changelog.md index aaf85af2..6f66f37d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # changelog +## 2.6.4 +* `FIX` [#937](https://github.com/sumneko/lua-language-server/issues/937) + ## 2.6.3 `2022-1-25` * `FIX` new files are not loaded correctly diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index 099bdc47..800c11a1 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1221,13 +1221,20 @@ end ---@async local function tryWord(state, position, triggerCharacter, results) + if triggerCharacter == '(' + or triggerCharacter == '#' + or triggerCharacter == ',' + or triggerCharacter == '{' then + return + end local text = state.lua local offset = guide.positionToOffset(state, position) local finish = lookBackward.skipSpace(text, offset) local word, start = lookBackward.findWord(text, offset) local startPos if not word then - return nil + word = '' + startPos = position else startPos = guide.offsetToPosition(state, start - 1) end @@ -1241,17 +1248,17 @@ local function tryWord(state, position, triggerCharacter, results) else local parent, oop = findParent(state, startPos) if parent then - if not hasSpace then - checkField(state, word, startPos, position, parent, oop, results) - end + checkField(state, word, startPos, position, parent, oop, results) elseif isFuncArg(state, position) then checkProvideLocal(state, word, startPos, results) checkFunctionArgByDocParam(state, word, startPos, results) else local afterLocal = isAfterLocal(state, startPos) - local stop = checkKeyWord(state, startPos, position, word, hasSpace, afterLocal, results) - if stop then - return + if triggerCharacter ~= nil then + local stop = checkKeyWord(state, startPos, position, word, hasSpace, afterLocal, results) + if stop then + return + end end if not hasSpace then if afterLocal then @@ -1265,7 +1272,7 @@ local function tryWord(state, position, triggerCharacter, results) end end end - if not hasSpace then + if not hasSpace and (#results == 0 or word ~= '') then checkCommon(state, word, position, results) end end @@ -1282,15 +1289,15 @@ local function trySymbol(state, position, results) return nil end local startPos = guide.offsetToPosition(state, start) - if symbol == '.' - or symbol == ':' then - local parent, oop = findParent(state, startPos) - if parent then - tracy.ZoneBeginN 'completion.trySymbol' - checkField(state, '', startPos, position, parent, oop, results) - tracy.ZoneEnd() - end - end + --if symbol == '.' + --or symbol == ':' then + -- local parent, oop = findParent(state, startPos) + -- if parent then + -- tracy.ZoneBeginN 'completion.trySymbol' + -- checkField(state, '', startPos, position, parent, oop, results) + -- tracy.ZoneEnd() + -- end + --end if symbol == '(' then checkFunctionArgByDocParam(state, '', startPos, results) end diff --git a/test/completion/common.lua b/test/completion/common.lua index 2d887b68..bfb987c6 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -3067,3 +3067,10 @@ require '<??>' (function (results) assert(#results == 11, require 'utility'.dump(results)) end) + +TEST [[ +AAA = 1 + +<??> +]] +(EXISTS) diff --git a/test/completion/init.lua b/test/completion/init.lua index 95da8890..3d0c4df6 100644 --- a/test/completion/init.lua +++ b/test/completion/init.lua @@ -1,6 +1,7 @@ local core = require 'core.completion' local files = require 'files' local catch = require 'catch' +local guide = require 'parser.guide' EXISTS = {'EXISTS'} @@ -68,12 +69,17 @@ function TEST(script) local newScript, catched = catch(script, '?') files.setText('', newScript) - local inputPos = catched['?'][1][1] + local state = files.getState('') + local inputPos = catched['?'][1][2] if ContinueTyping then local triggerCharacter = script:sub(inputPos - 1, inputPos - 1) core.completion('', inputPos, triggerCharacter) end - local triggerCharacter = script:sub(inputPos, inputPos) + local offset = guide.positionToOffset(state, inputPos) + local triggerCharacter = script:sub(offset, offset) + if triggerCharacter == '\n' then + triggerCharacter = nil + end local result = core.completion('', inputPos, triggerCharacter) if not expect then |