summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--locale/en-us/script.lua2
-rw-r--r--locale/zh-cn/script.lua2
-rw-r--r--script/files.lua2
-rw-r--r--script/progress.lua12
-rw-r--r--script/provider/diagnostic.lua5
-rw-r--r--script/provider/provider.lua28
-rw-r--r--script/vm/ref.lua14
-rw-r--r--script/workspace/loading.lua2
8 files changed, 41 insertions, 26 deletions
diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua
index ff19d170..98be9bcb 100644
--- a/locale/en-us/script.lua
+++ b/locale/en-us/script.lua
@@ -490,6 +490,8 @@ WINDOW_APPLY_WHITOUT_SETTING =
'Apply but do not modify settings'
WINDOW_ASK_APPLY_LIBRARY =
'Do you need to configure your work environment as `{}`?'
+WINDOW_SEARCHING_IN_FILES =
+'Searching in files...'
CONFIG_LOAD_FAILED =
'Unable to read the settings file: {}'
diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua
index 8efde418..75026526 100644
--- a/locale/zh-cn/script.lua
+++ b/locale/zh-cn/script.lua
@@ -489,6 +489,8 @@ WINDOW_APPLY_WHITOUT_SETTING =
'应用但不修改设置'
WINDOW_ASK_APPLY_LIBRARY =
'是否需要将你的工作环境配置为 `{}` ?'
+WINDOW_SEARCHING_IN_FILES =
+'正在文件中搜索...'
CONFIG_LOAD_FAILED =
'无法读取设置文件:{}'
diff --git a/script/files.lua b/script/files.lua
index 2ddb00d6..05b7ab23 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -480,7 +480,7 @@ function m.compileState(uri, text)
end
return nil
end
- local prog <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_COMPILING, 0.5)
+ local prog <close> = progress.create(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/progress.lua b/script/progress.lua
index 5388ef6e..b43ed05b 100644
--- a/script/progress.lua
+++ b/script/progress.lua
@@ -11,7 +11,7 @@ local m = {}
m.map = {}
---@class progress
----@field _scp scope
+---@field _uri uri
local mt = {}
mt.__index = mt
mt._token = nil
@@ -85,7 +85,7 @@ function mt:_update()
and self._clock + self._delay <= time.time() then
self._updated = time.time()
self._dirty = false
- if not config.get(self._scp.uri, 'Lua.window.progressBar') then
+ if not config.get(self._uri, 'Lua.window.progressBar') then
return
end
proto.request('window/workDoneProgress/create', {
@@ -108,7 +108,7 @@ function mt:_update()
if not self._showed then
return
end
- if not config.get(self._scp.uri, 'Lua.window.progressBar') then
+ if not config.get(self._uri, 'Lua.window.progressBar') then
self:remove()
return
end
@@ -145,16 +145,16 @@ function m.update()
end
---创建一个进度条
----@param scp scope
+---@param uri uri
---@param title string # 标题
---@param delay number # 至少经过这么久之后才会显示出来
-function m.create(scp, title, delay)
+function m.create(uri, title, delay)
local prog = setmetatable({
_token = nextToken(),
_title = title,
_clock = time.time(),
_delay = delay * 1000,
- _scp = scp,
+ _uri = uri,
}, mt)
m.map[prog._token] = prog
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index ef61d0c3..b359c21c 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -221,9 +221,8 @@ function m.doDiagnostic(uri, isScopeDiag)
end
local version = files.getVersion(uri)
- local scp = scope.getScope(uri)
- local prog <close> = progress.create(scp, lang.script.WINDOW_DIAGNOSING, 0.5)
+ local prog <close> = progress.create(uri, lang.script.WINDOW_DIAGNOSING, 0.5)
prog:setMessage(ws.getRelativePath(uri))
--log.debug('Diagnostic file:', uri)
@@ -367,7 +366,7 @@ function m.awaitDiagnosticsScope(suri)
await.sleep(1.0)
end
local clock = os.clock()
- local bar <close> = progress.create(scope.getScope(suri), lang.script.WORKSPACE_DIAGNOSTIC, 1)
+ local bar <close> = progress.create(suri, lang.script.WORKSPACE_DIAGNOSTIC, 1)
local cancelled
bar:onCancel(function ()
log.info('Cancel workspace diagnostics')
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 4061f6b1..18783ccf 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -120,7 +120,7 @@ m.register 'initialized'{
---@async
function (params)
files.init()
- local _ <close> = progress.create(workspace.getFirstScope(), lang.script.WINDOW_INITIALIZING, 0.5)
+ local _ <close> = progress.create(workspace.getFirstScope().uri, lang.script.WINDOW_INITIALIZING, 0.5)
updateConfig()
local registrations = {}
@@ -293,7 +293,7 @@ m.register 'textDocument/hover' {
}
}
end
- local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_HOVER, 0.5)
+ local _ <close> = progress.create(uri, lang.script.WINDOW_PROCESSING_HOVER, 0.5)
local core = require 'core.hover'
if not files.exists(uri) then
return nil
@@ -325,7 +325,7 @@ m.register 'textDocument/definition' {
if not files.exists(uri) then
return nil
end
- local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_DEFINITION, 0.5)
+ local _ <close> = progress.create(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)
@@ -367,7 +367,7 @@ m.register 'textDocument/typeDefinition' {
if not files.exists(uri) then
return nil
end
- local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_DEFINITION, 0.5)
+ local _ <close> = progress.create(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)
@@ -409,7 +409,7 @@ m.register 'textDocument/references' {
if not files.exists(uri) then
return nil
end
- local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_REFERENCE, 0.5)
+ local _ <close> = progress.create(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)
@@ -469,7 +469,7 @@ m.register 'textDocument/rename' {
if not files.exists(uri) then
return nil
end
- local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_RENAME, 0.5)
+ local _ <close> = progress.create(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)
@@ -529,7 +529,7 @@ m.register 'textDocument/completion' {
}
}
end
- local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_COMPLETION, 0.5)
+ local _ <close> = progress.create(uri, lang.script.WINDOW_PROCESSING_COMPLETION, 0.5)
--log.info(util.dump(params))
local core = require 'core.completion'
--log.debug('textDocument/completion')
@@ -683,7 +683,7 @@ m.register 'textDocument/signatureHelp' {
if not files.exists(uri) then
return nil
end
- local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_SIGNATURE, 0.5)
+ local _ <close> = progress.create(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)
@@ -726,7 +726,7 @@ m.register 'textDocument/documentSymbol' {
function (params)
local uri = files.getRealUri(params.textDocument.uri)
workspace.awaitReady(uri)
- local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_SYMBOL, 0.5)
+ local _ <close> = progress.create(uri, lang.script.WINDOW_PROCESSING_SYMBOL, 0.5)
local core = require 'core.document-symbol'
local symbols = core(uri)
@@ -852,7 +852,7 @@ m.register 'workspace/symbol' {
abortByFileUpdate = true,
---@async
function (params)
- local _ <close> = progress.create(workspace.getFirstScope(), lang.script.WINDOW_PROCESSING_WS_SYMBOL, 0.5)
+ local _ <close> = progress.create(workspace.getFirstScope().uri, lang.script.WINDOW_PROCESSING_WS_SYMBOL, 0.5)
local core = require 'core.workspace-symbol'
local symbols = core(params.query)
@@ -906,7 +906,7 @@ m.register 'textDocument/semanticTokens/full' {
log.debug('textDocument/semanticTokens/full')
local uri = files.getRealUri(params.textDocument.uri)
workspace.awaitReady(uri)
- local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_SEMANTIC_FULL, 0.5)
+ local _ <close> = progress.create(uri, lang.script.WINDOW_PROCESSING_SEMANTIC_FULL, 0.5)
local core = require 'core.semantic-tokens'
local results = core(uri, 0, math.huge)
return {
@@ -930,7 +930,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(scope.getScope(uri), lang.script.WINDOW_PROCESSING_SEMANTIC_RANGE, 0.5)
+ local _ <close> = progress.create(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)
@@ -1101,7 +1101,7 @@ m.register 'textDocument/onTypeFormatting' {
function (params)
local uri = files.getRealUri(params.textDocument.uri)
workspace.awaitReady(uri)
- local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
+ local _ <close> = progress.create(uri, lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
local ch = params.ch
if not files.exists(uri) then
return nil
@@ -1177,7 +1177,7 @@ do
workspace.awaitReady(uri)
local edits = {}
local hint = require 'core.hint'
- local _ <close> = progress.create(scope.getScope(uri), lang.script.WINDOW_PROCESSING_HINT, 0.5)
+ local _ <close> = progress.create(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/vm/ref.lua b/script/vm/ref.lua
index 472b3b49..59b62c15 100644
--- a/script/vm/ref.lua
+++ b/script/vm/ref.lua
@@ -8,6 +8,8 @@ local globalMgr = require 'vm.global-manager'
local nodeMgr = require 'vm.node'
local files = require 'files'
local await = require 'await'
+local progress = require 'progress'
+local lang = require 'language'
local simpleSwitch
@@ -92,14 +94,24 @@ local function searchInAllFiles(suri, searcher, notify)
end
end
- for _, uri in ipairs(uris) do
+ local loading <close> = progress.create(suri, lang.script.WINDOW_SEARCHING_IN_FILES, 1)
+ local cancelled
+ loading:onCancel(function ()
+ cancelled = true
+ end)
+ for i, uri in ipairs(uris) do
if notify then
local continue = notify(uri)
if continue == false then
break
end
end
+ loading:setMessage(('%03d/%03d'):format(i, #uris))
+ loading:setPercentage(i / #uris * 100)
await.delay()
+ if cancelled then
+ break
+ end
searcher(uri)
end
end
diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua
index fa8f780f..258c67d6 100644
--- a/script/workspace/loading.lua
+++ b/script/workspace/loading.lua
@@ -176,7 +176,7 @@ m._loadings = setmetatable({}, { __mode = 'k' })
function m.create(scp)
local loading = setmetatable({
scp = scp,
- _bar = progress.create(scp, lang.script('WORKSPACE_LOADING', scp.uri), 0.5),
+ _bar = progress.create(scp.uri, lang.script('WORKSPACE_LOADING', scp.uri), 0.5),
_stash = {},
_cache = {},
}, mt)