summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/matcher/document_symbol.lua61
-rw-r--r--server/test/crossfile/hover.lua5
-rw-r--r--server/test/document_symbol/init.lua85
-rw-r--r--server/test/main.lua1
4 files changed, 120 insertions, 32 deletions
diff --git a/server/src/matcher/document_symbol.lua b/server/src/matcher/document_symbol.lua
index 3c636941..b6802c93 100644
--- a/server/src/matcher/document_symbol.lua
+++ b/server/src/matcher/document_symbol.lua
@@ -1,50 +1,50 @@
local hover = require 'matcher.hover'
local SymbolKind = {
- File = 1,
- Module = 2,
- Namespace = 3,
- Package = 4,
- Class = 5,
- Method = 6,
- Property = 7,
- Field = 8,
- Constructor = 9,
- Enum = 10,
- Interface = 11,
- Function = 12,
- Variable = 13,
- Constant = 14,
- String = 15,
- Number = 16,
- Boolean = 17,
- Array = 18,
- Object = 19,
- Key = 20,
- Null = 21,
- EnumMember = 22,
- Struct = 23,
- Event = 24,
- Operator = 25,
- TypeParameter = 26,
+ File = 1,
+ Module = 2,
+ Namespace = 3,
+ Package = 4,
+ Class = 5,
+ Method = 6,
+ Property = 7,
+ Field = 8,
+ Constructor = 9,
+ Enum = 10,
+ Interface = 11,
+ Function = 12,
+ Variable = 13,
+ Constant = 14,
+ String = 15,
+ Number = 16,
+ Boolean = 17,
+ Array = 18,
+ Object = 19,
+ Key = 20,
+ Null = 21,
+ EnumMember = 22,
+ Struct = 23,
+ Event = 24,
+ Operator = 25,
+ TypeParameter = 26,
}
local function buildFunc(vm, func, nextFunction, nextFinish)
local source = func.source
- local var = vm.results.sources[source]
+ local var = vm.results.sources[source.name]
if not var then
return
end
- local hvr = hover(var, source)
+ local hvr = hover(var, source.name)
if not hvr then
return
end
return {
name = hvr.name,
- detail = hvr.title,
+ detail = hvr.label,
kind = SymbolKind.Function,
range = { source.start, source.finish },
- selectionRange = { source.start, source.start },
+ selectionRange = { source.name.start, source.name.finish },
}
end
@@ -71,7 +71,6 @@ return function (vm)
break
end
symbols[1] = buildFunc(vm, func, nextFunction, nextFinish)
- do break end
end
return symbols
diff --git a/server/test/crossfile/hover.lua b/server/test/crossfile/hover.lua
index 51ac85bd..32fd7580 100644
--- a/server/test/crossfile/hover.lua
+++ b/server/test/crossfile/hover.lua
@@ -113,6 +113,7 @@ TEST {
},
hover = {
label = 'function f(a: any, b: any)',
+ name = 'f',
}
}
@@ -133,6 +134,7 @@ TEST {
},
hover = {
label = 'function (a: any, b: any)',
+ name = '',
}
}
@@ -160,6 +162,7 @@ TEST {
]]
},
hover = {
- label = 'function mt:add(a: any, b: any)'
+ label = 'function mt:add(a: any, b: any)',
+ name = 'mt:add',
},
}
diff --git a/server/test/document_symbol/init.lua b/server/test/document_symbol/init.lua
new file mode 100644
index 00000000..5b1ed397
--- /dev/null
+++ b/server/test/document_symbol/init.lua
@@ -0,0 +1,85 @@
+local parser = require 'parser'
+local matcher = require 'matcher'
+
+local SymbolKind = {
+ File = 1,
+ Module = 2,
+ Namespace = 3,
+ Package = 4,
+ Class = 5,
+ Method = 6,
+ Property = 7,
+ Field = 8,
+ Constructor = 9,
+ Enum = 10,
+ Interface = 11,
+ Function = 12,
+ Variable = 13,
+ Constant = 14,
+ String = 15,
+ Number = 16,
+ Boolean = 17,
+ Array = 18,
+ Object = 19,
+ Key = 20,
+ Null = 21,
+ EnumMember = 22,
+ Struct = 23,
+ Event = 24,
+ Operator = 25,
+ TypeParameter = 26,
+}
+
+rawset(_G, 'TEST', true)
+
+local EXISTS = {}
+
+local function eq(a, b)
+ if a == EXISTS and b ~= nil then
+ return true
+ end
+ local tp1, tp2 = type(a), type(b)
+ if tp1 ~= tp2 then
+ return false
+ end
+ if tp1 == 'table' then
+ local mark = {}
+ for k in pairs(a) do
+ if not eq(a[k], b[k]) then
+ return false
+ end
+ mark[k] = true
+ end
+ for k in pairs(b) do
+ if not mark[k] then
+ return false
+ end
+ end
+ return true
+ end
+ return a == b
+end
+
+function TEST(script)
+ return function (expect)
+ local ast = parser:ast(script)
+ local vm = matcher.vm(ast)
+ assert(vm)
+ local result = matcher.documentSymbol(vm)
+ assert(eq(expect, result))
+ end
+end
+
+TEST [[
+local function f()
+end
+]]
+{
+ [1] = {
+ name = 'f',
+ detail = 'function f()',
+ kind = SymbolKind.Function,
+ range = {1, 22},
+ selectionRange = {16, 16},
+ }
+}
diff --git a/server/test/main.lua b/server/test/main.lua
index 02d55665..b7161870 100644
--- a/server/test/main.lua
+++ b/server/test/main.lua
@@ -33,6 +33,7 @@ local function main()
test 'hover'
test 'completion'
test 'signature'
+ test 'document_symbol'
test 'crossfile'
print('测试完成')