diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/completion.lua | 22 | ||||
-rw-r--r-- | server/src/method/initialize.lua | 2 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 4 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 5 | ||||
-rw-r--r-- | server/src/vm/emmy.lua | 4 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 2 | ||||
-rw-r--r-- | server/test/completion/init.lua | 15 |
7 files changed, 50 insertions, 4 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 3b6e67e7..cef8b798 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -37,6 +37,8 @@ for _, k in ipairs(KEYS) do KEYMAP[k] = true end +local EMMY_KEYWORD = {'class', 'type', 'alias', 'param', 'return', 'field', 'generic', 'vararg', 'language', 'see'} + local function matchKey(me, other) if me == other then return true @@ -359,6 +361,14 @@ local function searchAsArg(vm, source, word, callback) searchCloseGlobal(vm, source, word, callback) end +local function searchEmmyKeyword(vm, source, word, callback) + for _, kw in ipairs(EMMY_KEYWORD) do + if matchKey(word, kw) then + callback(kw, nil, CompletionItemKind.Keyword) + end + end +end + local function searchSource(vm, source, word, callback) if source:get 'table index' then searchAsIndex(vm, source, word, callback) @@ -384,6 +394,10 @@ local function searchSource(vm, source, word, callback) searchAsSuffix(vm, source, word, callback) return end + if source.type == 'emmyIncomplete' then + searchEmmyKeyword(vm, source, word, callback) + return + end end local function searchInRequire(vm, select, source, callback) @@ -506,7 +520,7 @@ local function searchAllWords(vm, source, word, callback, pos) end) end -local function searchSpecial(vm, source, word, callback, pos) +local function searchSpecialHashSign(vm, pos, callback) -- 尝试 XXX[#XXX+1] -- 1. 搜索 [] local index @@ -571,6 +585,10 @@ local function searchSpecial(vm, source, word, callback, pos) end end +local function searchSpecial(vm, source, word, callback, pos) + searchSpecialHashSign(vm, pos, callback) +end + local function makeList(source, pos, word) local list = {} local mark = {} @@ -624,7 +642,7 @@ local function searchToclose(text, word, callback, pos) end return function (vm, text, pos, word, oldText) - local source = findSource(vm, pos) or findSource(vm, pos-1) + local source = findSource(vm, pos) or findSource(vm, pos-1) or findSource(vm, pos+1) if not source then return nil end diff --git a/server/src/method/initialize.lua b/server/src/method/initialize.lua index 930ff75e..82ff9640 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 839f9b76..7ac3db06 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -1201,6 +1201,10 @@ local Defs = { className, methodName } end, + EmmyIncomplete = function (emmyName) + emmyName.type = 'emmyIncomplete' + return emmyName + end, -- 捕获错误 UnknownSymbol = function (start, symbol) diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index 7c29881b..6743ed89 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -520,7 +520,8 @@ EmmyBody <- 'class' %s+ EmmyClass -> EmmyClass / 'generic' %s+ EmmyGeneric -> EmmyGeneric / 'vararg' %s+ EmmyVararg -> EmmyVararg / 'language' %s+ EmmyLanguage -> EmmyLanguage - / 'see' %s+ EmmySee -> EmmySee + / 'see' %s+ EmmySee -> EmmySee + / EmmyIncomplete EmmyName <- ({} {[a-zA-Z_] [a-zA-Z0-9_]*}) -> EmmyName @@ -528,6 +529,8 @@ MustEmmyName <- EmmyName / DirtyEmmyName DirtyEmmyName <- {} -> DirtyEmmyName EmmyLongName <- ({} {(!%nl .)+}) -> EmmyName +EmmyIncomplete <- MustEmmyName + -> EmmyIncomplete EmmyClass <- (MustEmmyName EmmyParentClass?) EmmyParentClass <- %s* ':' %s* MustEmmyName diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua index 900747e6..4ab42c93 100644 --- a/server/src/vm/emmy.lua +++ b/server/src/vm/emmy.lua @@ -11,3 +11,7 @@ function mt:doEmmyClass(action) local emmyClass = emmyMgr:addClass(class, parent) self.emmy = emmyClass end + +function mt:doEmmyIncomplete(action) + self:instantSource(action) +end diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 6f6a4d59..b89a8c51 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -1053,6 +1053,8 @@ function mt:doAction(action) elseif tp == 'emmyTableType' then elseif tp == 'emmyFunctionType' then elseif tp == 'emmySee' then + elseif tp == 'emmyIncomplete' then + self:doEmmyIncomplete(action) else self:getExp(action) action:set('as action', true) diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index 7d59eb7a..db23ad84 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -769,3 +769,18 @@ t.$ kind = CompletionItemKind.Field, } } + +TEST [[ +---@$ +]] +(EXISTS) + +TEST [[ +---@cl$ +]] +{ + { + label = 'class', + kind = CompletionItemKind.Keyword + } +} |