diff options
-rw-r--r-- | script/provider/provider.lua | 65 | ||||
-rw-r--r-- | script/workspace/scope.lua | 2 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 103 |
3 files changed, 94 insertions, 76 deletions
diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 3ca177b6..41338e59 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -211,9 +211,9 @@ m.register 'workspace/didRenameFiles' { m.register 'textDocument/didOpen' { ---@async function (params) - workspace.awaitReady() local doc = params.textDocument local uri = files.getRealUri(doc.uri) + workspace.awaitReady(uri) local text = doc.text log.debug('didOpen', uri) files.setText(uri, text, true) @@ -236,10 +236,10 @@ m.register 'textDocument/didClose' { m.register 'textDocument/didChange' { ---@async function (params) - workspace.awaitReady() local doc = params.textDocument local changes = params.contentChanges local uri = files.getRealUri(doc.uri) + workspace.awaitReady(uri) --log.debug('changes', util.dump(changes)) local text = files.getOriginText(uri) or '' local rows = files.getCachedRows(uri) @@ -288,13 +288,13 @@ m.register 'textDocument/definition' { abortByFileUpdate = true, ---@async function (params) - workspace.awaitReady() - local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_DEFINITION, 0.5) - local core = require 'core.definition' local uri = files.getRealUri(params.textDocument.uri) + workspace.awaitReady(uri) if not files.exists(uri) then return nil end + local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_DEFINITION, 0.5) + local core = require 'core.definition' local pos = converter.unpackPosition(uri, params.position) local result = core(uri, pos) if not result then @@ -327,13 +327,13 @@ m.register 'textDocument/typeDefinition' { abortByFileUpdate = true, ---@async function (params) - workspace.awaitReady() - local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_TYPE_DEFINITION, 0.5) - local core = require 'core.type-definition' local uri = files.getRealUri(params.textDocument.uri) + workspace.awaitReady(uri) if not files.exists(uri) then return nil end + local _ <close> = progress.create(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) if not result then @@ -366,13 +366,13 @@ m.register 'textDocument/references' { abortByFileUpdate = true, ---@async function (params) - workspace.awaitReady() - local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_REFERENCE, 0.5) - local core = require 'core.reference' local uri = files.getRealUri(params.textDocument.uri) + workspace.awaitReady(uri) if not files.exists(uri) then return nil end + local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_REFERENCE, 0.5) + local core = require 'core.reference' local pos = converter.unpackPosition(uri, params.position) local result = core(uri, pos) if not result then @@ -417,13 +417,13 @@ m.register 'textDocument/rename' { abortByFileUpdate = true, ---@async function (params) - workspace.awaitReady() - local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_RENAME, 0.5) - local core = require 'core.rename' local uri = files.getRealUri(params.textDocument.uri) + workspace.awaitReady(uri) if not files.exists(uri) then return nil end + local _ <close> = progress.create(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) if not result then @@ -620,15 +620,15 @@ m.register 'textDocument/signatureHelp' { abortByFileUpdate = true, ---@async function (params) - if not config.get(nil, 'Lua.signatureHelp.enable') then + local uri = files.getRealUri(params.textDocument.uri) + if not config.get(uri, 'Lua.signatureHelp.enable') then return nil end - workspace.awaitReady() - local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SIGNATURE, 0.5) - local uri = files.getRealUri(params.textDocument.uri) + workspace.awaitReady(uri) if not files.exists(uri) then return nil end + local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SIGNATURE, 0.5) local pos = converter.unpackPosition(uri, params.position) local core = require 'core.signature' local results = core(uri, pos) @@ -666,11 +666,11 @@ m.register 'textDocument/documentSymbol' { abortByFileUpdate = true, ---@async function (params) - workspace.awaitReady() - local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SYMBOL, 0.5) - local core = require 'core.document-symbol' local uri = files.getRealUri(params.textDocument.uri) + workspace.awaitReady(uri) + local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SYMBOL, 0.5) + local core = require 'core.document-symbol' local symbols = core(uri) if not symbols then return nil @@ -769,7 +769,6 @@ m.register 'workspace/symbol' { abortByFileUpdate = true, ---@async function (params) - workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_WS_SYMBOL, 0.5) local core = require 'core.workspace-symbol' @@ -803,7 +802,7 @@ m.register 'textDocument/semanticTokens/full' { ---@async function (params) local uri = files.getRealUri(params.textDocument.uri) - workspace.awaitReady() + workspace.awaitReady(uri) local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SEMANTIC_FULL, 0.5) local core = require 'core.semantic-tokens' local results = core(uri, 0, math.huge) @@ -818,7 +817,7 @@ m.register 'textDocument/semanticTokens/range' { ---@async function (params) local uri = files.getRealUri(params.textDocument.uri) - workspace.awaitReady() + workspace.awaitReady(uri) local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SEMANTIC_RANGE, 0.5) local core = require 'core.semantic-tokens' local cache = files.getOpenedCache(uri) @@ -911,10 +910,10 @@ m.register 'textDocument/onTypeFormatting' { abortByFileUpdate = true, ---@async function (params) - workspace.awaitReady() + local uri = files.getRealUri(params.textDocument.uri) + workspace.awaitReady(uri) local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5) local ch = params.ch - local uri = files.getRealUri(params.textDocument.uri) if not files.exists(uri) then return nil end @@ -948,12 +947,12 @@ m.register '$/cancelRequest' { m.register '$/requestHint' { ---@async function (params) - local core = require 'core.hint' - if not config.get(nil, 'Lua.hint.enable') then + local uri = files.getRealUri(params.textDocument.uri) + if not config.get(uri, 'Lua.hint.enable') then return end - workspace.awaitReady() - local uri = files.getRealUri(params.textDocument.uri) + workspace.awaitReady(uri) + local core = require 'core.hint' local start, finish = converter.unpackRange(uri, params.range) local results = core(uri, start, finish) local hintResults = {} @@ -972,13 +971,13 @@ m.register '$/requestHint' { do ---@async local function updateHint(uri) - if not config.get(nil, 'Lua.hint.enable') then + if not config.get(uri, 'Lua.hint.enable') then return end local id = 'updateHint' .. uri await.close(id) await.setID(id) - workspace.awaitReady() + workspace.awaitReady(uri) local visibles = files.getVisibles(uri) if not visibles then return @@ -986,7 +985,7 @@ do await.close(id) await.setID(id) await.delay() - workspace.awaitReady() + workspace.awaitReady(uri) local edits = {} local hint = require 'core.hint' local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_HINT, 0.5) diff --git a/script/workspace/scope.lua b/script/workspace/scope.lua index f0a98972..6abf30d5 100644 --- a/script/workspace/scope.lua +++ b/script/workspace/scope.lua @@ -97,7 +97,7 @@ end ---@return scope function m.getFolder(uri) for _, scope in ipairs(m.folders) do - if not uri or scope.uri:sub(1, #uri) == uri then + if not uri or scope:isChildUri(uri) then return scope end end diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index a1f57a7d..aee61366 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -16,20 +16,11 @@ local plugin = require 'plugin' local util = require 'utility' local fw = require 'filewatch' local scope = require 'workspace.scope' +local loading = require 'workspace.loading' ---@class workspace local m = {} m.type = 'workspace' -m.nativeVersion = -1 -m.libraryVersion = -1 -m.nativeMatcher = nil -m.fileLoaded = 0 -m.fileFound = 0 -m.waitingReady = {} -m.requireCache = {} -m.cache = {} -m.watchers = {} -m.matchOption = {} function m.initRoot(uri) m.rootUri = uri @@ -308,22 +299,24 @@ end --- 预读工作区内所有文件 ---@async -function m.awaitPreload() +---@param scp scope +function m.awaitPreload(scp) local diagnostic = require 'provider.diagnostic' await.close 'preload' await.setID 'preload' await.sleep(0.1) - diagnostic.pause() - m.libraryMatchers = nil - m.nativeMatcher = nil - m.fileLoaded = 0 - m.fileFound = 0 - m.cache = {} - for i, watchers in ipairs(m.watchers) do - watchers() - m.watchers[i] = nil + diagnostic.pause(scp) + + if scp:get 'watchers' then + for _, dispose in ipairs(scp:get 'watchers') do + dispose() + end end - local progressBar <close> = progress.create(lang.script.WORKSPACE_LOADING) + scp:set('watchers', {}) + + local ld = loading.create(scp) + + local progressBar <close> = progress.create(lang.script('WORKSPACE_LOADING', scp.uri)) local progressData = { max = 0, read = 0, @@ -337,6 +330,7 @@ function m.awaitPreload() end } log.info('Preload start.') + local nativeLoader = loadFileFactory(m.rootPath, progressData) local native = m.getNativeMatcher() local librarys = m.getLibraryMatchers() @@ -564,14 +558,18 @@ function m.flushCache() m.cache = {} end -function m.reload() +---@param scp scope +function m.reload(scp) if not m.inited then return end if TEST then return end - await.call(m.awaitReload) + ---@async + await.call(function () + m.awaitReload(scp) + end) end function m.init() @@ -579,39 +577,59 @@ function m.init() return end m.inited = true - m.reload() + if m.rootUri then + for _, folder in ipairs(scope.folders) do + m.reload(folder) + end + else + m.reload(scope.fallback) + end end ---@async -function m.awaitReload() - m.ready = false - m.hasHitMaxPreload = false - files.flushAllLibrary() - files.removeAllClosed() - files.flushCache() - plugin.init() - m.awaitPreload() - m.ready = true - local waiting = m.waitingReady - m.waitingReady = {} - for _, waker in ipairs(waiting) do - waker() +---@param scp scope +function m.awaitReload(scp) + files.flushAllLibrary(scp) + files.removeAllClosed(scp) + files.flushCache(scp) + plugin.init(scp) + m.awaitPreload(scp) + scp:set('ready', true) + local waiting = scp:get('waitingReady') + if waiting then + scp:set('waitingReady', nil) + for _, waker in ipairs(waiting) do + waker() + end end end +---@param uri uri +---@return scope +function m.getScope(uri) + return scope.getFolder(uri) + or scope.getLinkedScope(uri) + or scope.fallback +end + ---等待工作目录加载完成 ---@async -function m.awaitReady() - if m.isReady() then +function m.awaitReady(uri) + if m.isReady(uri) then return end + local scp = m.getScope(uri) + local waitingReady = scp:get('waitingReady') + or scp:set('waitingReady', {}) await.wait(function (waker) - m.waitingReady[#m.waitingReady+1] = waker + waitingReady[#waitingReady+1] = waker end) end -function m.isReady() - return m.ready == true +---@param uri uri +function m.isReady(uri) + local scp = m.getScope(uri) + return scp:get('ready') == true end function m.getLoadProcess() @@ -637,6 +655,7 @@ config.watch(function (key, value, oldValue) end) fw.event(function (changes) ---@async + -- TODO m.awaitReady() for _, change in ipairs(changes) do local path = change.path |