diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-06-30 21:09:18 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-06-30 21:09:18 +0800 |
commit | 8abe15deac954ee0c1c0a155c2490289dfd37b04 (patch) | |
tree | f90d0a626dec00333866537d5ca6dc4d2a2ce5b1 | |
parent | b7caff0e2668dcad90d4e91c61736202000bc243 (diff) | |
download | lua-language-server-8abe15deac954ee0c1c0a155c2490289dfd37b04.zip |
reports initialization progress
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | locale/en-us/script.lua | 2 | ||||
-rw-r--r-- | locale/zh-cn/script.lua | 2 | ||||
-rw-r--r-- | script/provider/provider.lua | 25 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 12 |
5 files changed, 36 insertions, 6 deletions
diff --git a/changelog.md b/changelog.md index 0d8e61ae..d0b1192a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,7 @@ # changelog ## 2.0.5 +* `NEW` `hover` and `completion` reports initialization progress * `CHG` `class field` consider implicit definition ```lua ---@class Class diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index 69f97bb1..886f4d31 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -154,11 +154,11 @@ HOVER_STRING_BYTES = '{} bytes' HOVER_STRING_CHARACTERS = '{} bytes, {} characters' HOVER_MULTI_DEF_PROTO = '({} definitions, {} prototypes)' HOVER_MULTI_PROTO_NOT_FUNC = '({} non functional definition)' -HOVER_MORE_ENUMS = '|...(+{})' HOVER_USE_LUA_PATH = '(Search path: `{}`)' HOVER_EXTENDS = 'Expand to {}' HOVER_TABLE_TIME_UP = 'Partial type inference has been disabled for performance reasons.' +HOVER_WS_LOADING = 'Workspace loading: {} / {}' ACTION_DISABLE_DIAG = 'Disable diagnostics in the workspace ({}).' ACTION_MARK_GLOBAL = 'Mark `{}` as defined global.' diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index e949ad31..51d2a284 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -153,11 +153,11 @@ HOVER_STRING_BYTES = '{} 个字节' HOVER_STRING_CHARACTERS = '{} 个字节,{} 个字符' HOVER_MULTI_DEF_PROTO = '({} 个定义,{} 个原型)' HOVER_MULTI_PROTO_NOT_FUNC = '({} 个非函数定义)' -HOVER_MORE_ENUMS = '|...(+{})' HOVER_USE_LUA_PATH = '(搜索路径: `{}`)' HOVER_EXTENDS = '展开为 {}' HOVER_TABLE_TIME_UP = '出于性能考虑,已禁用了部分类型推断。' +HOVER_WS_LOADING = '正在加载工作目录:{} / {}' ACTION_DISABLE_DIAG = '在工作区禁用诊断 ({})。' ACTION_MARK_GLOBAL = '标记 `{}` 为已定义的全局变量。' diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 5b1200cc..0249ffca 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -293,7 +293,15 @@ end) proto.on('textDocument/hover', function (params) await.close 'hover' await.setID 'hover' - workspace.awaitReady() + if not workspace.isReady() then + local count, max = workspace.getLoadProcess() + return { + contents = { + value = lang.script('HOVER_WS_LOADING', count, max), + kind = 'markdown', + } + } + end local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_HOVER, 0.5) local core = require 'core.hover' local doc = params.textDocument @@ -439,7 +447,20 @@ end) proto.on('textDocument/completion', function (params) await.close 'completion' await.setID 'completion' - workspace.awaitReady() + if not workspace.isReady() then + local count, max = workspace.getLoadProcess() + return { + { + label = lang.script('HOVER_WS_LOADING', count, max),textEdit = { + range = { + start = params.position, + ['end'] = params.position, + }, + newText = '', + }, + } + } + end local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_COMPLETION, 0.5) --log.info(util.dump(params)) local core = require 'core.completion' diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 5350369e..5ffcac5c 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -9,8 +9,6 @@ local await = require 'await' local proto = require 'proto.proto' local lang = require 'language' local library = require 'library' -local sp = require 'bee.subprocess' -local timer = require 'timer' local progress = require 'progress' local define = require "proto.define" @@ -19,6 +17,8 @@ m.type = 'workspace' m.nativeVersion = -1 m.libraryVersion = -1 m.nativeMatcher = nil +m.fileLoaded = 0 +m.fileFound = 0 m.waitingReady = {} m.requireCache = {} m.cache = {} @@ -282,6 +282,8 @@ function m.awaitPreload() diagnostic.pause() m.libraryMatchers = nil m.nativeMatcher = nil + m.fileLoaded = 0 + m.fileFound = 0 m.cache = {} local progressBar <close> = progress.create(lang.script.WORKSPACE_LOADING) local progressData = { @@ -291,6 +293,8 @@ function m.awaitPreload() update = function (self) progressBar:setMessage(('%d/%d'):format(self.read, self.max)) progressBar:setPercentage(self.read / self.max * 100) + m.fileLoaded = self.read + m.fileFound = self.max end } log.info('Preload start.') @@ -501,6 +505,10 @@ function m.isReady() return m.ready == true end +function m.getLoadProcess() + return m.fileLoaded, m.fileFound +end + files.watch(function (ev, uri) if ev == 'close' and m.isIgnored(uri) |