diff options
author | sumneko <sumneko@hotmail.com> | 2022-01-23 18:37:30 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2022-01-23 18:37:30 +0800 |
commit | 37b5f6cdb45651487792758a931203a54af3dd29 (patch) | |
tree | 7ee58cf5500c56654d686a34d01b2dc0980d1da4 | |
parent | 3a0596e06cdb8f3f7e055fdcd21862de4906647e (diff) | |
download | lua-language-server-37b5f6cdb45651487792758a931203a54af3dd29.zip |
improve performance
-rw-r--r-- | script/workspace/require-path.lua | 20 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 6 |
2 files changed, 19 insertions, 7 deletions
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua index 7d6db35b..c3dc92d3 100644 --- a/script/workspace/require-path.lua +++ b/script/workspace/require-path.lua @@ -28,7 +28,10 @@ local function getOnePath(uri, path, searcher) : gsub('%.[^%.]+$', '') : gsub('[/\\%.]+', separator) local start = stemSearcher:match '()%?' or 1 - for pos = start, #stemPath do + if stemPath:sub(1, start - 1) ~= stemSearcher:sub(1, start - 1) then + return nil + end + for pos = #stemPath, start, -1 do local word = stemPath:sub(start, pos) local newSearcher = stemSearcher:gsub('%?', (word:gsub('%%', '%%%%'))) if newSearcher == stemPath then @@ -43,8 +46,12 @@ function m.getVisiblePath(suri, path) local strict = config.get(suri, 'Lua.runtime.pathStrict') path = workspace.normalize(path) local uri = furi.encode(path) - local libraryPath = furi.decode(files.getLibraryUri(suri, uri)) local scp = scope.getScope(suri) + if not scp:isChildUri(uri) + and not scp:isLinkedUri(uri) then + return {} + end + local libraryPath = furi.decode(files.getLibraryUri(suri, uri)) local cache = scp:get('visiblePath') or scp:set('visiblePath', {}) local result = cache[path] if not result then @@ -62,9 +69,13 @@ function m.getVisiblePath(suri, path) local pos = 1 if not isAbsolute then if libraryPath then - pos = #libraryPath + 2 + currentPath = currentPath:sub(#libraryPath + 2) else - currentPath = workspace.getRelativePath(uri) + local isRelative + currentPath, isRelative = workspace.getRelativePath(uri) + if not isAbsolute and not isRelative then + goto CONTINUE + end end end repeat @@ -89,6 +100,7 @@ function m.getVisiblePath(suri, path) addRequireName(suri, uri, expect) end until not pos or strict + ::CONTINUE:: end end return result diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index f9e0e2c5..9b8cb703 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -372,13 +372,13 @@ function m.getRelativePath(uriOrPath) local scp = scope.getScope(uri) if not scp.uri then local relative = m.normalize(path) - return relative:gsub('^[/\\]+', '') + return relative:gsub('^[/\\]+', ''), false end local _, pos = m.normalize(path):find(furi.decode(scp.uri), 1, true) if pos then - return m.normalize(path:sub(pos + 1)):gsub('^[/\\]+', '') + return m.normalize(path:sub(pos + 1)):gsub('^[/\\]+', ''), true else - return m.normalize(path):gsub('^[/\\]+', '') + return m.normalize(path):gsub('^[/\\]+', ''), false end end |