diff options
author | sumneko <sumneko@hotmail.com> | 2022-01-23 03:11:38 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2022-01-23 03:11:38 +0800 |
commit | ce3a22bacd3acd2984c14246feee9bd90283279a (patch) | |
tree | e27056967c9f48ecb81495fa78d5f197677ca706 /script/workspace | |
parent | 37760683528051654ceff5026b28462ebc22df7c (diff) | |
download | lua-language-server-ce3a22bacd3acd2984c14246feee9bd90283279a.zip |
cleanup
Diffstat (limited to 'script/workspace')
-rw-r--r-- | script/workspace/require-path.lua | 13 | ||||
-rw-r--r-- | script/workspace/scope.lua | 10 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 26 |
3 files changed, 25 insertions, 24 deletions
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua index 874c6743..915d0c1e 100644 --- a/script/workspace/require-path.lua +++ b/script/workspace/require-path.lua @@ -4,6 +4,7 @@ local furi = require 'file-uri' local workspace = require "workspace" local config = require 'config' local collector = require 'core.collector' +local scope = require 'workspace.scope' ---@class require-path local m = {} @@ -11,7 +12,7 @@ local m = {} local function addRequireName(suri, uri, name) local separator = config.get(uri, 'Lua.completion.requireSeparator') local fsname = name:gsub('%' .. separator, '/') - local scp = workspace.getScope(suri) + local scp = scope.getScope(suri) ---@type collector local clt = scp:get('requireName') or scp:set('requireName', collector()) clt:subscribe(uri, fsname, name) @@ -43,7 +44,7 @@ function m.getVisiblePath(suri, path) path = workspace.normalize(path) local uri = furi.encode(path) local libraryPath = files.getLibraryPath(uri) - local scp = workspace.getScope(suri) + local scp = scope.getScope(suri) local cache = scp:get('visiblePath') or scp:set('visiblePath', {}) if not cache[path] then local result = {} @@ -114,7 +115,7 @@ function m.findUrisByRequirePath(suri, path) end ---@type collector - local clt = workspace.getScope(suri):get('requireName') + local clt = scope.getScope(suri):get('requireName') if clt then for _, uri in clt:each(suri, fspath) do local infos = m.getVisiblePath(suri, furi.decode(uri)) @@ -146,12 +147,12 @@ local function removeVisiblePath(uri) scp:get('visiblePath')[path] = nil scp:get('requireName'):dropUri(uri) end - workspace.getScope(nil):get('visiblePath')[path] = nil - workspace.getScope(nil):get('requireName'):dropUri(uri) + scope.getScope(nil):get('visiblePath')[path] = nil + scope.getScope(nil):get('requireName'):dropUri(uri) end function m.flush(suri) - local scp = workspace.getScope(suri) + local scp = scope.getScope(suri) scp:set('visiblePath', {}) ---@type collector local clt = scp:get('requireName') diff --git a/script/workspace/scope.lua b/script/workspace/scope.lua index 5c9a1756..4e04d720 100644 --- a/script/workspace/scope.lua +++ b/script/workspace/scope.lua @@ -37,7 +37,7 @@ function mt:isChildUri(uri) return false end if not self.uri then - return true + return false end return uri:sub(1, #self.uri) == self.uri end @@ -146,4 +146,12 @@ function m.getLinkedScope(uri) end end +---@param uri uri +---@return scope +function m.getScope(uri) + return m.getFolder(uri) + or m.getLinkedScope(uri) + or m.fallback +end + return m diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 1867f70d..e064b424 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -59,7 +59,7 @@ end m.reset() function m.getRootUri(uri) - local scp = m.getScope(uri) + local scp = scope.getScope(uri) return scp.uri end @@ -199,7 +199,7 @@ end ---@async ---@param uri uri function m.isIgnored(uri) - local scp = m.getScope(uri) + local scp = scope.getScope(uri) local path = m.getRelativePath(uri) local ignore = m.getNativeMatcher(scp) if not ignore then @@ -222,7 +222,7 @@ end ---@async function m.awaitLoadFile(uri) - local scp = m.getScope(uri) + local scp = scope.getScope(uri) local ld <close> = loading.create(scp) local native = m.getNativeMatcher(scp) log.info('Scan files at:', uri) @@ -368,7 +368,7 @@ function m.getRelativePath(uriOrPath) path = uriOrPath uri = furi.encode(uriOrPath) end - local scp = m.getScope(uri) + local scp = scope.getScope(uri) if not scp.uri then local relative = m.normalize(path) return relative:gsub('^[/\\]+', '') @@ -443,14 +443,6 @@ function m.awaitReload(scp) m.onWatch('reload', scp.uri) end ----@param uri uri ----@return scope -function m.getScope(uri) - return scope.getFolder(uri) - or scope.getLinkedScope(uri) - or scope.fallback -end - ---@return scope function m.getFirstScope() return m.folders[1] or scope.fallback @@ -462,7 +454,7 @@ function m.awaitReady(uri) if m.isReady(uri) then return end - local scp = m.getScope(uri) + local scp = scope.getScope(uri) local waitingReady = scp:get('waitingReady') or scp:set('waitingReady', {}) await.wait(function (waker) @@ -472,12 +464,12 @@ end ---@param uri uri function m.isReady(uri) - local scp = m.getScope(uri) + local scp = scope.getScope(uri) return scp:get('ready') == true end function m.getLoadingProcess(uri) - local scp = m.getScope(uri) + local scp = scope.getScope(uri) ---@type workspace.loading local ld = scp:get 'loading' if ld then @@ -492,7 +484,7 @@ config.watch(function (uri, key, value, oldValue) or key:find '^Lua.workspace' or key:find '^files' then if value ~= oldValue then - m.reload(m.getScope(uri)) + m.reload(scope.getScope(uri)) end end end) @@ -526,7 +518,7 @@ fw.event(function (changes) ---@async -- 排除类文件发生更改需要重新扫描 if filename == '.gitignore' or filename == '.gitmodules' then - local scp = m.getScope(uri) + local scp = scope.getScope(uri) if scp.type ~= 'fallback' then m.reload(scp) end |