From a6fc1ae6fb30a04026518601623278434d474f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 18 Aug 2021 15:32:06 +0800 Subject: cleanup --- script/provider/provider.lua | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'script/provider/provider.lua') diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 5cb0151e..e1cb86c3 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -39,9 +39,6 @@ local function isValidLuaUri(uri) if not files.isLua(uri) then return false end - if not files.isOpen(uri) then - return false - end if workspace.isIgnored(uri) and not files.isLibrary(uri) then return false @@ -67,24 +64,13 @@ proto.on('initialized', function (params) updateConfig() local registrations = {} - nonil.enable() - if client.info.capabilities.workspace.didChangeWatchedFiles.dynamicRegistration then + if client.getAbility 'workspace.didChangeWatchedFiles.dynamicRegistration' + and workspace.path then -- 监视文件变化 - registrations[#registrations+1] = { - id = 'workspace/didChangeWatchedFiles', - method = 'workspace/didChangeWatchedFiles', - registerOptions = { - watchers = { - { - globPattern = '**/', - kind = 1 | 2 | 4, - } - }, - }, - } + client.watchFiles(workspace.path) end - if client.info.capabilities.workspace.didChangeConfiguration.dynamicRegistration then + if client.getAbility 'workspace.didChangeConfiguration.dynamicRegistration' then -- 监视配置变化 registrations[#registrations+1] = { id = 'workspace/didChangeConfiguration', @@ -92,8 +78,6 @@ proto.on('initialized', function (params) } end - nonil.disable() - if #registrations ~= 0 then proto.awaitRequest('client/registerCapability', { registrations = registrations @@ -125,7 +109,8 @@ proto.on('workspace/didChangeWatchedFiles', function (params) workspace.awaitReady() for _, change in ipairs(params.changes) do local uri = change.uri - if not workspace.isWorkspaceUri(uri) then + if not workspace.isWorkspaceUri(uri) + and not files.isLibrary(uri) then goto CONTINUE end if change.type == define.FileChangeType.Created then @@ -140,9 +125,11 @@ proto.on('workspace/didChangeWatchedFiles', function (params) files.remove(curi) end elseif change.type == define.FileChangeType.Changed then - -- 如果文件处于关闭状态,则立即更新;否则等待didChange协议来更新 if isValidLuaUri(uri) then - files.setText(uri, pub.awaitTask('loadFile', uri), false) + -- 如果文件处于关闭状态,则立即更新;否则等待didChange协议来更新 + if not files.isOpen(uri) then + files.setText(uri, pub.awaitTask('loadFile', uri), false) + end else local path = furi.decode(uri) local filename = fs.path(path):filename():string() -- cgit v1.2.3