Skip to content

Commit e518eed

Browse files
committed
解决冲突
2 parents bfcbdd3 + 6149891 commit e518eed

File tree

6 files changed

+137
-65
lines changed

6 files changed

+137
-65
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Just some comment
22
{
33
"Lua.misc.parameters": [
4+
"--preview",
45
"--develop=true",
56
"--dbgport=11413",
67
]

script/config/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ local Template = {
208208
['Lua.hint.arrayIndex'] = Type.Boolean >> 'Auto',
209209
['Lua.window.statusBar'] = Type.Boolean >> true,
210210
['Lua.window.progressBar'] = Type.Boolean >> true,
211-
['Lua.format.enable'] = Type.Boolean >> false,
211+
['Lua.format.enable'] = Type.Boolean >> true,
212212
['Lua.format.defaultConfig'] = Type.Hash(Type.String, Type.String)
213213
>> {},
214214
['Lua.IntelliSense.traceLocalSet'] = Type.Boolean >> false,

script/global.d.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ FOOTPRINT = false
3333
---trace rpc, use command line: --rpclog=true
3434
---@type boolean
3535
RPCLOG = false
36+
37+
--enable preview features.
38+
--
39+
--the current version is `formatting`
40+
---@type boolean
41+
PREVIEW = false

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: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ m.attributes = {}
6161
function m.register(method)
6262
return function (attrs)
6363
m.attributes[method] = attrs
64+
if attrs.preview and not PREVIEW then
65+
return
66+
end
67+
if attrs.capability then
68+
cap.filling(attrs.capability)
69+
end
6470
proto.on(method, attrs[1])
6571
end
6672
end
@@ -101,7 +107,7 @@ m.register 'initialize' {
101107
end
102108

103109
return {
104-
capabilities = cap.getIniter(),
110+
capabilities = cap.getProvider(),
105111
serverInfo = {
106112
name = 'sumneko.lua',
107113
},
@@ -261,6 +267,9 @@ m.register 'textDocument/didChange' {
261267
}
262268

263269
m.register 'textDocument/hover' {
270+
capability = {
271+
hoverProvider = true,
272+
},
264273
abortByFileUpdate = true,
265274
---@async
266275
function (params)
@@ -299,6 +308,9 @@ m.register 'textDocument/hover' {
299308
}
300309

301310
m.register 'textDocument/definition' {
311+
capability = {
312+
definitionProvider = true,
313+
},
302314
abortByFileUpdate = true,
303315
---@async
304316
function (params)
@@ -338,6 +350,9 @@ m.register 'textDocument/definition' {
338350
}
339351

340352
m.register 'textDocument/typeDefinition' {
353+
capability = {
354+
typeDefinitionProvider = true,
355+
},
341356
abortByFileUpdate = true,
342357
---@async
343358
function (params)
@@ -377,6 +392,9 @@ m.register 'textDocument/typeDefinition' {
377392
}
378393

379394
m.register 'textDocument/references' {
395+
capability = {
396+
referencesProvider = true,
397+
},
380398
abortByFileUpdate = true,
381399
---@async
382400
function (params)
@@ -404,6 +422,9 @@ m.register 'textDocument/references' {
404422
}
405423

406424
m.register 'textDocument/documentHighlight' {
425+
capability = {
426+
documentHighlightProvider = true,
427+
},
407428
abortByFileUpdate = true,
408429
function (params)
409430
local core = require 'core.highlight'
@@ -428,6 +449,11 @@ m.register 'textDocument/documentHighlight' {
428449
}
429450

430451
m.register 'textDocument/rename' {
452+
capability = {
453+
renameProvider = {
454+
prepareProvider = true,
455+
},
456+
},
431457
abortByFileUpdate = true,
432458
---@async
433459
function (params)
@@ -631,6 +657,11 @@ m.register 'completionItem/resolve' {
631657
}
632658

633659
m.register 'textDocument/signatureHelp' {
660+
capability = {
661+
signatureHelpProvider = {
662+
triggerCharacters = { '(', ',' },
663+
},
664+
},
634665
abortByFileUpdate = true,
635666
---@async
636667
function (params)
@@ -677,6 +708,9 @@ m.register 'textDocument/signatureHelp' {
677708
}
678709

679710
m.register 'textDocument/documentSymbol' {
711+
capability = {
712+
documentSymbolProvider = true,
713+
},
680714
abortByFileUpdate = true,
681715
---@async
682716
function (params)
@@ -723,6 +757,17 @@ m.register 'textDocument/documentSymbol' {
723757
}
724758

725759
m.register 'textDocument/codeAction' {
760+
capability = {
761+
codeActionProvider = {
762+
codeActionKinds = {
763+
'',
764+
'quickfix',
765+
'refactor.rewrite',
766+
'refactor.extract',
767+
},
768+
resolveProvider = false,
769+
},
770+
},
726771
abortByFileUpdate = true,
727772
function (params)
728773
local core = require 'core.code-action'
@@ -757,6 +802,17 @@ m.register 'textDocument/codeAction' {
757802
}
758803

759804
m.register 'workspace/executeCommand' {
805+
capability = {
806+
executeCommandProvider = {
807+
commands = {
808+
'lua.removeSpace',
809+
'lua.solve',
810+
'lua.jsonToLua',
811+
'lua.setConfig',
812+
'lua.autoRequire',
813+
},
814+
},
815+
},
760816
---@async
761817
function (params)
762818
local command = params.command:gsub(':.+', '')
@@ -780,6 +836,9 @@ m.register 'workspace/executeCommand' {
780836
}
781837

782838
m.register 'workspace/symbol' {
839+
capability = {
840+
workspaceSymbolProvider = true,
841+
},
783842
abortByFileUpdate = true,
784843
---@async
785844
function (params)
@@ -826,7 +885,29 @@ m.register 'textDocument/semanticTokens/full' {
826885
end
827886
}
828887

888+
local function toArray(map)
889+
local array = {}
890+
for k in pairs(map) do
891+
array[#array+1] = k
892+
end
893+
table.sort(array, function (a, b)
894+
return map[a] < map[b]
895+
end)
896+
return array
897+
end
898+
899+
829900
m.register 'textDocument/semanticTokens/range' {
901+
capability = {
902+
semanticTokensProvider = {
903+
legend = {
904+
tokenTypes = toArray(define.TokenTypes),
905+
tokenModifiers = toArray(define.TokenModifiers),
906+
},
907+
range = true,
908+
full = false,
909+
},
910+
},
830911
---@async
831912
function (params)
832913
log.debug('textDocument/semanticTokens/range')
@@ -843,6 +924,9 @@ m.register 'textDocument/semanticTokens/range' {
843924
}
844925

845926
m.register 'textDocument/foldingRange' {
927+
capability = {
928+
foldingRangeProvider = true,
929+
},
846930
abortByFileUpdate = true,
847931
---@async
848932
function (params)
@@ -915,6 +999,10 @@ m.register '$/status/click' {
915999
}
9161000

9171001
m.register 'textDocument/formatting' {
1002+
capability = {
1003+
documentFormattingProvider = true,
1004+
},
1005+
preview = true,
9181006
---@async
9191007
function(params)
9201008
local uri = files.getRealUri(params.textDocument.uri)
@@ -949,6 +1037,10 @@ m.register 'textDocument/formatting' {
9491037
}
9501038

9511039
m.register 'textDocument/rangeFormatting' {
1040+
capability = {
1041+
documentRangeFormattingProvider = true,
1042+
},
1043+
preview = true,
9521044
---@async
9531045
function(params)
9541046
local uri = files.getRealUri(params.textDocument.uri)
@@ -983,6 +1075,12 @@ m.register 'textDocument/rangeFormatting' {
9831075
}
9841076

9851077
m.register 'textDocument/onTypeFormatting' {
1078+
capability = {
1079+
documentOnTypeFormattingProvider = {
1080+
firstTriggerCharacter = '\n',
1081+
moreTriggerCharacter = nil, -- string[]
1082+
},
1083+
},
9861084
abortByFileUpdate = true,
9871085
---@async
9881086
function (params)

0 commit comments

Comments
 (0)