diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-06-27 21:16:49 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-06-27 21:16:49 +0800 |
commit | 92aa3d6c203aef82a57efbe8216830a016db6d5e (patch) | |
tree | bc40905c5acd1ce368a468897345fcb40a5a04da /server/src | |
parent | ca19e2ea1d6df45e7e2fa1ac7bd910e083a13600 (diff) | |
download | lua-language-server-92aa3d6c203aef82a57efbe8216830a016db6d5e.zip |
偷偷支持新的 EmmyEnum
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/completion.lua | 12 | ||||
-rw-r--r-- | server/src/emmy/manager.lua | 8 | ||||
-rw-r--r-- | server/src/emmy/param.lua | 8 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 40 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 10 |
5 files changed, 46 insertions, 32 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 18bf12af..37527ac2 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -677,18 +677,18 @@ local function searchEnumAsEmmyParams(vm, source, word, callback, pos, args, fun return end - param:eachEnum(function (enum) - if matchKey(word, enum) then - local strSource = parser:ast(tostring(enum), 'String') + param:eachEnum(function (str) + if matchKey(word, str) then + local strSource = parser:ast(tostring(str), 'String') if strSource then if source.type == 'string' then local data = buildTextEdit(source.start, source.finish, strSource[1], source[2]) - callback(enum, nil, CompletionItemKind.EnumMember, data) + callback(str, nil, CompletionItemKind.EnumMember, data) else - callback(enum, nil, CompletionItemKind.EnumMember) + callback(str, nil, CompletionItemKind.EnumMember) end else - callback(enum, nil, CompletionItemKind.EnumMember) + callback(str, nil, CompletionItemKind.EnumMember) end end end) diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua index 1be0be94..931c9449 100644 --- a/server/src/emmy/manager.lua +++ b/server/src/emmy/manager.lua @@ -136,7 +136,7 @@ function mt:addAlias(source, typeObj) local list = self:getClass(aliasName) list[source.id] = aliasObj for i = 3, #source do - aliasObj:addEnum(source[i][1]) + aliasObj:addEnum(source[i][1][1], source[i].option) end return aliasObj end @@ -149,14 +149,14 @@ function mt:addParam(source, bind) paramObj:bindType(bind) self:eachClass(bind:getName(), function (class) if class.type == 'emmy.alias' then - class:eachEnum(function (enum) - paramObj:addEnum(enum) + class:eachEnum(function (enum, option) + paramObj:addEnum(enum, option) end) end end) end for i = 3, #source do - paramObj:addEnum(source[i][1]) + paramObj:addEnum(source[i][1][1], source[i].option) end paramObj:setOption(source.option) return paramObj diff --git a/server/src/emmy/param.lua b/server/src/emmy/param.lua index 6fd41d5a..65791fd6 100644 --- a/server/src/emmy/param.lua +++ b/server/src/emmy/param.lua @@ -37,13 +37,13 @@ function mt:bindGeneric(generic) end end -function mt:addEnum(str) - self._enum[#self._enum+1] = str +function mt:addEnum(enum, option) + self._enum[#self._enum+1] = {enum, option} end function mt:eachEnum(callback) - for _, str in ipairs(self._enum) do - callback(str) + for _, enum in ipairs(self._enum) do + callback(enum[1], enum[2]) end end diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 0e408c73..e2add23e 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -1233,20 +1233,7 @@ local Defs = { ... } end, - EmmyParam = function (argName, emmyName, options, ...) - local option - if options then - option = {} - for _, pair in ipairs(options) do - if pair.type == 'pair' then - local key = pair[1] - local value = pair[2] - if key.type == 'name' then - option[key[1]] = value[1] - end - end - end - end + EmmyParam = function (argName, emmyName, option, ...) local emmy = { type = 'emmyParam', option = option, @@ -1332,6 +1319,31 @@ local Defs = { [1] = table.concat({...}, ' '), } end, + EmmyOption = function (options) + if not options or options == '' then + return nil + end + local option = {} + for _, pair in ipairs(options) do + if pair.type == 'pair' then + local key = pair[1] + local value = pair[2] + if key.type == 'name' then + option[key[1]] = value[1] + end + end + end + return option + end, + EmmyTypeEnum = function (enum, option) + return { + type = 'emmyEnum', + option = option, + start = enum.start, + finish = enum.finish, + [1] = enum, + } + end, -- 捕获错误 UnknownSymbol = function (start, symbol) diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index 913b0b25..5a408d90 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -556,12 +556,14 @@ EmmyTypeName <- EmmyFunctionType / EmmyTableType / EmmyArrayType / MustEmmyName -EmmyTypeEnums <- %s* '|' %s* String +EmmyTypeEnum <- %s* (%nl %s* '---')? '|' %s* (String EmmyOption) + -> EmmyTypeEnum -EmmyAlias <- MustEmmyName %s* EmmyType EmmyTypeEnums* +EmmyAlias <- MustEmmyName %s* EmmyType EmmyTypeEnum* -EmmyParam <- MustEmmyName %s* EmmyType %s* EmmyOption %s* EmmyTypeEnums* -EmmyOption <- Table / %nil +EmmyParam <- MustEmmyName %s* EmmyType %s* EmmyOption %s* EmmyTypeEnum* +EmmyOption <- Table? + -> EmmyOption EmmyReturn <- EmmyType |