diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-11-29 18:44:52 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-11-29 18:44:52 +0800 |
commit | ac3be36d170dfbfaa7c9f9a5d3ace10ccce8cfe4 (patch) | |
tree | 671bc8c6bc5ea5a02478b64491b1c65e71dcbbd2 /script | |
parent | 943b86f06af58216e2f99eee2a45547080980efa (diff) | |
download | lua-language-server-ac3be36d170dfbfaa7c9f9a5d3ace10ccce8cfe4.zip |
improve
Diffstat (limited to 'script')
-rw-r--r-- | script/core/modifyRequirePath.lua | 7 | ||||
-rw-r--r-- | script/files.lua | 1 | ||||
-rw-r--r-- | script/workspace/require-path.lua | 30 |
3 files changed, 32 insertions, 6 deletions
diff --git a/script/core/modifyRequirePath.lua b/script/core/modifyRequirePath.lua index 91c600ac..d0783736 100644 --- a/script/core/modifyRequirePath.lua +++ b/script/core/modifyRequirePath.lua @@ -31,13 +31,8 @@ local function checkConvert(changes, uri, renames) if type(name) ~= 'string' then return end - local uris = rpath.findUrisByRequireName(uri, name) - local ruri = uris and uris[1] - if not ruri then - return - end for _, rename in ipairs(renames) do - if rename.oldUri == ruri then + if rpath.isMatchedUri(uri, rename.oldUri, name) then local visibles = rpath.getVisiblePath(uri, furi.decode(rename.newUri)) if #visibles > 0 then local newName = visibles[1].name diff --git a/script/files.lua b/script/files.lua index 5af2d137..f0881242 100644 --- a/script/files.lua +++ b/script/files.lua @@ -667,6 +667,7 @@ function m.compileState(uri) local ws = require 'workspace' local prog <close> = progress.create(uri, lang.script.WINDOW_COMPILING, 0.5) prog:setMessage(ws.getRelativePath(uri)) + log.trace('Compile State:', uri) local clock = os.clock() local state, err = parser.compile(file.text , 'Lua' diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua index cfe89b28..f65af868 100644 --- a/script/workspace/require-path.lua +++ b/script/workspace/require-path.lua @@ -250,6 +250,36 @@ function m.findUrisByRequireName(uri, name) return mgr:findUrisByRequireName(uri, name) end +---@param suri uri +---@param uri uri +---@param name string +---@return boolean +function m.isMatchedUri(suri, uri, name) + local searchers = config.get(suri, 'Lua.runtime.path') + local strict = config.get(suri, 'Lua.runtime.pathStrict') + local separator = config.get(suri, 'Lua.completion.requireSeparator') + local path = name:gsub('%' .. separator, '/') + + for _, searcher in ipairs(searchers) do + local fspath = searcher:gsub('%?', (path:gsub('%%', '%%%%'))) + fspath = workspace.normalize(fspath) + local tail = '/' .. furi.encode(fspath):gsub('^file:[/]*', '') + if util.stringEndWith(uri, tail) then + local parentUri = files.getLibraryUri(suri, uri) or uri + if parentUri == nil or parentUri == '' then + parentUri = furi.encode '/' + end + local relative = uri:sub(#parentUri + 1):sub(1, - #tail) + if not strict + or relative == '/' + or relative == '' then + return true + end + end + end + return false +end + files.watch(function (ev, uri) for _, scp in ipairs(workspace.folders) do scp:set('requireManager', nil) |