summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-09-28 02:43:52 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-09-28 02:43:52 +0800
commit274cd6b326ca6be0da65ebde79f8c48c83bc406b (patch)
treebc20cc1cc5a1be2645e18db35a4c1ef0a71c0354
parentc352af7a59b14f60ea5aca7bddfbc891068b4cb0 (diff)
downloadlua-language-server-274cd6b326ca6be0da65ebde79f8c48c83bc406b.zip
hover也显示推测的搜索路径
-rw-r--r--script-beta/core/hover/description.lua14
-rw-r--r--script-beta/workspace/workspace.lua10
-rw-r--r--test-beta/crossfile/definition.lua12
-rw-r--r--test-beta/crossfile/hover.lua17
4 files changed, 46 insertions, 7 deletions
diff --git a/script-beta/core/hover/description.lua b/script-beta/core/hover/description.lua
index 63c5afae..af6ad608 100644
--- a/script-beta/core/hover/description.lua
+++ b/script-beta/core/hover/description.lua
@@ -7,6 +7,7 @@ local markdown = require 'provider.markdown'
local config = require 'config'
local client = require 'provider.client'
local lang = require 'language'
+local platform = require 'bee.platform'
local function asString(source)
local literal = guide.getLiteral(source)
@@ -15,7 +16,7 @@ local function asString(source)
end
local parent = source.parent
if parent and parent.type == 'callargs' then
- local result
+ local result, searchers
local call = parent.parent
local func = call.node
local lib = vm.getLibrary(func)
@@ -23,20 +24,27 @@ local function asString(source)
return
end
if lib.name == 'require' then
- result = ws.findUrisByRequirePath(literal)
+ result, searchers = ws.findUrisByRequirePath(literal)
elseif lib.name == 'dofile'
or lib.name == 'loadfile' then
result = ws.findUrisByFilePath(literal)
end
if result and #result > 0 then
for i, uri in ipairs(result) do
+ local searcher = searchers and furi.decode(searchers[uri])
uri = files.getOriginUri(uri)
local path = furi.decode(uri)
if files.eq(path:sub(1, #ws.path), ws.path) then
path = path:sub(#ws.path + 1)
end
path = path:gsub('^[/\\]*', '')
- result[i] = ('* [%s](%s)'):format(path, uri)
+ if searcher then
+ searcher = ws.normalize(searcher)
+ searcher = searcher:sub(#ws.path + 1)
+ result[i] = ('* [%s](%s) (假设搜索路径包含 `%s`)'):format(path, uri, searcher)
+ else
+ result[i] = ('* [%s](%s)'):format(path, uri)
+ end
end
table.sort(result)
return table.concat(result, '\n')
diff --git a/script-beta/workspace/workspace.lua b/script-beta/workspace/workspace.lua
index 0552bf98..9ddb6bff 100644
--- a/script-beta/workspace/workspace.lua
+++ b/script-beta/workspace/workspace.lua
@@ -146,6 +146,7 @@ end
---@param path string
function m.findUrisByFilePath(path)
local results = {}
+ local posts = {}
for uri in files.eachFile() do
local pathLen = #path
local uriLen = #uri
@@ -154,10 +155,11 @@ function m.findUrisByFilePath(path)
local see = uri:sub(uriLen - pathLen + 1, uriLen)
if files.eq(see, path) then
results[#results+1] = uri
+ posts[uri] = uri:sub(1, uriLen - pathLen)
end
end
end
- return results
+ return results, posts
end
--- 查找符合指定require path的所有uri
@@ -166,19 +168,21 @@ end
function m.findUrisByRequirePath(path)
local results = {}
local mark = {}
+ local searchers = {}
local input = path:gsub('%.', '/')
:gsub('%%', '%%%%')
for _, luapath in ipairs(config.config.runtime.path) do
local part = luapath:gsub('%?', input)
- local uris = m.findUrisByFilePath(part)
+ local uris, posts = m.findUrisByFilePath(part)
for _, uri in ipairs(uris) do
if not mark[uri] then
mark[uri] = true
results[#results+1] = uri
+ searchers[uri] = posts[uri] .. luapath
end
end
end
- return results
+ return results, searchers
end
function m.normalize(path)
diff --git a/test-beta/crossfile/definition.lua b/test-beta/crossfile/definition.lua
index c5601a1f..99e1d7f2 100644
--- a/test-beta/crossfile/definition.lua
+++ b/test-beta/crossfile/definition.lua
@@ -119,6 +119,18 @@ TEST {
TEST {
{
+ path = 'aaa/bbb.lua',
+ content = '',
+ target = {0, 0},
+ },
+ {
+ path = 'b.lua',
+ content = 'require "<?bbb?>"',
+ },
+}
+
+TEST {
+ {
path = 'a.lua',
content = 'local <!t!> = 1; return <!t!>',
},
diff --git a/test-beta/crossfile/hover.lua b/test-beta/crossfile/hover.lua
index d73aeb7f..594094ba 100644
--- a/test-beta/crossfile/hover.lua
+++ b/test-beta/crossfile/hover.lua
@@ -85,7 +85,22 @@ TEST {
},
hover = {
label = '1 个字节',
- description = [[* [a.lua](file:///a.lua)]],
+ description = [[* [a.lua](file:///a.lua) (假设搜索路径包含 `?.lua`)]],
+ }
+}
+
+TEST {
+ {
+ path = 'folder/a.lua',
+ content = '',
+ },
+ {
+ path = 'b.lua',
+ content = 'require <?"a"?>',
+ },
+ hover = {
+ label = '1 个字节',
+ description = [[* [folder\a.lua](file:///folder/a.lua) (假设搜索路径包含 `folder\?.lua`)]],
}
}