Skip to content

Commit

Permalink
fix #482
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Apr 2, 2021
1 parent 55e7d59 commit e5947d5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 22 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.21.0
* `CHG` `LuaDoc`: supports `---@param self TYPE`
* `CHG` completion: does not show suggests after `\n`, `{` and `,`, unless your setting `editor.acceptSuggestionOnEnter` is `off`
* `FIX` [#482](https://github.com/sumneko/lua-language-server/issues/482)

## 1.20.1
`2021-3-27`
Expand Down
14 changes: 13 additions & 1 deletion script/provider/completion.lua
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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', {
Expand All @@ -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', {
Expand Down
50 changes: 30 additions & 20 deletions script/provider/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion script/provider/semantic-tokens.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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', {
Expand Down Expand Up @@ -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', {
Expand Down

0 comments on commit e5947d5

Please sign in to comment.