summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-22 16:36:29 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-22 16:36:29 +0800
commit1cc1be17cd3af205fda7ec80b333bf020a929fda (patch)
treed5da46d9932d4cb2677430dec168c0ea37bc7eb6
parentd09c74c69306fa5b3deb0db68552c9223b6d76df (diff)
downloadlua-language-server-1cc1be17cd3af205fda7ec80b333bf020a929fda.zip
handle `../?.lua`
-rw-r--r--.vscode/launch.json2
-rw-r--r--changelog.md1
-rw-r--r--script/core/completion/completion.lua2
-rw-r--r--script/workspace/require-path.lua34
-rw-r--r--script/workspace/workspace.lua7
5 files changed, 40 insertions, 6 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 36a148b0..88d361b2 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -25,7 +25,7 @@
"type": "lua",
"request": "attach",
"stopOnEntry": false,
- "address": "127.0.0.1:11427",
+ "address": "127.0.0.1:11428",
"outputCapture": [
],
"sourceMaps": [
diff --git a/changelog.md b/changelog.md
index 61e351ed..eb63faa3 100644
--- a/changelog.md
+++ b/changelog.md
@@ -2,6 +2,7 @@
## 3.5.1
* `CHG` setting `type.castNumberToInteger` default by `true`
+* `CHG` improve supports for multi-workspace
* `FIX` [#1335](https://github.com/sumneko/lua-language-server/issues/1335)
* `FIX` [#1354](https://github.com/sumneko/lua-language-server/issues/1354)
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index b2f74aa8..09d276a6 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -913,7 +913,7 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
goto CONTINUE
end
local path = furi.decode(uri)
- local infos = rpath.getVisiblePath(uri, path)
+ local infos = rpath.getVisiblePath(myUri, path)
local relative = workspace.getRelativePath(path)
for _, info in ipairs(infos) do
if matchKey(literal, info.name) then
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua
index 6c550e12..204a22a6 100644
--- a/script/workspace/require-path.lua
+++ b/script/workspace/require-path.lua
@@ -39,7 +39,7 @@ function mt:getRequireNameByPath(path, searcher)
: gsub('[/\\%.]+', separator)
local stemSearcher = searcher
: gsub('%.[^%.]+$', '')
- : gsub('[/\\%.]+', separator)
+ : gsub('[/\\]+', separator)
local start = stemSearcher:match '()%?' or 1
if stemPath:sub(1, start - 1) ~= stemSearcher:sub(1, start - 1) then
return nil
@@ -58,15 +58,18 @@ end
---@return require-manager.visibleResult[]
function mt:getRequireResultByPath(path)
local uri = furi.encode(path)
- local searchers = config.get(self.scp.uri, 'Lua.runtime.path')
- local strict = config.get(self.scp.uri, 'Lua.runtime.pathStrict')
- local libUri = files.getLibraryUri(self.scp.uri, uri)
+ local searchers = config.get(self.scp.uri, 'Lua.runtime.path')
+ local strict = config.get(self.scp.uri, 'Lua.runtime.pathStrict')
+ local libUri = files.getLibraryUri(self.scp.uri, uri)
local libraryPath = libUri and furi.decode(libUri)
local result = {}
for _, searcher in ipairs(searchers) do
local isAbsolute = searcher:match '^[/\\]'
or searcher:match '^%a+%:'
searcher = workspace.normalize(searcher)
+ if searcher:sub(1, 1) == '.' then
+ strict = true
+ end
local cutedPath = path
local currentPath = path
local head
@@ -78,6 +81,29 @@ function mt:getRequireResultByPath(path)
currentPath = workspace.getRelativePath(uri)
end
end
+
+ -- handle `../?.lua`
+ local parentCount = 0
+ for _ = 1, 1000 do
+ if searcher:match '^%.%.[/\\]' then
+ parentCount = parentCount + 1
+ searcher = searcher:sub(4)
+ else
+ break
+ end
+ end
+ if parentCount > 0 then
+ local parentPath = libraryPath
+ or (self.scp.uri and furi.decode(self.scp.uri))
+ if parentPath then
+ local tail
+ for _ = 1, parentCount do
+ parentPath, tail = parentPath:match '^(.+)[/\\]([^/\\]*)$'
+ currentPath = tail .. '/' .. currentPath
+ end
+ end
+ end
+
repeat
cutedPath = currentPath:sub(pos)
head = currentPath:sub(1, pos - 1)
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index c2a5dfc0..60078975 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -383,6 +383,13 @@ function m.normalize(path)
end)
path = util.expandPath(path)
path = path:gsub('^%.[/\\]+', '')
+ for _ = 1, 1000 do
+ local count
+ path, count = path:gsub('[^/\\]+[/\\]%.%.', '')
+ if count == 0 then
+ break
+ end
+ end
if platform.OS == 'Windows' then
path = path:gsub('[/\\]+', '\\')
:gsub('[/\\]+$', '')