diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-11-02 17:29:18 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-11-02 17:29:18 +0800 |
commit | 625f5be9a6ae1c30dd5821f1dd2485073d054209 (patch) | |
tree | 2581abc44fa0b6a42b590fc842501b8a9edf9a1f /script/core | |
parent | 3bf48c900605681216ce7c14cfe0cb43e583de4f (diff) | |
download | lua-language-server-625f5be9a6ae1c30dd5821f1dd2485073d054209.zip |
`---@see` use workspace-symbol
#1344
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/completion/completion.lua | 47 | ||||
-rw-r--r-- | script/core/definition.lua | 24 | ||||
-rw-r--r-- | script/core/semantic-tokens.lua | 11 | ||||
-rw-r--r-- | script/core/type-definition.lua | 1 | ||||
-rw-r--r-- | script/core/workspace-symbol.lua | 57 |
5 files changed, 99 insertions, 41 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index b665bcd1..cac74543 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -19,6 +19,7 @@ local guide = require 'parser.guide' local await = require 'await' local postfix = require 'core.completion.postfix' local diag = require 'proto.diagnostic' +local wssymbol = require 'core.workspace-symbol' local diagnosticModes = { 'disable-next-line', @@ -1715,6 +1716,7 @@ local function getluaDocByErr(state, start, position) return targetError, targetDoc end +---@async local function tryluaDocBySource(state, position, source, results) if source.type == 'doc.extends.name' then if source.parent.type == 'doc.class' then @@ -1823,8 +1825,8 @@ local function tryluaDocBySource(state, position, source, results) if matchKey(source[1], name) then results[#results+1] = { label = name, - kind = define.CompletionItemKind.Variable, - id = stack(function () ---@async + kind = define.CompletionItemKind.Variable, + id = stack(function () ---@async return { detail = buildDetail(loc), description = buildDesc(loc), @@ -1863,10 +1865,33 @@ local function tryluaDocBySource(state, position, source, results) end end return true + elseif source.type == 'doc.see.name' then + local symbolds = wssymbol(source[1]) + table.sort(symbolds, function (a, b) + return a.name < b.name + end) + for _, symbol in ipairs(symbolds) do + results[#results+1] = { + label = symbol.name, + kind = symbol.ckind, + id = stack(function () ---@async + return { + detail = buildDetail(symbol.source), + description = buildDesc(symbol.source), + } + end), + textEdit = { + start = source.start, + finish = source.finish, + newText = symbol.name, + }, + } + end end return false end +---@async local function tryluaDocByErr(state, position, err, docState, results) if err.type == 'LUADOC_MISS_CLASS_EXTENDS_NAME' then local used = {} @@ -2003,6 +2028,23 @@ local function tryluaDocByErr(state, position, err, docState, results) description = ('```lua\n%s\n```'):format(vm.OP_OTHER_MAP[name]), } end + elseif err.type == 'LUADOC_MISS_SEE_NAME' then + local symbolds = wssymbol('') + table.sort(symbolds, function (a, b) + return a.name < b.name + end) + for _, symbol in ipairs(symbolds) do + results[#results+1] = { + label = symbol.name, + kind = symbol.ckind, + id = stack(function () ---@async + return { + detail = buildDetail(symbol.source), + description = buildDesc(symbol.source), + } + end), + } + end end end @@ -2080,6 +2122,7 @@ local function tryluaDocOfFunction(doc, results) } end +---@async local function tryLuaDoc(state, position, results) local doc = getLuaDoc(state, position) if not doc then diff --git a/script/core/definition.lua b/script/core/definition.lua index 1a886a91..22a43bbf 100644 --- a/script/core/definition.lua +++ b/script/core/definition.lua @@ -5,6 +5,7 @@ local findSource = require 'core.find-source' local guide = require 'parser.guide' local rpath = require 'workspace.require-path' local jumpSource = require 'core.jump-source' +local wssymbol = require 'core.workspace-symbol' local function sortResults(results) -- 先按照顺序排序 @@ -53,7 +54,6 @@ local accept = { ['doc.extends.name'] = true, ['doc.alias.name'] = true, ['doc.see.name'] = true, - ['doc.see.field'] = true, ['doc.cast.name'] = true, ['doc.enum.name'] = true, ['doc.field.name'] = true, @@ -107,6 +107,26 @@ local function convertIndex(source) return source end +---@async +---@param source parser.object +---@param results table +local function checkSee(source, results) + if source.type ~= 'doc.see.name' then + return + end + local symbols = wssymbol(source[1]) + for _, symbol in ipairs(symbols) do + if symbol.name == source[1] then + results[#results+1] = { + target = symbol.source, + source = source, + uri = guide.getUri(symbol.source), + } + end + end +end + +---@async return function (uri, offset) local ast = files.getState(uri) if not ast then @@ -134,6 +154,8 @@ return function (uri, offset) end end + checkSee(source, results) + local defs = vm.getDefs(source) for _, src in ipairs(defs) do diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index b470fec2..14d6ddc8 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -592,17 +592,6 @@ local Care = util.switch() type = define.TokenTypes.class, } end) - : case 'doc.see.field' - : call(function (source, options, results) - if not options.annotation then - return - end - results[#results+1] = { - start = source.start, - finish = source.finish, - type = define.TokenTypes.property, - } - end) : case 'doc.diagnostic' : call(function (source, options, results) if not options.annotation then diff --git a/script/core/type-definition.lua b/script/core/type-definition.lua index a1c2b29f..0a821f25 100644 --- a/script/core/type-definition.lua +++ b/script/core/type-definition.lua @@ -54,7 +54,6 @@ local accept = { ['doc.alias.name'] = true, ['doc.enum.name'] = true, ['doc.see.name'] = true, - ['doc.see.field'] = true, } local function checkRequire(source, offset) diff --git a/script/core/workspace-symbol.lua b/script/core/workspace-symbol.lua index 6501708d..2e865594 100644 --- a/script/core/workspace-symbol.lua +++ b/script/core/workspace-symbol.lua @@ -12,10 +12,10 @@ local function buildSource(uri, source, key, results) local name = source[1] if matchKey(key, name) then results[#results+1] = { - name = name, - kind = define.SymbolKind.Variable, - uri = uri, - range = { source.start, source.finish }, + name = name, + skind = define.SymbolKind.Variable, + ckind = define.CompletionItemKind.Variable, + source = source, } end elseif source.type == 'setfield' @@ -24,10 +24,10 @@ local function buildSource(uri, source, key, results) local name = field and field[1] if name and matchKey(key, name) then results[#results+1] = { - name = name, - kind = define.SymbolKind.Field, - uri = uri, - range = { field.start, field.finish }, + name = name, + skind = define.SymbolKind.Field, + ckind = define.CompletionItemKind.Field, + source = field, } end elseif source.type == 'setmethod' then @@ -35,10 +35,10 @@ local function buildSource(uri, source, key, results) local name = method and method[1] if name and matchKey(key, name) then results[#results+1] = { - name = name, - kind = define.SymbolKind.Method, - uri = uri, - range = { method.start, method.finish }, + name = name, + skind = define.SymbolKind.Method, + ckind = define.CompletionItemKind.Method, + source = method, } end end @@ -63,19 +63,22 @@ local function searchGlobalAndClass(key, results) local name = global:getCodeName() if matchKey(key, name) then for _, set in ipairs(global:getAllSets()) do - local kind + local skind, ckind if set.type == 'doc.class' then - kind = define.SymbolKind.Class + skind = define.SymbolKind.Class + ckind = define.CompletionItemKind.Class elseif set.type == 'doc.alias' then - kind = define.SymbolKind.Namespace + skind = define.SymbolKind.Struct + ckind = define.CompletionItemKind.Struct else - kind = define.SymbolKind.Variable + skind = define.SymbolKind.Variable + ckind = define.CompletionItemKind.Variable end results[#results+1] = { - name = name, - kind = kind, - uri = guide.getUri(set), - range = { set.start, set.finish }, + name = name, + skind = skind, + ckind = ckind, + source = set, } end await.delay() @@ -113,10 +116,10 @@ local function searchClassField(key, results) return end results[#results+1] = { - name = class .. '.' .. keyName, - kind = define.SymbolKind.Field, - uri = guide.getUri(field), - range = { field.start, field.finish }, + name = class .. '.' .. keyName, + skind = define.SymbolKind.Field, + ckind = define.SymbolKind.Field, + source = field, } end) end @@ -135,12 +138,14 @@ local function searchWords(key, results) end ---@async -return function (key) +return function (key, includeWords) local results = {} searchGlobalAndClass(key, results) searchClassField(key, results) - searchWords(key, results) + if includeWords then + searchWords(key, results) + end return results end |