diff options
-rw-r--r-- | server/src/core/document_symbol.lua | 32 | ||||
-rw-r--r-- | server/src/core/vm.lua | 8 | ||||
-rw-r--r-- | server/test/document_symbol/init.lua | 54 |
3 files changed, 67 insertions, 27 deletions
diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua index b67a97db..b0802b9b 100644 --- a/server/src/core/document_symbol.lua +++ b/server/src/core/document_symbol.lua @@ -32,33 +32,45 @@ local SymbolKind = { local function buildFunc(vm, func, nextFunction, nextFinish) local source = func.source + local declarat = func.declarat local name - if source.name then - local var = vm.results.sources[source.name] - if var then - name = hoverName(var, source.name) + local var + if declarat then + if declarat.type == 'function' then + var = vm.results.sources[declarat.name] else - name = '' + var = vm.results.sources[declarat] end + end + if var then + name = hoverName(var, declarat) else name = '' end - local hover = hoverFunction(name, func) + local hover = hoverFunction(name, func, declarat and declarat.object) if not hover then return end local selectionRange - if source.name then - selectionRange = { source.name.start, source.name.finish } + local range + local kind = SymbolKind.Function + if var then + range = { math.min(source.start, declarat.start), source.finish } + selectionRange = { declarat.start, declarat.finish } + if var.parent and var.parent.value and not var.parent.value.ENV then + kind = SymbolKind.Method + end else + range = { source.start, source.finish } selectionRange = { source.start, source.start } end + return { name = name, -- 前端不支持多行 detail = hover.label:gsub('[\r\n]', ''), - kind = SymbolKind.Function, - range = { source.start, source.finish }, + kind = kind, + range = range, selectionRange = selectionRange, } end diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua index b4948e62..5ccada8e 100644 --- a/server/src/core/vm.lua +++ b/server/src/core/vm.lua @@ -334,6 +334,10 @@ function mt:setValue(var, value, source) error('Cant set value list') end value = value or self:createValue('any', source) + if source and source.start then + self:addInfo(var, 'set', source) + self:addInfo(value, 'set', source) + end if var.value then if value.type == 'any' then self:mergeChild(var.value, value) @@ -344,10 +348,6 @@ function mt:setValue(var, value, source) else var.value = value end - if source and source.start then - self:addInfo(var, 'set', source) - self:addInfo(value, 'set', source) - end return value end diff --git a/server/test/document_symbol/init.lua b/server/test/document_symbol/init.lua index 4f806bfe..869e2939 100644 --- a/server/test/document_symbol/init.lua +++ b/server/test/document_symbol/init.lua @@ -112,16 +112,44 @@ end } } ---TEST [[ ---local f = function () ---end ---]] ---{ --- [1] = { --- name = 'f', --- detail = 'function f()', --- kind = SymbolKind.Function, --- range = {11, 25}, --- selectionRange = {11, 11}, --- } ---} +TEST [[ +f = function () +end +]] +{ + [1] = { + name = 'f', + detail = 'function f()', + kind = SymbolKind.Function, + range = {1, 19}, + selectionRange = {1, 1}, + } +} + +TEST [[ +local f = function () +end +]] +{ + [1] = { + name = 'f', + detail = 'function f()', + kind = SymbolKind.Function, + range = {7, 25}, + selectionRange = {7, 7}, + } +} + +TEST [[ +function mt:add() +end +]] +{ + [1] = { + name = 'mt:add', + detail = 'function mt:add()', + kind = SymbolKind.Method, + range = {1, 21}, + selectionRange = {13, 15}, + } +} |