summaryrefslogtreecommitdiff
path: root/script/workspace
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 /script/workspace
parentd09c74c69306fa5b3deb0db68552c9223b6d76df (diff)
downloadlua-language-server-1cc1be17cd3af205fda7ec80b333bf020a929fda.zip
handle `../?.lua`
Diffstat (limited to 'script/workspace')
-rw-r--r--script/workspace/require-path.lua34
-rw-r--r--script/workspace/workspace.lua7
2 files changed, 37 insertions, 4 deletions
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('[/\\]+$', '')