diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-10-17 14:12:48 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-10-17 14:12:48 +0800 |
commit | f8cd9ff51925b3a52e5bad430ef276794f953adb (patch) | |
tree | f014b85d4acd61a514f9957cdbf7d48a38a796fa | |
parent | 6b04f490fc0c45a0e3a70f3ca27c976f70b620c1 (diff) | |
download | lua-language-server-f8cd9ff51925b3a52e5bad430ef276794f953adb.zip |
improve workspace-symbol
-rw-r--r-- | script/core/workspace-symbol.lua | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/script/core/workspace-symbol.lua b/script/core/workspace-symbol.lua index 9d52572b..6501708d 100644 --- a/script/core/workspace-symbol.lua +++ b/script/core/workspace-symbol.lua @@ -84,11 +84,47 @@ local function searchGlobalAndClass(key, results) end ---@async -return function (key) - local results = {} - - searchGlobalAndClass(key, results) +---@param key string +---@param results table[] +local function searchClassField(key, results) + local class, inField = key:match('^(.+)%.(.-)$') + if not class then + return + end + local global = vm.getGlobal('type', class) + if not global then + return + end + local set = global:getAllSets()[1] + if not set then + return + end + local suri = guide.getUri(set) + vm.getClassFields(suri, global, nil, false, function (field, isMark) + if field.type == 'generic' then + return + end + ---@cast field -vm.generic + local keyName = guide.getKeyName(field) + if not keyName then + return + end + if not matchKey(inField, keyName) then + return + end + results[#results+1] = { + name = class .. '.' .. keyName, + kind = define.SymbolKind.Field, + uri = guide.getUri(field), + range = { field.start, field.finish }, + } + end) +end +---@async +---@param key string +---@param results table[] +local function searchWords(key, results) for uri in files.eachFile() do searchFile(uri, key, results) if #results > 1000 then @@ -96,6 +132,15 @@ return function (key) end await.delay() end +end + +---@async +return function (key) + local results = {} + + searchGlobalAndClass(key, results) + searchClassField(key, results) + searchWords(key, results) return results end |