diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-03-17 19:42:47 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-03-17 19:42:47 +0800 |
commit | 924896a13cca2f027916b9eb3601c1267b61b945 (patch) | |
tree | e15a71dfcc3a989c66ae4d5fccfe45b581daafca /script/workspace | |
parent | b947086c5b2db7899c692878234a279aff4dd321 (diff) | |
download | lua-language-server-924896a13cca2f027916b9eb3601c1267b61b945.zip |
fix #453 `Lua.runtime.path` supports absolute path
Diffstat (limited to 'script/workspace')
-rw-r--r-- | script/workspace/require-path.lua | 38 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 6 |
2 files changed, 29 insertions, 15 deletions
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua index 4503f0ee..220755b4 100644 --- a/script/workspace/require-path.lua +++ b/script/workspace/require-path.lua @@ -18,7 +18,7 @@ local function getOnePath(path, searcher) for pos = start, #stemPath do local word = stemPath:sub(start, pos) local newSearcher = stemSearcher:gsub('%?', (word:gsub('%%', '%%%%'))) - if newSearcher == stemPath then + if files.eq(newSearcher, stemPath) then return word end end @@ -32,21 +32,26 @@ function m.getVisiblePath(path, searchers, strict) if not m.cache[path] then local result = {} m.cache[path] = result - local pos = 1 if libraryPath then libraryPath = libraryPath:gsub('^[/\\]+', '') - pos = #libraryPath + 2 - else - path = workspace.getRelativePath(uri) end - repeat - local cutedPath = path:sub(pos) + for _, searcher in ipairs(searchers) do + local isAbsolute = searcher:match '^[/\\]' + or searcher:match '^%a+%:' + local cutedPath = path local head - if pos > 1 then - head = path:sub(1, pos - 1) + local pos = 1 + if not isAbsolute then + if libraryPath then + pos = #libraryPath + 2 + else + path = workspace.getRelativePath(uri) + end end - pos = path:match('[/\\]+()', pos) - for _, searcher in ipairs(searchers) do + repeat + cutedPath = path:sub(pos) + head = path:sub(1, pos - 1) + pos = path:match('[/\\]+()', pos) if platform.OS == 'Windows' then searcher = searcher :gsub('[/\\]+', '\\') :gsub('^[/\\]+', '') @@ -64,8 +69,8 @@ function m.getVisiblePath(path, searchers, strict) expect = expect, } end - end - until not pos or strict + until not pos or strict + end end return m.cache[path] end @@ -74,4 +79,11 @@ function m.flush() m.cache = {} end +files.watch(function (ev) + if ev == 'create' + or ev == 'remove' then + m.flush() + end +end) + return m diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 2934f0ba..e0d8dae0 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -330,6 +330,10 @@ function m.findUrisByFilePath(path) return {} end local lpath = path:gsub('[/\\]+', '/') + if lpath:match('^[/\\]') + or lpath:match('^%a+%:') then + lpath = furi.encode(lpath) + end if platform.OS == 'Windows' then lpath = lpath:lower() end @@ -471,14 +475,12 @@ function m.reload() end function m.awaitReload() - local rpath = require 'workspace.require-path' local plugin = require 'plugin' m.ready = false m.hasHitMaxPreload = false files.flushAllLibrary() files.removeAllClosed() files.flushCache() - rpath.flush() plugin.init() m.awaitPreload() m.ready = true |