Skip to content

Commit e5947d5

Browse files
committed
fix #482
1 parent 55e7d59 commit e5947d5

File tree

4 files changed

+53
-22
lines changed

4 files changed

+53
-22
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.21.0
44
* `CHG` `LuaDoc`: supports `---@param self TYPE`
55
* `CHG` completion: does not show suggests after `\n`, `{` and `,`, unless your setting `editor.acceptSuggestionOnEnter` is `off`
6+
* `FIX` [#482](https://github.com./sumneko/lua-language-server/issues/482)
67

78
## 1.20.1
89
`2021-3-27`

script/provider/completion.lua

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
local proto = require 'proto'
1+
local proto = require 'proto'
2+
local nonil = require 'without-check-nil'
3+
local client = require 'provider.client'
24

35
local isEnable = false
46

@@ -15,6 +17,11 @@ local function enable()
1517
if isEnable then
1618
return
1719
end
20+
nonil.enable()
21+
if not client.info.capabilities.textDocument.completion.dynamicRegistration then
22+
return
23+
end
24+
nonil.disable()
1825
isEnable = true
1926
log.debug('Enable completion.')
2027
proto.awaitRequest('client/registerCapability', {
@@ -35,6 +42,11 @@ local function disable()
3542
if not isEnable then
3643
return
3744
end
45+
nonil.enable()
46+
if not client.info.capabilities.textDocument.completion.dynamicRegistration then
47+
return
48+
end
49+
nonil.disable()
3850
isEnable = false
3951
log.debug('Disable completion.')
4052
proto.awaitRequest('client/unregisterCapability', {

script/provider/provider.lua

+30-20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ local plugin = require 'plugin'
1919
local progress = require 'progress'
2020
local tm = require 'text-merger'
2121
local vm = require 'vm'
22+
local nonil = require 'without-check-nil'
2223

2324
local function updateConfig()
2425
local diagnostics = require 'provider.diagnostic'
@@ -121,29 +122,38 @@ proto.on('initialized', function (params)
121122
updateConfig()
122123
local registrations = {}
123124

124-
-- 监视文件变化
125-
registrations[#registrations+1] = {
126-
id = 'workspace/didChangeWatchedFiles',
127-
method = 'workspace/didChangeWatchedFiles',
128-
registerOptions = {
129-
watchers = {
130-
{
131-
globPattern = '**/',
132-
kind = 1 | 2 | 4,
133-
}
125+
nonil.enable()
126+
if client.info.capabilities.workspace.didChangeWatchedFiles.dynamicRegistration then
127+
-- 监视文件变化
128+
registrations[#registrations+1] = {
129+
id = 'workspace/didChangeWatchedFiles',
130+
method = 'workspace/didChangeWatchedFiles',
131+
registerOptions = {
132+
watchers = {
133+
{
134+
globPattern = '**/',
135+
kind = 1 | 2 | 4,
136+
}
137+
},
134138
},
135-
},
136-
}
139+
}
140+
end
137141

138-
-- 监视配置变化
139-
registrations[#registrations+1] = {
140-
id = 'workspace/didChangeConfiguration',
141-
method = 'workspace/didChangeConfiguration',
142-
}
142+
if client.info.capabilities.workspace.didChangeConfiguration.dynamicRegistration then
143+
-- 监视配置变化
144+
registrations[#registrations+1] = {
145+
id = 'workspace/didChangeConfiguration',
146+
method = 'workspace/didChangeConfiguration',
147+
}
148+
end
143149

144-
proto.awaitRequest('client/registerCapability', {
145-
registrations = registrations
146-
})
150+
nonil.disable()
151+
152+
if #registrations ~= 0 then
153+
proto.awaitRequest('client/registerCapability', {
154+
registrations = registrations
155+
})
156+
end
147157
workspace.reload()
148158
return true
149159
end)

script/provider/semantic-tokens.lua

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local client = require 'provider.client'
44
local json = require "json"
55
local config = require 'config'
66
local lang = require 'language'
7+
local nonil = require 'without-check-nil'
78

89
local isEnable = false
910

@@ -23,9 +24,11 @@ local function enable()
2324
if isEnable then
2425
return
2526
end
26-
if not client.info.capabilities.textDocument.semanticTokens then
27+
nonil.enable()
28+
if not client.info.capabilities.textDocument.semanticTokens.dynamicRegistration then
2729
return
2830
end
31+
nonil.disable()
2932
isEnable = true
3033
log.debug('Enable semantic tokens.')
3134
proto.awaitRequest('client/registerCapability', {
@@ -80,6 +83,11 @@ local function disable()
8083
if not isEnable then
8184
return
8285
end
86+
nonil.enable()
87+
if not client.info.capabilities.textDocument.semanticTokens.dynamicRegistration then
88+
return
89+
end
90+
nonil.disable()
8391
isEnable = false
8492
log.debug('Disable semantic tokens.')
8593
proto.awaitRequest('client/unregisterCapability', {

0 commit comments

Comments
 (0)