summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md2
-rw-r--r--script/workspace/require-path.lua40
2 files changed, 35 insertions, 7 deletions
diff --git a/changelog.md b/changelog.md
index d3dec956..4988b337 100644
--- a/changelog.md
+++ b/changelog.md
@@ -31,6 +31,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
```
* `FIX` [#1567]
* `FIX` [#1593]
+* `FIX` [#1595]
* `FIX` [#1606]
* `FIX` [#1608]
@@ -41,6 +42,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
[#1561]: https://github.com/sumneko/lua-language-server/issues/1561
[#1567]: https://github.com/sumneko/lua-language-server/issues/1567
[#1593]: https://github.com/sumneko/lua-language-server/issues/1593
+[#1595]: https://github.com/sumneko/lua-language-server/issues/1595
[#1606]: https://github.com/sumneko/lua-language-server/issues/1606
[#1608]: https://github.com/sumneko/lua-language-server/issues/1608
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua
index 02b1996d..968511f2 100644
--- a/script/workspace/require-path.lua
+++ b/script/workspace/require-path.lua
@@ -13,6 +13,7 @@ local m = {}
---@field scp scope
---@field nameMap table<string, string>
---@field visibleCache table<string, require-manager.visibleResult[]>
+---@field requireCache table<string, table>
local mt = {}
mt.__index = mt
@@ -25,6 +26,7 @@ local function createRequireManager(scp)
scp = scp,
nameMap = {},
visibleCache = {},
+ requireCache = {},
}, mt)
end
@@ -153,14 +155,10 @@ function mt:getVisiblePath(path)
end
--- 查找符合指定require name的所有uri
----@param suri uri
---@param name string
---@return uri[]
----@return table<uri, string>?
-function mt:findUrisByRequireName(suri, name)
- if type(name) ~= 'string' then
- return {}
- end
+---@return table<uri, string>
+function mt:searchUrisByRequireName(name)
local searchers = config.get(self.scp.uri, 'Lua.runtime.path')
local strict = config.get(self.scp.uri, 'Lua.runtime.pathStrict')
local separator = config.get(self.scp.uri, 'Lua.completion.requireSeparator')
@@ -174,7 +172,6 @@ function mt:findUrisByRequireName(suri, name)
local tail = '/' .. furi.encode(fspath):gsub('^file:[/]*', '')
for uri in files.eachFile(self.scp.uri) do
if not searcherMap[uri]
- and suri ~= uri
and util.stringEndWith(uri, tail) then
local parentUri = files.getLibraryUri(self.scp.uri, uri) or self.scp.uri
if parentUri == nil or parentUri == '' then
@@ -203,6 +200,35 @@ function mt:findUrisByRequireName(suri, name)
return results, searcherMap
end
+--- 查找符合指定require name的所有uri,并排除当前文件
+---@param suri uri
+---@param name string
+---@return uri[]
+---@return table<uri, string>?
+function mt:findUrisByRequireName(suri, name)
+ if type(name) ~= 'string' then
+ return {}
+ end
+ local cache = self.requireCache[name]
+ if not cache then
+ local results, searcherMap = self:searchUrisByRequireName(name)
+ cache = {
+ results = results,
+ searcherMap = searcherMap,
+ }
+ self.requireCache[name] = cache
+ end
+ local results = {}
+ local searcherMap = {}
+ for _, uri in ipairs(cache.results) do
+ if uri ~= suri then
+ results[#results+1] = uri
+ searcherMap[uri] = cache.searcherMap[uri]
+ end
+ end
+ return results, searcherMap
+end
+
---@param uri uri
---@param path string
---@return require-manager.visibleResult[]