diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-02-15 15:08:51 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-02-15 15:09:15 +0800 |
commit | 08a8a5ddb05610e282b3d4bed438aa779a0789f2 (patch) | |
tree | 7380248f928dd0bb8505bbe99b66d0276987a22d /script/workspace | |
parent | 30a3c34fdc23bd8b6d08e0782971d53004f8c25e (diff) | |
download | lua-language-server-08a8a5ddb05610e282b3d4bed438aa779a0789f2.zip |
should normalize path in filewatch
Diffstat (limited to 'script/workspace')
-rw-r--r-- | script/workspace/require-path.lua | 10 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 52 |
2 files changed, 14 insertions, 48 deletions
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua index e51d1219..c319cbad 100644 --- a/script/workspace/require-path.lua +++ b/script/workspace/require-path.lua @@ -81,7 +81,7 @@ function mt:getRequireResultByPath(path) for _, searcher in ipairs(searchers) do local isAbsolute = searcher:match '^[/\\]' or searcher:match '^%a+%:' - searcher = workspace.normalize(searcher) + searcher = files.normalize(searcher) if searcher:sub(1, 1) == '.' then strict = true end @@ -158,7 +158,7 @@ function mt:getVisiblePath(path) and not self.scp:isLinkedUri(uri) then return {} end - path = workspace.normalize(path) + path = files.normalize(path) local result = self.visibleCache[path] if not result then result = self:getRequireResultByPath(path) @@ -196,7 +196,7 @@ function mt:searchUrisByRequireName(name) for _, searcher in ipairs(searchers) do local fspath = searcher:gsub('%?', (path:gsub('%%', '%%%%'))) - fspath = workspace.normalize(fspath) + fspath = files.normalize(fspath) local tail = '/' .. furi.encode(fspath):gsub('^file:[/]*', '') for uri in files.eachFile(self.scp.uri) do if not searcherMap[uri] @@ -212,7 +212,7 @@ function mt:searchUrisByRequireName(name) or relative == '/' or relative == '' then results[#results+1] = uri - searcherMap[uri] = workspace.normalize(relative .. searcher) + searcherMap[uri] = files.normalize(relative .. searcher) end end end @@ -294,7 +294,7 @@ function m.isMatchedUri(suri, uri, name) for _, searcher in ipairs(searchers) do local fspath = searcher:gsub('%?', (path:gsub('%%', '%%%%'))) - fspath = workspace.normalize(fspath) + fspath = files.normalize(fspath) local tail = '/' .. furi.encode(fspath):gsub('^file:[/]*', '') if util.stringEndWith(uri, tail) then local parentUri = files.getLibraryUri(suri, uri) or uri diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 9d701167..3e85e0fc 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -217,14 +217,14 @@ function m.getLibraryMatchers(scp) for _, path in ipairs(config.get(scp.uri, 'Lua.workspace.library')) do path = m.getAbsolutePath(scp.uri, path) if path then - librarys[m.normalize(path)] = true + librarys[files.normalize(path)] = true end end local metaPaths = scp:get 'metaPaths' log.debug('meta path:', inspect(metaPaths)) if metaPaths then for _, metaPath in ipairs(metaPaths) do - librarys[m.normalize(metaPath)] = true + librarys[files.normalize(metaPath)] = true end end @@ -326,7 +326,7 @@ function m.awaitPreload(scp) if scp.uri and not scp:get('bad root') then log.info('Scan files at:', scp:getName()) - scp:gc(fw.watch(m.normalize(furi.decode(scp.uri)), true, function (path) + scp:gc(fw.watch(files.normalize(furi.decode(scp.uri)), true, function (path) local rpath = m.getRelativePath(path) if native(rpath) then return false @@ -401,52 +401,18 @@ function m.findUrisByFilePath(path) return results end ----@param path string ----@return string -function m.normalize(path) - path = path:gsub('%$%{(.-)%}', function (key) - if key == '3rd' then - return (ROOT / 'meta' / '3rd'):string() - end - if key:sub(1, 4) == 'env:' then - local env = os.getenv(key:sub(5)) - return env - end - end) - path = util.expandPath(path) - path = path:gsub('^%.[/\\]+', '') - for _ = 1, 1000 do - if path:sub(1, 2) == '..' then - break - end - local count - path, count = path:gsub('[^/\\]+[/\\]+%.%.[/\\]', '/', 1) - if count == 0 then - break - end - end - if platform.OS == 'Windows' then - path = path:gsub('[/\\]+', '\\') - :gsub('[/\\]+$', '') - :gsub('^(%a:)$', '%1\\') - else - path = path:gsub('[/\\]+', '/') - :gsub('[/\\]+$', '') - end - return path -end ---@param folderUri? uri ---@param path string ---@return string? function m.getAbsolutePath(folderUri, path) - path = m.normalize(path) + path = files.normalize(path) if fs.path(path):is_relative() then if not folderUri then return nil end local folderPath = furi.decode(folderUri) - path = m.normalize(folderPath .. '/' .. path) + path = files.normalize(folderPath .. '/' .. path) end return path end @@ -465,14 +431,14 @@ function m.getRelativePath(uriOrPath) end local scp = scope.getScope(uri) if not scp.uri then - local relative = m.normalize(path) + local relative = files.normalize(path) return relative:gsub('^[/\\]+', ''), false end - local _, pos = m.normalize(path):find(furi.decode(scp.uri), 1, true) + local _, pos = files.normalize(path):find(furi.decode(scp.uri), 1, true) if pos then - return m.normalize(path:sub(pos + 1)):gsub('^[/\\]+', ''), true + return files.normalize(path:sub(pos + 1)):gsub('^[/\\]+', ''), true else - return m.normalize(path):gsub('^[/\\]+', ''), false + return files.normalize(path):gsub('^[/\\]+', ''), false end end |