From f4e6b2b3dc487d14a17683a38c0cfc9b8ab6f5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 21 Jul 2020 15:35:56 +0800 Subject: =?UTF-8?q?=E5=85=A8=E5=B1=80=E7=AC=A6=E5=8F=B7=E5=8F=AA=E5=8C=85?= =?UTF-8?q?=E5=90=ABset=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/method/workspace/symbol.lua | 55 ++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'script/method') diff --git a/script/method/workspace/symbol.lua b/script/method/workspace/symbol.lua index 6ec2d025..70755ee0 100644 --- a/script/method/workspace/symbol.lua +++ b/script/method/workspace/symbol.lua @@ -46,6 +46,49 @@ local function convertRange(lines, range) return result end +local function getParentName(source) + local parentValue = source:get 'parent' + if not parentValue then + return + end + local pSource = parentValue:getSource() + if not pSource then + return + end + local name = pSource[1] + if type(name) ~= 'string' or name == '' then + return + end + return name +end + +local function collect(results, source, uri, lines) + if source:action() ~= 'set' then + return + end + local kind = SymbolKind.Variable + local contain = getParentName(source) + local value = source:bindValue() + if value and value:getFunction() then + kind = SymbolKind.Function + else + if source:get 'global' then + kind = SymbolKind.Namespace + elseif source:get 'table index' then + kind = SymbolKind.EnumMember + end + end + results[#results+1] = { + name = source[1], + kind = kind, + containerName = contain, + location = { + uri = uri, + range = convertRange(lines, source), + } + } +end + local function searchVM(lsp, results, query, uri) local vm, lines = lsp:getVM(uri) if not vm then @@ -53,15 +96,11 @@ local function searchVM(lsp, results, query, uri) end vm:eachSource(function (src) if src.type == 'name' then + if src[1] == '' then + return + end if matchKey(query, src[1]) then - results[#results+1] = { - name = src[1], - kind = SymbolKind.Variable, - location = { - uri = uri, - range = convertRange(lines, src), - } - } + collect(results, src, uri, lines) end end end) -- cgit v1.2.3