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 | |
parent | 37760683528051654ceff5026b28462ebc22df7c (diff) | |
download | lua-language-server-ce3a22bacd3acd2984c14246feee9bd90283279a.zip |
cleanup
-rw-r--r-- | script/client.lua | 12 | ||||
-rw-r--r-- | script/config/loader.lua | 5 | ||||
-rw-r--r-- | script/files.lua | 2 | ||||
-rw-r--r-- | script/library.lua | 3 | ||||
-rw-r--r-- | script/plugin.lua | 4 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 7 | ||||
-rw-r--r-- | script/provider/provider.lua | 24 | ||||
-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 |
10 files changed, 54 insertions, 52 deletions
diff --git a/script/client.lua b/script/client.lua index 4f7658e8..86b13179 100644 --- a/script/client.lua +++ b/script/client.lua @@ -7,6 +7,7 @@ local config = require 'config' local converter = require 'proto.converter' local json = require 'json-beautify' local await = require 'await' +local scope = require 'workspace.scope' local m = {} @@ -204,8 +205,7 @@ end ---@param changes config.change[] ---@return boolean local function applyConfig(cfg, uri, changes) - local ws = require 'workspace' - local scp = ws.getScope(uri) + local scp = scope.getScope(uri) local ok = false for _, change in ipairs(changes) do if scp:isChildUri(change.uri) @@ -222,8 +222,7 @@ local function tryModifySpecifiedConfig(uri, finalChanges) return false end local workspace = require 'workspace' - local loader = require 'config.loader' - local scp = workspace.getScope(uri) + local scp = scope.getScope(uri) if scp:get('lastLocalType') ~= 'json' then return false end @@ -249,7 +248,7 @@ local function tryModifyRC(uri, finalChanges, create) if not buf and not create then return false end - local scp = workspace.getScope(uri) + local scp = scope.getScope(uri) local rc = scp:get('lastRCConfig') or { ['$schema'] = lang.id == 'zh-cn' and [[https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema-zh-cn.json]] or [[https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json]] } @@ -268,8 +267,7 @@ local function tryModifyClient(uri, finalChanges) if not m.getOption 'changeConfiguration' then return false end - local ws = require 'workspace' - local scp = ws.getScope(uri) + local scp = scope.getScope(uri) local scpChanges = {} for _, change in ipairs(finalChanges) do if change.uri diff --git a/script/config/loader.lua b/script/config/loader.lua index b2cf6fd3..1b520c15 100644 --- a/script/config/loader.lua +++ b/script/config/loader.lua @@ -3,6 +3,7 @@ local proto = require 'proto' local lang = require 'language' local util = require 'utility' local workspace = require 'workspace' +local scope = require 'workspace.scope' local function errorMessage(msg) proto.notify('window/showMessage', { @@ -16,7 +17,7 @@ end local m = {} function m.loadRCConfig(uri, filename) - local scp = workspace.getScope(uri) + local scp = scope.getScope(uri) local path = workspace.getAbsolutePath(uri, filename) if not path then scp:set('lastRCConfig', nil) @@ -37,7 +38,7 @@ function m.loadRCConfig(uri, filename) end function m.loadLocalConfig(uri, filename) - local scp = workspace.getScope(uri) + local scp = scope.getScope(uri) local path = workspace.getAbsolutePath(uri, filename) if not path then scp:set('lastLocalConfig', nil) diff --git a/script/files.lua b/script/files.lua index 4b7f8cf2..10b02b2d 100644 --- a/script/files.lua +++ b/script/files.lua @@ -485,7 +485,7 @@ function m.compileState(uri, text) end return nil end - local prog <close> = progress.create(ws.getScope(uri), lang.script.WINDOW_COMPILING, 0.5) + local prog <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_COMPILING, 0.5) prog:setMessage(ws.getRelativePath(uri)) local clock = os.clock() local state, err = parser.compile(text diff --git a/script/library.lua b/script/library.lua index 1c8d33f3..d95b0fa1 100644 --- a/script/library.lua +++ b/script/library.lua @@ -12,6 +12,7 @@ local await = require 'await' local timer = require 'timer' local encoder = require 'encoder' local ws = require 'workspace.workspace' +local scope = require 'workspace.scope' local m = {} @@ -203,7 +204,7 @@ end local function initBuiltIn(uri) log.info('Init builtin library at:', uri) - local scp = ws.getScope(uri) + local scp = scope.getScope(uri) local langID = lang.id local version = config.get(uri, 'Lua.runtime.version') local encoding = config.get(uri, 'Lua.runtime.fileEncoding') diff --git a/script/plugin.lua b/script/plugin.lua index 677644ef..145abe74 100644 --- a/script/plugin.lua +++ b/script/plugin.lua @@ -3,6 +3,7 @@ local util = require 'utility' local client = require 'client' local lang = require 'language' local await = require 'await' +local scope = require 'workspace.scope' ---@class plugin local m = {} @@ -16,8 +17,7 @@ function m.showError(scp, err) end function m.dispatch(event, uri, ...) - local ws = require 'workspace' - local scp = ws.getScope(uri) + local scp = scope.getScope(uri) local interface = scp:get('pluginInterface') if not interface then return false diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index 0655b1c7..7b5993a2 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -11,6 +11,7 @@ local progress = require "progress" local client = require 'client' local converter = require 'proto.converter' local loading = require 'workspace.loading' +local scope = require 'workspace.scope' ---@class diagnosticProvider local m = {} @@ -216,7 +217,7 @@ function m.doDiagnostic(uri, isScopeDiag) end local version = files.getVersion(uri) - local scp = ws.getScope(uri) + local scp = scope.getScope(uri) local prog <close> = progress.create(scp, lang.script.WINDOW_DIAGNOSING, 0.5) prog:setMessage(ws.getRelativePath(uri)) @@ -351,7 +352,7 @@ function m.diagnosticsScope(uri, force) if not force and delay < 0 then return end - local scp = ws.getScope(uri) + local scp = scope.getScope(uri) local id = 'diagnosticsScope:' .. scp:getName() await.close(id) await.call(function () ---@async @@ -360,7 +361,7 @@ function m.diagnosticsScope(uri, force) await.sleep(1.0) end local clock = os.clock() - local bar <close> = progress.create(ws.getScope(uri), lang.script.WORKSPACE_DIAGNOSTIC, 1) + local bar <close> = progress.create(scope.getScope(uri), lang.script.WORKSPACE_DIAGNOSTIC, 1) local cancelled bar:onCancel(function () log.debug('Cancel workspace diagnostics') diff --git a/script/provider/provider.lua b/script/provider/provider.lua index b16a076f..66999aa0 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -276,7 +276,7 @@ m.register 'textDocument/hover' { } } end - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_HOVER, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_HOVER, 0.5) local core = require 'core.hover' if not files.exists(uri) then return nil @@ -305,7 +305,7 @@ m.register 'textDocument/definition' { if not files.exists(uri) then return nil end - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_DEFINITION, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_DEFINITION, 0.5) local core = require 'core.definition' local pos = converter.unpackPosition(uri, params.position) local result = core(uri, pos) @@ -344,7 +344,7 @@ m.register 'textDocument/typeDefinition' { if not files.exists(uri) then return nil end - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_DEFINITION, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_DEFINITION, 0.5) local core = require 'core.type-definition' local pos = converter.unpackPosition(uri, params.position) local result = core(uri, pos) @@ -383,7 +383,7 @@ m.register 'textDocument/references' { if not files.exists(uri) then return nil end - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_REFERENCE, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_REFERENCE, 0.5) local core = require 'core.reference' local pos = converter.unpackPosition(uri, params.position) local result = core(uri, pos) @@ -434,7 +434,7 @@ m.register 'textDocument/rename' { if not files.exists(uri) then return nil end - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_RENAME, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_RENAME, 0.5) local core = require 'core.rename' local pos = converter.unpackPosition(uri, params.position) local result = core.rename(uri, pos, params.newName) @@ -494,7 +494,7 @@ m.register 'textDocument/completion' { } } end - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_COMPLETION, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_COMPLETION, 0.5) --log.info(util.dump(params)) local core = require 'core.completion' --log.debug('textDocument/completion') @@ -640,7 +640,7 @@ m.register 'textDocument/signatureHelp' { if not files.exists(uri) then return nil end - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_SIGNATURE, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_SIGNATURE, 0.5) local pos = converter.unpackPosition(uri, params.position) local core = require 'core.signature' local results = core(uri, pos) @@ -680,7 +680,7 @@ m.register 'textDocument/documentSymbol' { function (params) local uri = files.getRealUri(params.textDocument.uri) workspace.awaitReady(uri) - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_SYMBOL, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_SYMBOL, 0.5) local core = require 'core.document-symbol' local symbols = core(uri) @@ -815,7 +815,7 @@ m.register 'textDocument/semanticTokens/full' { function (params) local uri = files.getRealUri(params.textDocument.uri) workspace.awaitReady(uri) - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_SEMANTIC_FULL, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_SEMANTIC_FULL, 0.5) local core = require 'core.semantic-tokens' local results = core(uri, 0, math.huge) return { @@ -830,7 +830,7 @@ m.register 'textDocument/semanticTokens/range' { log.debug('textDocument/semanticTokens/range') local uri = files.getRealUri(params.textDocument.uri) workspace.awaitReady(uri) - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_SEMANTIC_RANGE, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_SEMANTIC_RANGE, 0.5) local core = require 'core.semantic-tokens' local start, finish = converter.unpackRange(uri, params.range) local results = core(uri, start, finish) @@ -918,7 +918,7 @@ m.register 'textDocument/onTypeFormatting' { function (params) local uri = files.getRealUri(params.textDocument.uri) workspace.awaitReady(uri) - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5) local ch = params.ch if not files.exists(uri) then return nil @@ -994,7 +994,7 @@ do workspace.awaitReady(uri) local edits = {} local hint = require 'core.hint' - local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_HINT, 0.5) + local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_HINT, 0.5) for _, visible in ipairs(visibles) do local piece = hint(uri, visible.start, visible.finish) if piece then 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 |