diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-04-02 18:30:13 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-04-02 18:30:13 +0800 |
commit | e5947d5cb525d0c3376d36be657c0f940d8bfaf8 (patch) | |
tree | 7457fbc168b3f0598038fe299b57c4e98b8400e9 /script/provider | |
parent | 55e7d5950398eb6816646d1612701565364fa08b (diff) | |
download | lua-language-server-e5947d5cb525d0c3376d36be657c0f940d8bfaf8.zip |
fix #482
Diffstat (limited to 'script/provider')
-rw-r--r-- | script/provider/completion.lua | 14 | ||||
-rw-r--r-- | script/provider/provider.lua | 50 | ||||
-rw-r--r-- | script/provider/semantic-tokens.lua | 10 |
3 files changed, 52 insertions, 22 deletions
diff --git a/script/provider/completion.lua b/script/provider/completion.lua index 9cf3a39a..1adcc47a 100644 --- a/script/provider/completion.lua +++ b/script/provider/completion.lua @@ -1,4 +1,6 @@ -local proto = require 'proto' +local proto = require 'proto' +local nonil = require 'without-check-nil' +local client = require 'provider.client' local isEnable = false @@ -15,6 +17,11 @@ local function enable() if isEnable then return end + nonil.enable() + if not client.info.capabilities.textDocument.completion.dynamicRegistration then + return + end + nonil.disable() isEnable = true log.debug('Enable completion.') proto.awaitRequest('client/registerCapability', { @@ -35,6 +42,11 @@ local function disable() if not isEnable then return end + nonil.enable() + if not client.info.capabilities.textDocument.completion.dynamicRegistration then + return + end + nonil.disable() isEnable = false log.debug('Disable completion.') proto.awaitRequest('client/unregisterCapability', { diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 59af1c7a..11b87405 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -19,6 +19,7 @@ local plugin = require 'plugin' local progress = require 'progress' local tm = require 'text-merger' local vm = require 'vm' +local nonil = require 'without-check-nil' local function updateConfig() local diagnostics = require 'provider.diagnostic' @@ -121,29 +122,38 @@ proto.on('initialized', function (params) updateConfig() local registrations = {} - -- 监视文件变化 - registrations[#registrations+1] = { - id = 'workspace/didChangeWatchedFiles', - method = 'workspace/didChangeWatchedFiles', - registerOptions = { - watchers = { - { - globPattern = '**/', - kind = 1 | 2 | 4, - } + nonil.enable() + if client.info.capabilities.workspace.didChangeWatchedFiles.dynamicRegistration then + -- 监视文件变化 + registrations[#registrations+1] = { + id = 'workspace/didChangeWatchedFiles', + method = 'workspace/didChangeWatchedFiles', + registerOptions = { + watchers = { + { + globPattern = '**/', + kind = 1 | 2 | 4, + } + }, }, - }, - } + } + end - -- 监视配置变化 - registrations[#registrations+1] = { - id = 'workspace/didChangeConfiguration', - method = 'workspace/didChangeConfiguration', - } + if client.info.capabilities.workspace.didChangeConfiguration.dynamicRegistration then + -- 监视配置变化 + registrations[#registrations+1] = { + id = 'workspace/didChangeConfiguration', + method = 'workspace/didChangeConfiguration', + } + end - proto.awaitRequest('client/registerCapability', { - registrations = registrations - }) + nonil.disable() + + if #registrations ~= 0 then + proto.awaitRequest('client/registerCapability', { + registrations = registrations + }) + end workspace.reload() return true end) diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua index bc8f81b9..268b8648 100644 --- a/script/provider/semantic-tokens.lua +++ b/script/provider/semantic-tokens.lua @@ -4,6 +4,7 @@ local client = require 'provider.client' local json = require "json" local config = require 'config' local lang = require 'language' +local nonil = require 'without-check-nil' local isEnable = false @@ -23,9 +24,11 @@ local function enable() if isEnable then return end - if not client.info.capabilities.textDocument.semanticTokens then + nonil.enable() + if not client.info.capabilities.textDocument.semanticTokens.dynamicRegistration then return end + nonil.disable() isEnable = true log.debug('Enable semantic tokens.') proto.awaitRequest('client/registerCapability', { @@ -80,6 +83,11 @@ local function disable() if not isEnable then return end + nonil.enable() + if not client.info.capabilities.textDocument.semanticTokens.dynamicRegistration then + return + end + nonil.disable() isEnable = false log.debug('Disable semantic tokens.') proto.awaitRequest('client/unregisterCapability', { |