diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-10-12 16:33:29 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-10-12 16:33:29 +0800 |
commit | ea2795520e68db8737bd6d0ab7a93d5e5a482346 (patch) | |
tree | 5f21f8392ad123497f52ab893e79cb3013879456 /script/workspace | |
parent | 896a1affdeed8304688611674df88140a5cc180e (diff) | |
download | lua-language-server-ea2795520e68db8737bd6d0ab7a93d5e5a482346.zip |
cleanup
Diffstat (limited to 'script/workspace')
-rw-r--r-- | script/workspace/require-path.lua | 34 | ||||
-rw-r--r-- | script/workspace/scope.lua | 24 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 8 |
3 files changed, 35 insertions, 31 deletions
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua index 1e7c81e5..02b1996d 100644 --- a/script/workspace/require-path.lua +++ b/script/workspace/require-path.lua @@ -170,30 +170,24 @@ function mt:findUrisByRequireName(suri, name) for _, searcher in ipairs(searchers) do local fspath = searcher:gsub('%?', (path:gsub('%%', '%%%%'))) - local fullPath = workspace.getAbsolutePath(self.scp.uri, fspath) - if fullPath then - local fullUri = furi.encode(fullPath) - if files.exists(fullUri) - and fullUri ~= suri then - results[#results+1] = fullUri - searcherMap[fullUri] = searcher - end - end + fspath = workspace.normalize(fspath) local tail = '/' .. furi.encode(fspath):gsub('^file:[/]*', '') for uri in files.eachFile(self.scp.uri) do - if not searcherMap[uri] + if not searcherMap[uri] and suri ~= uri and util.stringEndWith(uri, tail) then - local parentUri = files.getLibraryUri(self.scp.uri, uri) or self.scp.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 == "/" then - results[#results+1] = uri - end - searcherMap[uri] = workspace.normalize(relative .. searcher) - end + local parentUri = files.getLibraryUri(self.scp.uri, uri) or self.scp.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 + results[#results+1] = uri + searcherMap[uri] = workspace.normalize(relative .. searcher) + end + end end end diff --git a/script/workspace/scope.lua b/script/workspace/scope.lua index e6fcfeb7..da72a1eb 100644 --- a/script/workspace/scope.lua +++ b/script/workspace/scope.lua @@ -37,6 +37,12 @@ function mt:removeAllLinks() self._links = {} end +---@return fun(): uri +---@return table<uri, true> +function mt:eachLink() + return next, self._links +end + ---@param uri uri ---@return boolean function mt:isChildUri(uri) @@ -46,14 +52,14 @@ function mt:isChildUri(uri) if not self.uri then return false end - if self.uri == '' then - return true - end if self.uri == uri then return true end - if uri:sub(1, #self.uri) == self.uri - and uri:sub(#self.uri + 1, #self.uri + 1) == '/' then + if uri:sub(1, #self.uri) ~= self.uri then + return false + end + if uri:sub(#self.uri, #self.uri) == '/' + or uri:sub(#self.uri + 1, #self.uri + 1) == '/' then return true end return false @@ -69,10 +75,14 @@ function mt:isLinkedUri(uri) if uri == linkUri then return true end - if uri:sub(1, #linkUri) == linkUri - and uri:sub(#linkUri + 1, #linkUri + 1) == '/' then + if uri:sub(1, #linkUri) ~= linkUri then + goto CONTINUE + end + if uri:sub(#linkUri, #linkUri) == '/' + or uri:sub(#linkUri + 1, #linkUri + 1) == '/' then return true end + ::CONTINUE:: end return false end diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index a1b54f24..45fd6595 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -49,13 +49,13 @@ function m.create(uri) uri = furi.normalize(uri) end log.info('Workspace create: ', uri) + local scp = scope.createFolder(uri) + m.folders[#m.folders+1] = scp if uri == furi.encode '/' or uri == furi.encode(os.getenv 'HOME' or '') then client.showMessage('Error', lang.script('WORKSPACE_NOT_ALLOWED', furi.decode(uri))) - return + scp:set('bad root', true) end - local scp = scope.createFolder(uri) - m.folders[#m.folders+1] = scp end function m.remove(uri) @@ -306,7 +306,7 @@ function m.awaitPreload(scp) local native = m.getNativeMatcher(scp) local librarys = m.getLibraryMatchers(scp) - if scp.uri then + if scp.uri and not scp:get('bad root') then log.info('Scan files at:', scp:getName()) local count = 0 ---@async |