diff options
-rw-r--r-- | server/src/core/completion.lua | 9 | ||||
-rw-r--r-- | server/src/method/initialize.lua | 2 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 9 | ||||
-rw-r--r-- | server/test/completion/init.lua | 40 |
4 files changed, 54 insertions, 6 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index d0da95cd..3d8a47e0 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -3,6 +3,7 @@ local getFunctionHover = require 'core.hover.function' local getFunctionHoverAsLib = require 'core.hover.lib_function' local sourceMgr = require 'vm.source' local config = require 'config' +local State local CompletionItemKind = { Text = 1, @@ -436,10 +437,13 @@ local function searchSource(vm, source, word, callback) end if source.type == 'emmyIncomplete' then searchEmmyKeyword(vm, source, word, callback) + State.ignoreText = true return end if source:get 'target class' then searchEmmyClass(vm, source, word, callback) + State.ignoreText = true + return end end @@ -769,6 +773,7 @@ return function (vm, text, pos, oldText) return nil end end + State = {} local callback, list = makeList(source, pos, word) if searchToclose(text, source, word, callback) then return list @@ -777,7 +782,9 @@ return function (vm, text, pos, oldText) searchCallArg(vm, source, word, callback, pos) searchSource(vm, source, word, callback) if not oldText or #list > 0 then - searchAllWords(vm, source, word, callback, pos) + if not State.ignoreText then + searchAllWords(vm, source, word, callback, pos) + end end if #list == 0 then diff --git a/server/src/method/initialize.lua b/server/src/method/initialize.lua index 5478e744..84388fef 100644 --- a/server/src/method/initialize.lua +++ b/server/src/method/initialize.lua @@ -1,5 +1,5 @@ local function allWords() - local str = [[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:('"[,#*@ ]] + local str = [[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:('"[,#*@| ]] local list = {} for c in str:gmatch '.' do list[#list+1] = c diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index f7a94dfc..83c877e4 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -1104,13 +1104,13 @@ local Defs = { pushError { type = 'MISS_NAME', level = 'warning', - start = pos, - finish = pos, + start = pos-1, + finish = pos-1, } return { type = 'emmyName', - start = pos, - finish = pos, + start = pos-1, + finish = pos-1, [1] = '' } end, @@ -1538,3 +1538,4 @@ return function (self, lua, mode, version) end return res, Errs end + diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index 560f6fa4..0f4b27d3 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -784,3 +784,43 @@ TEST [[ kind = CompletionItemKind.Class, }, } + +TEST [[ +---@class abc +local abcd +---@type a$ +]] +{ + { + label = 'abc', + kind = CompletionItemKind.Class, + }, +} + +TEST [[ +---@class abc +local abcd +---@type $ +]] +{ + { + label = 'abc', + kind = CompletionItemKind.Class, + }, +} + +TEST [[ +---@class abc +local abcd +---@type xxx|$ +]] +{ + { + label = 'abc', + kind = CompletionItemKind.Class, + }, + { + label = 'xxx', + kind = CompletionItemKind.Class, + }, +} |