diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/core/completion.lua | 13 | ||||
-rw-r--r-- | test/completion/init.lua | 28 |
3 files changed, 38 insertions, 4 deletions
diff --git a/changelog.md b/changelog.md index 88e93759..1e95e1a8 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ ## 2.1.0 * `NEW` supports local config file, using `--configpath="config.json"`, [learn more here](https://github.com/sumneko/lua-language-server/wiki/Setting-without-VSCode) * `NEW` goto `type definition` +* `FIX` completion: sometimes `type() ==` does not work ## 2.0.5 `2021-7-1` diff --git a/script/core/completion.lua b/script/core/completion.lua index 01f83242..83a08a83 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -1107,11 +1107,12 @@ local function checkEqualEnum(ast, text, offset, results) end local function checkEqualEnumInString(ast, text, offset, results) - local source = guide.eachSourceContain(ast.ast, offset, function (source) + local list = {} + guide.eachSourceContain(ast.ast, offset, function (source) if source.type == 'binary' then if source.op.type == '==' or source.op.type == '~=' then - return source[1] + list[#list+1] = source[1] end end if not source.start then @@ -1124,16 +1125,20 @@ local function checkEqualEnumInString(ast, text, offset, results) return end if parent.type == 'local' then - return parent + list[#list+1] = parent end if parent.type == 'setlocal' or parent.type == 'setglobal' or parent.type == 'setfield' or parent.type == 'setindex' then - return parent.node + list[#list+1] = parent.node end end end) + table.sort(list, function (a, b) + return a.start > b.start + end) + local source = list[1] checkEqualEnumLeft(ast, text, offset, source, results) end diff --git a/test/completion/init.lua b/test/completion/init.lua index 91c66237..d55d1c9a 100644 --- a/test/completion/init.lua +++ b/test/completion/init.lua @@ -2539,3 +2539,31 @@ local b = tdirect -- type . here, shows "world" local c = tarray[1].$ -- type . here, no auto completion ]] (EXISTS) + +TEST [[ +local function f() + if type() == '$' then + end +end +]] +(EXISTS) + +--config.set('Lua.completion.callSnippet', 'Disable') +-- +--TEST [[ +--GGG = 1 +--GGG = function () +--end +-- +--GGG$ +--]] +--{ +-- { +-- label = 'GGG = 1', +-- kind = define.CompletionItemKind.Variable, +-- }, +-- { +-- label = 'GGG()', +-- kind = define.CompletionItemKind.Function, +-- }, +--} |