diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-16 23:47:40 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-16 23:47:40 +0800 |
commit | 04c671114d1d4c4bcfbad74c8341b24844552865 (patch) | |
tree | 5179418d409f223a0fa8fd02e9bd44464e559683 /script/core | |
parent | 697c9359636a639f044192fd81e3f4374488192c (diff) | |
download | lua-language-server-04c671114d1d4c4bcfbad74c8341b24844552865.zip |
doc.enum
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/completion/completion.lua | 9 | ||||
-rw-r--r-- | script/core/definition.lua | 7 | ||||
-rw-r--r-- | script/core/diagnostics/duplicate-doc-alias.lua | 6 | ||||
-rw-r--r-- | script/core/folding.lua | 2 | ||||
-rw-r--r-- | script/core/hover/description.lua | 7 | ||||
-rw-r--r-- | script/core/hover/label.lua | 3 | ||||
-rw-r--r-- | script/core/reference.lua | 6 | ||||
-rw-r--r-- | script/core/rename.lua | 8 | ||||
-rw-r--r-- | script/core/semantic-tokens.lua | 1 | ||||
-rw-r--r-- | script/core/type-definition.lua | 4 |
10 files changed, 47 insertions, 6 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index 908398e7..01b5fcfe 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1648,6 +1648,7 @@ local function tryluaDocBySource(state, position, source, results) for _, doc in ipairs(vm.getDocSets(state.uri)) do local name = (doc.type == 'doc.class' and doc.class[1]) or (doc.type == 'doc.alias' and doc.alias[1]) + or (doc.type == 'doc.enum' and doc.enum[1]) if name and not used[name] and matchKey(source[1], name) then @@ -1803,6 +1804,14 @@ local function tryluaDocByErr(state, position, err, docState, results) kind = define.CompletionItemKind.Class, } end + if doc.type == 'doc.enum' + and not used[doc.enum[1]] then + used[doc.enum[1]] = true + results[#results+1] = { + label = doc.enum[1], + kind = define.CompletionItemKind.Enum, + } + end end elseif err.type == 'LUADOC_MISS_PARAM_NAME' then local funcs = {} diff --git a/script/core/definition.lua b/script/core/definition.lua index ac2513e9..09a5fcf1 100644 --- a/script/core/definition.lua +++ b/script/core/definition.lua @@ -55,6 +55,7 @@ local accept = { ['doc.see.name'] = true, ['doc.see.field'] = true, ['doc.cast.name'] = true, + ['doc.enum.name'] = true, } local function checkRequire(source, offset) @@ -170,8 +171,12 @@ return function (uri, offset) if src.type == 'doc.alias' then src = src.alias end + if src.type == 'doc.enum' then + src = src.enum + end if src.type == 'doc.class.name' - or src.type == 'doc.alias.name' then + or src.type == 'doc.alias.name' + or src.type == 'doc.enum.name' then if source.type ~= 'doc.type.name' and source.type ~= 'doc.extends.name' and source.type ~= 'doc.see.name' then diff --git a/script/core/diagnostics/duplicate-doc-alias.lua b/script/core/diagnostics/duplicate-doc-alias.lua index 2625f88f..e9ee5aab 100644 --- a/script/core/diagnostics/duplicate-doc-alias.lua +++ b/script/core/diagnostics/duplicate-doc-alias.lua @@ -17,7 +17,8 @@ return function (uri, callback) local cache = {} for _, doc in ipairs(state.ast.docs) do - if doc.type == 'doc.alias' then + if doc.type == 'doc.alias' + or doc.type == 'doc.enum' then local name = guide.getKeyName(doc) if not name then return @@ -28,7 +29,8 @@ return function (uri, callback) cache[name] = {} for _, otherDoc in ipairs(docs) do if otherDoc.type == 'doc.alias' - or otherDoc.type == 'doc.class' then + or otherDoc.type == 'doc.class' + or otherDoc.type == 'doc.enum' then cache[name][#cache[name]+1] = { start = otherDoc.start, finish = otherDoc.finish, diff --git a/script/core/folding.lua b/script/core/folding.lua index 0034313a..7f59636e 100644 --- a/script/core/folding.lua +++ b/script/core/folding.lua @@ -152,7 +152,7 @@ local care = { hideLastLine = true, } results[#results+1] = folding - end + end, } ---@async diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index e32d204c..382404c1 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -164,7 +164,8 @@ end local function tryDocClassComment(source) for _, def in ipairs(vm.getDefs(source)) do if def.type == 'doc.class' - or def.type == 'doc.alias' then + or def.type == 'doc.alias' + or def.type == 'doc.enum' then local comment = getBindComment(def) if comment then return comment @@ -361,6 +362,10 @@ local function tryDocComment(source) local enums = buildEnumChunk(source, source.alias[1], guide.getUri(source)) md:add('lua', enums) end + if source.type == 'doc.enum' then + local enums = buildEnumChunk(source, source.enum[1], guide.getUri(source)) + md:add('lua', enums) + end local result = md:string() if result == '' then return nil diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua index 5befe84c..d5c0a11e 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -35,6 +35,9 @@ local function asDocTypeName(source) if doc.type == 'doc.alias' then return '(alias) ' .. doc.alias[1] .. ' ' .. lang.script('HOVER_EXTENDS', vm.getInfer(doc.extends):view(guide.getUri(source))) end + if doc.type == 'doc.enum' then + return '(enum) ' .. doc.enum[1] .. ' ' .. lang.script('HOVER_EXTENDS', vm.getInfer(doc.extends):view(guide.getUri(source))) + end end end diff --git a/script/core/reference.lua b/script/core/reference.lua index a468afde..fa838cff 100644 --- a/script/core/reference.lua +++ b/script/core/reference.lua @@ -50,6 +50,7 @@ local accept = { ['doc.class.name'] = true, ['doc.extends.name'] = true, ['doc.alias.name'] = true, + ['doc.enum.name'] = true, } ---@async @@ -102,12 +103,17 @@ return function (uri, position) if src.type == 'doc.alias' then src = src.alias end + if src.type == 'doc.enum' then + src = src.enum + end if src.type == 'doc.class.name' or src.type == 'doc.alias.name' + or src.type == 'doc.enum.name' or src.type == 'doc.type.name' or src.type == 'doc.extends.name' then if source.type ~= 'doc.type.name' and source.type ~= 'doc.class.name' + and source.type ~= 'doc.enum.name' and source.type ~= 'doc.extends.name' and source.type ~= 'doc.see.name' then goto CONTINUE diff --git a/script/core/rename.lua b/script/core/rename.lua index a4b6dd7c..90e66224 100644 --- a/script/core/rename.lua +++ b/script/core/rename.lua @@ -231,6 +231,9 @@ local function ofDocTypeName(source, newname, callback) if doc.type == 'doc.alias' then callback(doc, doc.alias.start, doc.alias.finish, newname) end + if doc.type == 'doc.enum' then + callback(doc, doc.enum.start, doc.enum.finish, newname) + end end for _, doc in ipairs(global:getGets(uri)) do if doc.type == 'doc.type.name' then @@ -276,7 +279,8 @@ local function rename(source, newname, callback) return ofGlobal(source, newname, callback) elseif source.type == 'doc.class.name' or source.type == 'doc.type.name' - or source.type == 'doc.alias.name' then + or source.type == 'doc.alias.name' + or source.type == 'doc.enum.name' then return ofDocTypeName(source, newname, callback) elseif source.type == 'doc.param.name' then return ofDocParamName(source, newname, callback) @@ -310,6 +314,7 @@ local function prepareRename(source) or source.type == 'doc.class.name' or source.type == 'doc.type.name' or source.type == 'doc.alias.name' + or source.type == 'doc.enum.name' or source.type == 'doc.param.name' then return source, source[1] elseif source.type == 'string' @@ -350,6 +355,7 @@ local accept = { ['doc.type.name'] = true, ['doc.alias.name'] = true, ['doc.param.name'] = true, + ['doc.enum.name'] = true, } local m = {} diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 5f9a137b..52f47014 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -449,6 +449,7 @@ local Care = util.switch() end end) : case 'doc.alias.name' + : case 'doc.enum.name' : call(function (source, options, results) if not options.annotation then return diff --git a/script/core/type-definition.lua b/script/core/type-definition.lua index 2140090b..791dfa83 100644 --- a/script/core/type-definition.lua +++ b/script/core/type-definition.lua @@ -52,6 +52,7 @@ local accept = { ['doc.class.name'] = true, ['doc.extends.name'] = true, ['doc.alias.name'] = true, + ['doc.enum.name'] = true, ['doc.see.name'] = true, ['doc.see.field'] = true, } @@ -145,6 +146,9 @@ return function (uri, offset) if src.type == 'doc.alias' then src = src.alias end + if src.type == 'doc.enum' then + src = src.enum + end if src.type == 'doc.class.name' or src.type == 'doc.alias.name' or src.type == 'doc.type.function' |