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