diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/completion.lua | 25 | ||||
-rw-r--r-- | server/src/core/definition.lua | 4 | ||||
-rw-r--r-- | server/src/core/implementation.lua | 4 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 4 | ||||
-rw-r--r-- | server/src/vm/emmy.lua | 10 | ||||
-rw-r--r-- | server/src/vm/function.lua | 7 | ||||
-rw-r--r-- | server/test/completion/init.lua | 37 |
7 files changed, 69 insertions, 22 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index f3e811a1..8b6b7676 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -401,8 +401,10 @@ end local function searchEmmyClass(vm, source, word, callback) local classes = {} vm.emmyMgr:eachClass(function (class) - if matchKey(word, class:getName()) then - classes[#classes+1] = class + if class.type == 'emmy.class' or class.type == 'emmy.alias' then + if matchKey(word, class:getName()) then + classes[#classes+1] = class + end end end) table.sort(classes, function (a, b) @@ -413,6 +415,18 @@ local function searchEmmyClass(vm, source, word, callback) end end +local function searchEmmyFunctionParam(vm, source, word, callback) + local func = source:get 'emmy function' + if not func.args then + return + end + for _, arg in ipairs(func.args) do + if matchKey(word, arg.name) then + callback(arg.name, arg, CompletionItemKind.Unit) + end + end +end + local function searchSource(vm, source, word, callback) if source.type == 'keyword' then searchAsKeyowrd(vm, source, word, callback) @@ -447,11 +461,16 @@ local function searchSource(vm, source, word, callback) State.ignoreText = true return end - if source:get 'target class' then + if source:get 'emmy class' then searchEmmyClass(vm, source, word, callback) State.ignoreText = true return end + if source:get 'emmy function' then + searchEmmyFunctionParam(vm, source, word, callback) + State.ignoreText = true + return + end end local function searchInRequire(vm, select, source, callback) diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua index a461dfe4..fd5b4758 100644 --- a/server/src/core/definition.lua +++ b/server/src/core/definition.lua @@ -163,7 +163,7 @@ local function jumpUri(callback, vm, source) end local function parseClass(callback, vm, source) - local className = source:get 'target class' + local className = source:get 'emmy class' vm.emmyMgr:eachClass(className, function (class) if Mode == 'definition' then if class.type == 'emmy.class' or class.type == 'emmy.alias' then @@ -262,7 +262,7 @@ return function (vm, pos, mode) if source:get 'in index' then isGlobal = parseValue(callback, vm, source) end - if source:get 'target class' then + if source:get 'emmy class' then parseClass(callback, vm, source) end diff --git a/server/src/core/implementation.lua b/server/src/core/implementation.lua index 450b9a0c..f51a97ca 100644 --- a/server/src/core/implementation.lua +++ b/server/src/core/implementation.lua @@ -167,7 +167,7 @@ local function jumpUri(vm, source, lsp) end local function parseClass(vm, source) - local className = source:get 'target class' + local className = source:get 'emmy class' local positions = {} vm.emmyMgr:eachClass(className, function (class) local src = class:getSource() @@ -198,7 +198,7 @@ return function (vm, source, lsp) return parseValue(vm, source, lsp) or parseValueSimily(vm, source, lsp) end - if source:get 'target class' then + if source:get 'emmy class' then return parseClass(vm, source) end end diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index e7957535..03e14776 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -554,9 +554,9 @@ EmmyTypeName <- EmmyFunctionType / MustEmmyName EmmyTypeEnums <- %s* '|' %s* String -EmmyAlias <- MustEmmyName %s+ EmmyType EmmyTypeEnums* +EmmyAlias <- MustEmmyName %s* EmmyType EmmyTypeEnums* -EmmyParam <- MustEmmyName %s+ EmmyType EmmyTypeEnums* +EmmyParam <- MustEmmyName %s* EmmyType EmmyTypeEnums* EmmyReturn <- EmmyType diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua index 5406aab1..f183de73 100644 --- a/server/src/vm/emmy.lua +++ b/server/src/vm/emmy.lua @@ -54,12 +54,12 @@ function mt:doEmmyClass(action) self:instantSource(action) self:instantSource(action[1]) local class = emmyMgr:addClass(action) - action:set('target class', class:getName()) - action[1]:set('target class', class:getName()) + action:set('emmy class', class:getName()) + action[1]:set('emmy class', class:getName()) local extends = action[2] if extends then self:instantSource(extends) - extends:set('target class', extends[1]) + extends:set('emmy class', extends[1]) end self._emmy = class action:set('emmy.class', class) @@ -74,7 +74,7 @@ function mt:doEmmyType(action) self:instantSource(action) for _, obj in ipairs(action) do self:instantSource(obj) - obj:set('target class', obj[1]) + obj:set('emmy class', obj[1]) end local type = emmyMgr:addType(action) self._emmy = type @@ -92,7 +92,7 @@ function mt:doEmmyAlias(action) local type = self:doEmmyType(action[2]) local alias = emmyMgr:addAlias(action, type) action:set('emmy.alias', alias) - action[1]:set('target class', alias:getName()) + action[1]:set('emmy class', alias:getName()) if self.lsp then self.lsp.global:markSet(self:getUri()) end diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index dff5952d..9b0811bf 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -381,7 +381,12 @@ function mt:markGlobal() end function mt:setEmmyParams(params) - self._emmyParams = params + if params then + self._emmyParams = params + for _, param in ipairs(params) do + param:getSource()[1]:set('emmy function', self) + end + end end local function create(source) diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index 0857e8cb..340af415 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -818,11 +818,7 @@ local abcd { label = 'abc', kind = CompletionItemKind.Class, - }, - { - label = 'xxx', - kind = CompletionItemKind.Class, - }, + } } TEST [[ @@ -831,11 +827,38 @@ TEST [[ ]] { { - label = 'abb', + label = 'abc', kind = CompletionItemKind.Class, }, +} + +TEST [[ +---@class Class +---@param x C$ +]] +{ { - label = 'abc', + label = 'Class', kind = CompletionItemKind.Class, }, } + +TEST [[ +---@param $ +function f(a, b, c) +end +]] +{ + { + label = 'a', + kind = CompletionItemKind.Unit, + }, + { + label = 'b', + kind = CompletionItemKind.Unit, + }, + { + label = 'c', + kind = CompletionItemKind.Unit, + }, +} |