diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-24 11:25:46 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-24 11:25:46 +0800 |
commit | 0f55f1535df9bfc6314dad7d339f5ebeeced1f5d (patch) | |
tree | 34a4d7714883b97e6b4f7ec756caeaef3fc5bbc5 | |
parent | 40a7b97a74bb8fde75ebf5ab5924bc2c80411182 (diff) | |
download | lua-language-server-0f55f1535df9bfc6314dad7d339f5ebeeced1f5d.zip |
修正require XXX 的hover不正确的BUG
-rw-r--r-- | server/src/matcher/hover.lua | 5 | ||||
-rw-r--r-- | server/test/crossfile/hover.lua | 94 | ||||
-rw-r--r-- | server/test/crossfile/init.lua | 1 |
3 files changed, 99 insertions, 1 deletions
diff --git a/server/src/matcher/hover.lua b/server/src/matcher/hover.lua index dc7d40de..774cce92 100644 --- a/server/src/matcher/hover.lua +++ b/server/src/matcher/hover.lua @@ -388,7 +388,10 @@ local function getStringHover(result, lsp) return nil end local path = lsp.workspace:relativePathByUri(result.uri) - return ('[%s](%s)'):format(path:string(), result.uri) + return { + label = '', + description = ('[%s](%s)'):format(path:string(), result.uri), + } end return function (result, source, lsp, select) diff --git a/server/test/crossfile/hover.lua b/server/test/crossfile/hover.lua new file mode 100644 index 00000000..0fbb59e6 --- /dev/null +++ b/server/test/crossfile/hover.lua @@ -0,0 +1,94 @@ +local service = require 'service' +local workspace = require 'workspace' +local fs = require 'bee.filesystem' +local matcher = require 'matcher' + +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 + +local function catch_target(script, sep) + local list = {} + local cur = 1 + local cut = 0 + while true do + local start, finish = script:find(('<%%%s.-%%%s>'):format(sep, sep), cur) + if not start then + break + end + list[#list+1] = { start - cut, finish - 4 - cut } + cur = finish + 1 + cut = cut + 4 + end + local new_script = script:gsub(('<%%%s(.-)%%%s>'):format(sep, sep), '%1') + return new_script, list +end + +function TEST(data) + local lsp = service() + local ws = workspace(lsp, 'test') + lsp.workspace = ws + ws.root = ROOT + + local targetScript = data[1].content + local targetUri = ws:uriEncode(fs.path(data[1].path)) + + local sourceScript, sourceList = catch_target(data[2].content, '?') + local sourceUri = ws:uriEncode(fs.path(data[2].path)) + + lsp:saveText(targetUri, 1, targetScript) + lsp:saveText(sourceUri, 1, sourceScript) + ws:addFile(targetUri) + ws:addFile(sourceUri) + lsp:compileVM(targetUri) + lsp:compileVM(sourceUri) + + local sourceVM = lsp:loadVM(sourceUri) + assert(sourceVM) + local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2 + local result, source = matcher.findResult(sourceVM, sourcePos) + local hover = matcher.hover(result, source, lsp) + assert(hover) + assert(eq(hover, data.hover)) +end + +TEST { + { + path = 'a.lua', + content = '', + }, + { + path = 'b.lua', + content = 'require <?"a"?>', + }, + hover = { + label = '', + description = [[[a.lua](file:///C%3A/Users/sunyi/.vscode/extensions/sumneko.lua-language-server/server/a.lua)]], + } +} diff --git a/server/test/crossfile/init.lua b/server/test/crossfile/init.lua index 81243416..e68a253c 100644 --- a/server/test/crossfile/init.lua +++ b/server/test/crossfile/init.lua @@ -1 +1,2 @@ require 'crossfile.definition' +require 'crossfile.hover' |