Skip to content

Commit 1cc1be1

Browse files
committed
handle ../?.lua
1 parent d09c74c commit 1cc1be1

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"type": "lua",
2626
"request": "attach",
2727
"stopOnEntry": false,
28-
"address": "127.0.0.1:11427",
28+
"address": "127.0.0.1:11428",
2929
"outputCapture": [
3030
],
3131
"sourceMaps": [

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 3.5.1
44
* `CHG` setting `type.castNumberToInteger` default by `true`
5+
* `CHG` improve supports for multi-workspace
56
* `FIX` [#1335](https://github.com/sumneko/lua-language-server/issues/1335)
67
* `FIX` [#1354](https://github.com/sumneko/lua-language-server/issues/1354)
78

script/core/completion/completion.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
913913
goto CONTINUE
914914
end
915915
local path = furi.decode(uri)
916-
local infos = rpath.getVisiblePath(uri, path)
916+
local infos = rpath.getVisiblePath(myUri, path)
917917
local relative = workspace.getRelativePath(path)
918918
for _, info in ipairs(infos) do
919919
if matchKey(literal, info.name) then

script/workspace/require-path.lua

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function mt:getRequireNameByPath(path, searcher)
3939
: gsub('[/\\%.]+', separator)
4040
local stemSearcher = searcher
4141
: gsub('%.[^%.]+$', '')
42-
: gsub('[/\\%.]+', separator)
42+
: gsub('[/\\]+', separator)
4343
local start = stemSearcher:match '()%?' or 1
4444
if stemPath:sub(1, start - 1) ~= stemSearcher:sub(1, start - 1) then
4545
return nil
@@ -58,15 +58,18 @@ end
5858
---@return require-manager.visibleResult[]
5959
function mt:getRequireResultByPath(path)
6060
local uri = furi.encode(path)
61-
local searchers = config.get(self.scp.uri, 'Lua.runtime.path')
62-
local strict = config.get(self.scp.uri, 'Lua.runtime.pathStrict')
63-
local libUri = files.getLibraryUri(self.scp.uri, uri)
61+
local searchers = config.get(self.scp.uri, 'Lua.runtime.path')
62+
local strict = config.get(self.scp.uri, 'Lua.runtime.pathStrict')
63+
local libUri = files.getLibraryUri(self.scp.uri, uri)
6464
local libraryPath = libUri and furi.decode(libUri)
6565
local result = {}
6666
for _, searcher in ipairs(searchers) do
6767
local isAbsolute = searcher:match '^[/\\]'
6868
or searcher:match '^%a+%:'
6969
searcher = workspace.normalize(searcher)
70+
if searcher:sub(1, 1) == '.' then
71+
strict = true
72+
end
7073
local cutedPath = path
7174
local currentPath = path
7275
local head
@@ -78,6 +81,29 @@ function mt:getRequireResultByPath(path)
7881
currentPath = workspace.getRelativePath(uri)
7982
end
8083
end
84+
85+
-- handle `../?.lua`
86+
local parentCount = 0
87+
for _ = 1, 1000 do
88+
if searcher:match '^%.%.[/\\]' then
89+
parentCount = parentCount + 1
90+
searcher = searcher:sub(4)
91+
else
92+
break
93+
end
94+
end
95+
if parentCount > 0 then
96+
local parentPath = libraryPath
97+
or (self.scp.uri and furi.decode(self.scp.uri))
98+
if parentPath then
99+
local tail
100+
for _ = 1, parentCount do
101+
parentPath, tail = parentPath:match '^(.+)[/\\]([^/\\]*)$'
102+
currentPath = tail .. '/' .. currentPath
103+
end
104+
end
105+
end
106+
81107
repeat
82108
cutedPath = currentPath:sub(pos)
83109
head = currentPath:sub(1, pos - 1)

script/workspace/workspace.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ function m.normalize(path)
383383
end)
384384
path = util.expandPath(path)
385385
path = path:gsub('^%.[/\\]+', '')
386+
for _ = 1, 1000 do
387+
local count
388+
path, count = path:gsub('[^/\\]+[/\\]%.%.', '')
389+
if count == 0 then
390+
break
391+
end
392+
end
386393
if platform.OS == 'Windows' then
387394
path = path:gsub('[/\\]+', '\\')
388395
:gsub('[/\\]+$', '')

0 commit comments

Comments
 (0)