Skip to content

Commit 2dd4ea4

Browse files
committed
cleanup
1 parent 1fc44f4 commit 2dd4ea4

File tree

2 files changed

+123
-63
lines changed

2 files changed

+123
-63
lines changed

script/provider/capability.lua

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ local define = require 'proto.define'
77
require 'provider.semantic-tokens'
88
require 'provider.formatting'
99

10-
local function toArray(map)
11-
local array = {}
12-
for k in pairs(map) do
13-
array[#array+1] = k
14-
end
15-
table.sort(array, function (a, b)
16-
return map[a] < map[b]
17-
end)
18-
return array
19-
end
20-
2110
local m = {}
2211

2312
local function testFileEvents(initer)
@@ -58,8 +47,27 @@ local function testFileEvents(initer)
5847
}
5948
end
6049

61-
function m.getIniter()
62-
local initer = {
50+
m.fillings = {}
51+
52+
local function mergeFillings(provider)
53+
for _, filling in ipairs(m.fillings) do
54+
for k, v in pairs(filling) do
55+
if type(v) == 'table' then
56+
if not provider[k] then
57+
provider[k] = {}
58+
end
59+
for kk, vv in pairs(v) do
60+
provider[k][kk] = vv
61+
end
62+
else
63+
provider[k] = v
64+
end
65+
end
66+
end
67+
end
68+
69+
function m.getProvider()
70+
local provider = {
6371
offsetEncoding = client.getOffsetEncoding(),
6472
-- 文本同步方式
6573
textDocumentSync = {
@@ -68,68 +76,27 @@ function m.getIniter()
6876
-- 文本增量更新
6977
change = 2,
7078
},
71-
72-
hoverProvider = true,
73-
definitionProvider = true,
74-
typeDefinitionProvider = true,
75-
referencesProvider = true,
76-
renameProvider = {
77-
prepareProvider = true,
78-
},
79-
documentSymbolProvider = true,
80-
workspaceSymbolProvider = true,
81-
documentHighlightProvider = true,
82-
codeActionProvider = {
83-
codeActionKinds = {
84-
'',
85-
'quickfix',
86-
'refactor.rewrite',
87-
'refactor.extract',
88-
},
89-
resolveProvider = false,
90-
},
91-
signatureHelpProvider = {
92-
triggerCharacters = { '(', ',' },
93-
},
94-
executeCommandProvider = {
95-
commands = {
96-
'lua.removeSpace',
97-
'lua.solve',
98-
'lua.jsonToLua',
99-
'lua.setConfig',
100-
'lua.autoRequire',
101-
},
102-
},
103-
foldingRangeProvider = true,
104-
documentOnTypeFormattingProvider = {
105-
firstTriggerCharacter = '\n',
106-
moreTriggerCharacter = nil, -- string[]
107-
},
108-
semanticTokensProvider = {
109-
legend = {
110-
tokenTypes = toArray(define.TokenTypes),
111-
tokenModifiers = toArray(define.TokenModifiers),
112-
},
113-
range = true,
114-
full = false,
115-
},
116-
documentFormattingProvider = true,
117-
documentRangeFormattingProvider = true
11879
}
11980

12081
--testFileEvents()
12182

12283
nonil.enable()
12384
if not client.info.capabilities.textDocument.completion.dynamicRegistration
12485
or not client.info.capabilities.workspace.configuration then
125-
initer.completionProvider = {
86+
provider.completionProvider = {
12687
resolveProvider = true,
12788
triggerCharacters = completion.allWords(),
12889
}
12990
end
13091
nonil.disable()
13192

132-
return initer
93+
mergeFillings(provider)
94+
95+
return provider
96+
end
97+
98+
function m.filling(t)
99+
m.fillings[#m.fillings+1] = t
133100
end
134101

135102
return m

script/provider/provider.lua

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ m.attributes = {}
6161
function m.register(method)
6262
return function (attrs)
6363
m.attributes[method] = attrs
64+
if attrs.capability then
65+
cap.filling(attrs.capability)
66+
end
6467
proto.on(method, attrs[1])
6568
end
6669
end
@@ -101,7 +104,7 @@ m.register 'initialize' {
101104
end
102105

103106
return {
104-
capabilities = cap.getIniter(),
107+
capabilities = cap.getProvider(),
105108
serverInfo = {
106109
name = 'sumneko.lua',
107110
},
@@ -261,6 +264,9 @@ m.register 'textDocument/didChange' {
261264
}
262265

263266
m.register 'textDocument/hover' {
267+
capability = {
268+
hoverProvider = true,
269+
},
264270
abortByFileUpdate = true,
265271
---@async
266272
function (params)
@@ -299,6 +305,9 @@ m.register 'textDocument/hover' {
299305
}
300306

301307
m.register 'textDocument/definition' {
308+
capability = {
309+
definitionProvider = true,
310+
},
302311
abortByFileUpdate = true,
303312
---@async
304313
function (params)
@@ -338,6 +347,9 @@ m.register 'textDocument/definition' {
338347
}
339348

340349
m.register 'textDocument/typeDefinition' {
350+
capability = {
351+
typeDefinitionProvider = true,
352+
},
341353
abortByFileUpdate = true,
342354
---@async
343355
function (params)
@@ -377,6 +389,9 @@ m.register 'textDocument/typeDefinition' {
377389
}
378390

379391
m.register 'textDocument/references' {
392+
capability = {
393+
referencesProvider = true,
394+
},
380395
abortByFileUpdate = true,
381396
---@async
382397
function (params)
@@ -404,6 +419,9 @@ m.register 'textDocument/references' {
404419
}
405420

406421
m.register 'textDocument/documentHighlight' {
422+
capability = {
423+
documentHighlightProvider = true,
424+
},
407425
abortByFileUpdate = true,
408426
function (params)
409427
local core = require 'core.highlight'
@@ -428,6 +446,11 @@ m.register 'textDocument/documentHighlight' {
428446
}
429447

430448
m.register 'textDocument/rename' {
449+
capability = {
450+
renameProvider = {
451+
prepareProvider = true,
452+
},
453+
},
431454
abortByFileUpdate = true,
432455
---@async
433456
function (params)
@@ -631,6 +654,11 @@ m.register 'completionItem/resolve' {
631654
}
632655

633656
m.register 'textDocument/signatureHelp' {
657+
capability = {
658+
signatureHelpProvider = {
659+
triggerCharacters = { '(', ',' },
660+
},
661+
},
634662
abortByFileUpdate = true,
635663
---@async
636664
function (params)
@@ -677,6 +705,9 @@ m.register 'textDocument/signatureHelp' {
677705
}
678706

679707
m.register 'textDocument/documentSymbol' {
708+
capability = {
709+
documentSymbolProvider = true,
710+
},
680711
abortByFileUpdate = true,
681712
---@async
682713
function (params)
@@ -723,6 +754,17 @@ m.register 'textDocument/documentSymbol' {
723754
}
724755

725756
m.register 'textDocument/codeAction' {
757+
capability = {
758+
codeActionProvider = {
759+
codeActionKinds = {
760+
'',
761+
'quickfix',
762+
'refactor.rewrite',
763+
'refactor.extract',
764+
},
765+
resolveProvider = false,
766+
},
767+
},
726768
abortByFileUpdate = true,
727769
function (params)
728770
local core = require 'core.code-action'
@@ -757,6 +799,17 @@ m.register 'textDocument/codeAction' {
757799
}
758800

759801
m.register 'workspace/executeCommand' {
802+
capability = {
803+
executeCommandProvider = {
804+
commands = {
805+
'lua.removeSpace',
806+
'lua.solve',
807+
'lua.jsonToLua',
808+
'lua.setConfig',
809+
'lua.autoRequire',
810+
},
811+
},
812+
},
760813
---@async
761814
function (params)
762815
local command = params.command:gsub(':.+', '')
@@ -780,6 +833,9 @@ m.register 'workspace/executeCommand' {
780833
}
781834

782835
m.register 'workspace/symbol' {
836+
capability = {
837+
workspaceSymbolProvider = true,
838+
},
783839
abortByFileUpdate = true,
784840
---@async
785841
function (params)
@@ -826,7 +882,29 @@ m.register 'textDocument/semanticTokens/full' {
826882
end
827883
}
828884

885+
local function toArray(map)
886+
local array = {}
887+
for k in pairs(map) do
888+
array[#array+1] = k
889+
end
890+
table.sort(array, function (a, b)
891+
return map[a] < map[b]
892+
end)
893+
return array
894+
end
895+
896+
829897
m.register 'textDocument/semanticTokens/range' {
898+
capability = {
899+
semanticTokensProvider = {
900+
legend = {
901+
tokenTypes = toArray(define.TokenTypes),
902+
tokenModifiers = toArray(define.TokenModifiers),
903+
},
904+
range = true,
905+
full = false,
906+
},
907+
},
830908
---@async
831909
function (params)
832910
log.debug('textDocument/semanticTokens/range')
@@ -843,6 +921,9 @@ m.register 'textDocument/semanticTokens/range' {
843921
}
844922

845923
m.register 'textDocument/foldingRange' {
924+
capability = {
925+
foldingRangeProvider = true,
926+
},
846927
abortByFileUpdate = true,
847928
---@async
848929
function (params)
@@ -915,6 +996,9 @@ m.register '$/status/click' {
915996
}
916997

917998
m.register 'textDocument/formatting' {
999+
capability = {
1000+
documentFormattingProvider = true,
1001+
},
9181002
---@async
9191003
function(params)
9201004
local uri = files.getRealUri(params.textDocument.uri)
@@ -949,6 +1033,9 @@ m.register 'textDocument/formatting' {
9491033
}
9501034

9511035
m.register 'textDocument/rangeFormatting' {
1036+
capability = {
1037+
documentRangeFormattingProvider = true,
1038+
},
9521039
---@async
9531040
function(params)
9541041
local uri = files.getRealUri(params.textDocument.uri)
@@ -983,6 +1070,12 @@ m.register 'textDocument/rangeFormatting' {
9831070
}
9841071

9851072
m.register 'textDocument/onTypeFormatting' {
1073+
capability = {
1074+
documentOnTypeFormattingProvider = {
1075+
firstTriggerCharacter = '\n',
1076+
moreTriggerCharacter = nil, -- string[]
1077+
},
1078+
},
9861079
abortByFileUpdate = true,
9871080
---@async
9881081
function (params)

0 commit comments

Comments
 (0)