diff options
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/files.lua | 32 | ||||
-rw-r--r-- | script-beta/proto/proto.lua | 8 | ||||
-rw-r--r-- | script-beta/provider/init.lua | 3 | ||||
-rw-r--r-- | script-beta/service/service.lua | 12 |
4 files changed, 46 insertions, 9 deletions
diff --git a/script-beta/files.lua b/script-beta/files.lua index ac27117c..9873cf95 100644 --- a/script-beta/files.lua +++ b/script-beta/files.lua @@ -69,16 +69,30 @@ function m.setText(uri, text) return end file.text = text + file.lastAst = file.ast file.vm = nil file.lines = nil file.ast = nil file.globals = nil file.links = nil m.globalVersion = m.globalVersion + 1 + m.needRefreshUri = originUri +end + +--- 刷新缓存 +---|必须在自动完成请求后执行,否则会影响自动完成的响应速度 +function m.refresh() + local uri = m.needRefreshUri + if not uri then + return false + end + log.debug('Refresh cache.') + m.needRefreshUri = nil vm.refreshCache() local diagnostic = require 'provider.diagnostic' - diagnostic.refresh(originUri) + diagnostic.refresh(uri) + return true end --- 监听编译完成 @@ -125,7 +139,7 @@ function m.remove(uri) m.globalVersion = m.globalVersion + 1 vm.refreshCache() - local diagnostic = require 'service.diagnostic' + local diagnostic = require 'provider.diagnostic' diagnostic.refresh(file.uri) diagnostic.clear(file.uri) end @@ -167,6 +181,20 @@ function m.getAst(uri) return file.ast end +function m.getLastAst(uri) + if platform.OS == 'Windows' then + uri = uri:lower() + end + local file = m.fileMap[uri] + if file.ast then + return file.ast + end + if file.lastAst then + return file.lastAst + end + return m.getAst(uri) +end + --- 获取文件行信息 ---@param uri string ---@return table lines diff --git a/script-beta/proto/proto.lua b/script-beta/proto/proto.lua index f04653d5..5e1ad38f 100644 --- a/script-beta/proto/proto.lua +++ b/script-beta/proto/proto.lua @@ -34,7 +34,7 @@ function m.response(id, res) data.id = id data.result = res local buf = jsonrpc.encode(data) - log.debug('Response', id, #buf) + --log.debug('Response', id, #buf) io.stdout:write(buf) end @@ -50,7 +50,7 @@ function m.responseErr(id, code, message) message = message, } } - log.debug('ResponseErr', id, #buf) + --log.debug('ResponseErr', id, #buf) io.stdout:write(buf) end @@ -59,7 +59,7 @@ function m.notify(name, params) method = name, params = params, } - log.debug('Notify', name, #buf) + --log.debug('Notify', name, #buf) io.stdout:write(buf) end @@ -70,7 +70,7 @@ function m.awaitRequest(name, params) method = name, params = params, } - log.debug('Request', name, #buf) + --log.debug('Request', name, #buf) io.stdout:write(buf) return await.wait(function (waker) m.waiting[id] = waker diff --git a/script-beta/provider/init.lua b/script-beta/provider/init.lua index 15731b46..985ec6be 100644 --- a/script-beta/provider/init.lua +++ b/script-beta/provider/init.lua @@ -140,7 +140,9 @@ proto.on('textDocument/didChange', function (params) local uri = doc.uri local text = change[1].text if files.isLua(uri) or files.isOpen(uri) then + log.debug('didChange:', uri) files.setText(uri, text) + log.debug('setText:', #text) end end) @@ -296,6 +298,7 @@ end) proto.on('textDocument/completion', function (params) --log.info(util.dump(params)) local core = require 'core.completion' + log.debug('completion:', params.context and params.context.triggerKind, params.context and params.context.triggerCharacter) local uri = params.textDocument.uri if not files.exists(uri) then return nil diff --git a/script-beta/service/service.lua b/script-beta/service/service.lua index e1cb604b..9226492a 100644 --- a/script-beta/service/service.lua +++ b/script-beta/service/service.lua @@ -4,6 +4,7 @@ local await = require 'await' local timer = require 'timer' local proto = require 'proto' local vm = require 'vm' +local files = require 'files' local m = {} m.type = 'service' @@ -115,11 +116,16 @@ end function m.startTimer() while true do + ::CONTINUE:: pub.step() - if not await.step() then - thread.sleep(0.001) - timer.update() + if await.step() then + goto CONTINUE end + if files.refresh() then + goto CONTINUE + end + thread.sleep(0.001) + timer.update() end end |