diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-06-28 15:01:16 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-06-28 15:01:16 +0800 |
commit | daee93fb17e8f206e63ab8573566762011a3f1cd (patch) | |
tree | 899636477d8afb30b7dbfe995ef9fa8a76239919 /server/src | |
parent | f6a6e9f9d36d34c542c721db41a4e9770bcebcf7 (diff) | |
download | lua-language-server-daee93fb17e8f206e63ab8573566762011a3f1cd.zip |
修改enum的语法
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/completion.lua | 15 | ||||
-rw-r--r-- | server/src/core/hover/function.lua | 12 | ||||
-rw-r--r-- | server/src/emmy/alias.lua | 6 | ||||
-rw-r--r-- | server/src/emmy/manager.lua | 8 | ||||
-rw-r--r-- | server/src/emmy/param.lua | 6 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 15 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 4 |
7 files changed, 34 insertions, 32 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index ddbe7271..6ab3c565 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -663,14 +663,14 @@ local function searchEnumAsLib(vm, source, word, callback, pos, args, lib) end end -local function buildEmmyEnumComment(option, data) - if not option or not option.comment then +local function buildEmmyEnumComment(enum, data) + if not enum.comment then return data end if not data then data = {} end - data.documentation = tostring(option.comment) + data.documentation = tostring(enum.comment) return data end @@ -688,18 +688,19 @@ local function searchEnumAsEmmyParams(vm, source, word, callback, pos, args, fun return end - param:eachEnum(function (str, option) + param:eachEnum(function (enum) + local str = enum[1] 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(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(option, data)) + callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(enum, data)) else - callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(option)) + callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(enum)) end else - callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(option)) + callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(enum)) end end end) diff --git a/server/src/core/hover/function.lua b/server/src/core/hover/function.lua index b3bbb428..620eb054 100644 --- a/server/src/core/hover/function.lua +++ b/server/src/core/hover/function.lua @@ -129,18 +129,18 @@ local function buildEnum(func) local strs = {} for _, param in ipairs(params) do local first = true - param:eachEnum(function (enum, option) + param:eachEnum(function (enum) if first then first = false strs[#strs+1] = ('\n%s: %s'):format(param:getName(), param:getType()) end - if option and option.default then - strs[#strs+1] = ('\n |>%s'):format(enum) + if enum.default then + strs[#strs+1] = ('\n |>%s'):format(enum[1]) else - strs[#strs+1] = ('\n | %s'):format(enum) + strs[#strs+1] = ('\n | %s'):format(enum[1]) end - if option and option.comment then - strs[#strs+1] = ' -- ' .. option.comment + if enum.comment then + strs[#strs+1] = ' -- ' .. enum.comment end end) end diff --git a/server/src/emmy/alias.lua b/server/src/emmy/alias.lua index 7e015542..be47cb4f 100644 --- a/server/src/emmy/alias.lua +++ b/server/src/emmy/alias.lua @@ -21,13 +21,13 @@ function mt:bindType(type) end end -function mt:addEnum(enum, option) - self._enum[#self._enum+1] = {enum, option} +function mt:addEnum(enum) + self._enum[#self._enum+1] = enum end function mt:eachEnum(callback) for _, enum in ipairs(self._enum) do - callback(enum[1], enum[2]) + callback(enum) end end diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua index 931c9449..0407bbc0 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][1], source[i].option) + aliasObj:addEnum(source[i]) 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, option) - paramObj:addEnum(enum, option) + class:eachEnum(function (enum) + paramObj:addEnum(enum) end) end end) end for i = 3, #source do - paramObj:addEnum(source[i][1][1], source[i].option) + paramObj:addEnum(source[i]) end paramObj:setOption(source.option) return paramObj diff --git a/server/src/emmy/param.lua b/server/src/emmy/param.lua index 65791fd6..12ac0633 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(enum, option) - self._enum[#self._enum+1] = {enum, option} +function mt:addEnum(enum) + self._enum[#self._enum+1] = enum end function mt:eachEnum(callback) for _, enum in ipairs(self._enum) do - callback(enum[1], enum[2]) + callback(enum) end end diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index f9a6d53d..08f7fdd3 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -1335,14 +1335,13 @@ local Defs = { end return option end, - EmmyTypeEnum = function (enum, option) - return { - type = 'emmyEnum', - option = option, - start = enum.start, - finish = enum.finish, - [1] = enum, - } + EmmyTypeEnum = function (default, enum, comment) + enum.type = 'emmyEnum' + if default ~= '' then + enum.default = true + end + enum.comment = comment + return enum end, -- 捕获错误 diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index c53597dd..2967ac3c 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -558,8 +558,10 @@ EmmyTypeName <- EmmyFunctionType / EmmyTableType / EmmyArrayType / MustEmmyName -EmmyTypeEnum <- %s* (%nl %s* '---')? '|' %s* (String EmmyOption) +EmmyTypeEnum <- %s* (%nl %s* '---')? '|' EmmyEnum -> EmmyTypeEnum +EmmyEnum <- %s* {'>'?} %s* String (EmmyEnumComment / (!%nl !'|' .)*) +EmmyEnumComment <- %s* '#' %s* {(!%nl .)*} EmmyAlias <- MustEmmyName %s* EmmyType EmmyTypeEnum* |