diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-23 00:05:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-23 00:05:30 +0800 |
commit | 6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444 (patch) | |
tree | fdc22d78150fd1c5edc46732c8b151ccfefb519f /test/crossfile/document_symbol.lua | |
parent | d0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (diff) | |
download | lua-language-server-6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444.zip |
正路目录
Diffstat (limited to 'test/crossfile/document_symbol.lua')
-rw-r--r-- | test/crossfile/document_symbol.lua | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/test/crossfile/document_symbol.lua b/test/crossfile/document_symbol.lua new file mode 100644 index 00000000..997d42c5 --- /dev/null +++ b/test/crossfile/document_symbol.lua @@ -0,0 +1,121 @@ +local service = require 'service' +local workspace = require 'workspace' +local fs = require 'bee.filesystem' +local core = require 'core' +local uric = require 'uri' + +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, +} + +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 + +rawset(_G, 'TEST', true) + +function TEST(data) + local lsp = service() + local ws = workspace(lsp, 'test') + lsp.workspace = ws + + local targetUri = uric.encode(fs.path(data[1].path)) + local sourceUri = uric.encode(fs.path(data[2].path)) + + lsp:saveText(sourceUri, 1, data[2].content) + ws:addFile(uric.decode(sourceUri)) + lsp:saveText(targetUri, 1, data[1].content) + ws:addFile(uric.decode(targetUri)) + while lsp._needCompile[1] do + lsp:compileVM(lsp._needCompile[1]) + end + + local sourceVM = lsp:getVM(sourceUri) + assert(sourceVM) + local result = core.documentSymbol(sourceVM) + assert(eq(data.symbol, result)) +end + +TEST { + { + path = 'a.lua', + content = 'return function () end', + }, + { + path = 'b.lua', + content = [[ +local t = { + x = require 'a', +} + ]], + }, + symbol = { + [1] = { + name = 't', + detail = EXISTS, + kind = SymbolKind.Variable, + range = {7, 7}, + selectionRange = {7, 7}, + valueRange = {11, 34}, + children = { + [1] = { + name = 'x', + detail = EXISTS, + kind = SymbolKind.Class, + range = {17, 17}, + selectionRange = {17, 17}, + valueRange = {21, 31}, + }, + } + } + } +} |