diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-12 17:19:03 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-12 17:19:03 +0800 |
commit | ac9e09ffb7e0dddf7e48725ce59733c53a7443b3 (patch) | |
tree | 8635af9b4e8b8b770bbb565eddeb48494dfbb5f3 | |
parent | d066720039568bab0126bc058faf23588500562a (diff) | |
download | lua-language-server-ac9e09ffb7e0dddf7e48725ce59733c53a7443b3.zip |
improve completion speed
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | script/core/completion/completion.lua | 11 | ||||
-rw-r--r-- | script/files.lua | 15 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 2 | ||||
-rw-r--r-- | script/provider/provider.lua | 2 | ||||
-rw-r--r-- | script/pub/pub.lua | 4 | ||||
-rw-r--r-- | script/service/service.lua | 51 | ||||
-rw-r--r-- | script/timer.lua | 4 |
8 files changed, 62 insertions, 30 deletions
diff --git a/changelog.md b/changelog.md index bf815b8e..35ab309c 100644 --- a/changelog.md +++ b/changelog.md @@ -8,8 +8,9 @@ + `Lua.semantic.variable` + `Lua.semantic.annotation` + `Lua.semantic.keyword` -* `CHG` diagnostic: smoother +* `CHG` completion: improve response speed * `CHG` completion: can be triggered in `LuaDoc` and strings +* `CHG` diagnostic: smoother * `CHG` settings `Lua.color.mode` removed * `FIX` [#879](https://github.com/sumneko/lua-language-server/issues/879) * `FIX` [#884](https://github.com/sumneko/lua-language-server/issues/884) diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index c457a14a..6edfac91 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -645,14 +645,11 @@ local function checkCommon(state, word, position, results) for _, data in ipairs(keyWordMap) do used[data[1]] = true end - if not config.get(state.uri, 'Lua.completion.workspaceWord') - or #word >= 2 then - results.complete = true - end if config.get(state.uri, 'Lua.completion.workspaceWord') and #word >= 2 then local myHead = word:sub(1, 2) for uri in files.eachFile() do if #results >= 100 then + results.incomplete = true break end if myUri == uri then @@ -702,6 +699,7 @@ local function checkCommon(state, word, position, results) end for str, offset in state.lua:gmatch '([%a_][%w_]+)()' do if #results >= 100 then + results.incomplete = true break end if #str >= 3 @@ -716,9 +714,6 @@ local function checkCommon(state, word, position, results) end end end - if #results >= 100 then - results.complete = false - end end local function checkKeyWord(state, start, position, word, hasSpace, afterLocal, results) @@ -1973,7 +1968,7 @@ end ---@async local function completion(uri, position, triggerCharacter) - local state = files.getState(uri) + local state = files.getLastState(uri) or files.getState(uri) if not state then return nil end diff --git a/script/files.lua b/script/files.lua index fbc158ae..516ff7ee 100644 --- a/script/files.lua +++ b/script/files.lua @@ -194,7 +194,7 @@ function m.setText(uri, text, isTrust, version) file.originText = text file.rows = nil file.words = nil - m.astMap[uri] = nil + m.astMap[uri] = nil file.cache = {} file.cacheActiveTime = math.huge m.globalVersion = m.globalVersion + 1 @@ -202,6 +202,9 @@ function m.setText(uri, text, isTrust, version) m.onWatch('version') if create then m.onWatch('create', uri) + m.onWatch('update', uri) + else + m.onWatch('update', uri) end if DEVELOP then if text ~= newText then @@ -210,7 +213,6 @@ function m.setText(uri, text, isTrust, version) end --if instance or TEST then - m.onWatch('update', uri) --else -- await.call(function () -- await.close('update:' .. uri) @@ -519,12 +521,21 @@ function m.getState(uri) if not state then state = m.compileState(uri, file.text) m.astMap[uri] = state + file.ast = state --await.delay() end file.cacheActiveTime = timer.clock() return state end +function m.getLastState(uri) + local file = m.fileMap[uri] + if not file then + return nil + end + return file.ast +end + ---设置文件的当前可见范围 ---@param uri uri ---@param ranges range[] diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index db967e81..907ed55d 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -352,7 +352,7 @@ function m.diagnosticsScope(uri, force) end await.close ('diagnosticsScope:' .. uri) await.call(function () ---@async - await.sleep(delay) + await.sleep(math.max(delay, 0.1)) local clock = os.clock() local bar <close> = progress.create(ws.getScope(uri), lang.script.WORKSPACE_DIAGNOSTIC, 1) local cancelled diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 5401ff47..1c84caf1 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -584,7 +584,7 @@ m.register 'textDocument/completion' { items[i] = item end return { - isIncomplete = not result.complete, + isIncomplete = result.incomplete, items = items, } end diff --git a/script/pub/pub.lua b/script/pub/pub.lua index fd780477..1b2dbcac 100644 --- a/script/pub/pub.lua +++ b/script/pub/pub.lua @@ -101,7 +101,7 @@ function m.popReport(brave, name, params) end --- 发布任务 ----@parma name string +---@param name string ---@param params any ---@return any ---@async @@ -122,7 +122,7 @@ end --- 发布同步任务,如果任务进入了队列,会返回执行器 --- 通过 jumpQueue 可以插队 ----@parma name string +---@param name string ---@param params any ---@param callback function function m.task(name, params, callback) diff --git a/script/service/service.lua b/script/service/service.lua index ea6ff1e5..627388d1 100644 --- a/script/service/service.lua +++ b/script/service/service.lua @@ -141,23 +141,46 @@ function m.report() t:onTimer() end -function m.startTimer() +function m.eventLoop() pub.task('timer', 1) - while true do - pub.step(not m.workingClock) - if await.step() then - m.sleeping = false - if not m.workingClock then - m.workingClock = time.monotonic() - end - else - if m.workingClock then - m.workingClock = nil - m.idleClock = time.monotonic() - m.reportStatus() + + local function doSomething() + pub.step(false) + if not await.step() then + return false + end + m.sleeping = false + if not m.workingClock then + m.workingClock = time.monotonic() + end + return true + end + + local function sleep() + if m.workingClock then + m.workingClock = nil + m.idleClock = time.monotonic() + m.reportStatus() + end + for _ = 1, 10 do + thread.sleep(0.1) + if doSomething() then + return end end + pub.step(true) + end + + while true do + if doSomething() then + goto CONTINUE + end timer.update() + if doSomething() then + goto CONTINUE + end + sleep() + ::CONTINUE:: end end @@ -234,7 +257,7 @@ function m.start() require 'provider' - m.startTimer() + m.eventLoop() end return m diff --git a/script/timer.lua b/script/timer.lua index 10ae9523..11a6687a 100644 --- a/script/timer.lua +++ b/script/timer.lua @@ -11,6 +11,7 @@ _ENV = nil local curFrame = 0 local maxFrame = 0 local curIndex = 0 +local tarFrame = 0 local freeQueue = {} local timer = {} @@ -29,7 +30,7 @@ local function mTimeout(self, timeout) if self._pauseRemaining or self._running then return end - local ti = curFrame + timeout + local ti = tarFrame + timeout local q = timer[ti] if q == nil then q = allocQueue() @@ -212,6 +213,7 @@ function m.update() curFrame = curFrame - 1 end maxFrame = maxFrame + delta + tarFrame = mathFloor(maxFrame) while curFrame < maxFrame do curFrame = curFrame + 1 onTick() |