diff options
-rw-r--r-- | script/provider/capability.lua | 91 | ||||
-rw-r--r-- | script/provider/provider.lua | 95 |
2 files changed, 123 insertions, 63 deletions
diff --git a/script/provider/capability.lua b/script/provider/capability.lua index e012f4b4..ba5690bf 100644 --- a/script/provider/capability.lua +++ b/script/provider/capability.lua @@ -7,17 +7,6 @@ local define = require 'proto.define' require 'provider.semantic-tokens' require 'provider.formatting' -local function toArray(map) - local array = {} - for k in pairs(map) do - array[#array+1] = k - end - table.sort(array, function (a, b) - return map[a] < map[b] - end) - return array -end - local m = {} local function testFileEvents(initer) @@ -58,8 +47,27 @@ local function testFileEvents(initer) } end -function m.getIniter() - local initer = { +m.fillings = {} + +local function mergeFillings(provider) + for _, filling in ipairs(m.fillings) do + for k, v in pairs(filling) do + if type(v) == 'table' then + if not provider[k] then + provider[k] = {} + end + for kk, vv in pairs(v) do + provider[k][kk] = vv + end + else + provider[k] = v + end + end + end +end + +function m.getProvider() + local provider = { offsetEncoding = client.getOffsetEncoding(), -- 文本同步方式 textDocumentSync = { @@ -68,53 +76,6 @@ function m.getIniter() -- 文本增量更新 change = 2, }, - - hoverProvider = true, - definitionProvider = true, - typeDefinitionProvider = true, - referencesProvider = true, - renameProvider = { - prepareProvider = true, - }, - documentSymbolProvider = true, - workspaceSymbolProvider = true, - documentHighlightProvider = true, - codeActionProvider = { - codeActionKinds = { - '', - 'quickfix', - 'refactor.rewrite', - 'refactor.extract', - }, - resolveProvider = false, - }, - signatureHelpProvider = { - triggerCharacters = { '(', ',' }, - }, - executeCommandProvider = { - commands = { - 'lua.removeSpace', - 'lua.solve', - 'lua.jsonToLua', - 'lua.setConfig', - 'lua.autoRequire', - }, - }, - foldingRangeProvider = true, - documentOnTypeFormattingProvider = { - firstTriggerCharacter = '\n', - moreTriggerCharacter = nil, -- string[] - }, - semanticTokensProvider = { - legend = { - tokenTypes = toArray(define.TokenTypes), - tokenModifiers = toArray(define.TokenModifiers), - }, - range = true, - full = false, - }, - documentFormattingProvider = true, - documentRangeFormattingProvider = true } --testFileEvents() @@ -122,14 +83,20 @@ function m.getIniter() nonil.enable() if not client.info.capabilities.textDocument.completion.dynamicRegistration or not client.info.capabilities.workspace.configuration then - initer.completionProvider = { + provider.completionProvider = { resolveProvider = true, triggerCharacters = completion.allWords(), } end nonil.disable() - return initer + mergeFillings(provider) + + return provider +end + +function m.filling(t) + m.fillings[#m.fillings+1] = t end return m diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 7d628306..0c1a95b4 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -61,6 +61,9 @@ m.attributes = {} function m.register(method) return function (attrs) m.attributes[method] = attrs + if attrs.capability then + cap.filling(attrs.capability) + end proto.on(method, attrs[1]) end end @@ -101,7 +104,7 @@ m.register 'initialize' { end return { - capabilities = cap.getIniter(), + capabilities = cap.getProvider(), serverInfo = { name = 'sumneko.lua', }, @@ -261,6 +264,9 @@ m.register 'textDocument/didChange' { } m.register 'textDocument/hover' { + capability = { + hoverProvider = true, + }, abortByFileUpdate = true, ---@async function (params) @@ -299,6 +305,9 @@ m.register 'textDocument/hover' { } m.register 'textDocument/definition' { + capability = { + definitionProvider = true, + }, abortByFileUpdate = true, ---@async function (params) @@ -338,6 +347,9 @@ m.register 'textDocument/definition' { } m.register 'textDocument/typeDefinition' { + capability = { + typeDefinitionProvider = true, + }, abortByFileUpdate = true, ---@async function (params) @@ -377,6 +389,9 @@ m.register 'textDocument/typeDefinition' { } m.register 'textDocument/references' { + capability = { + referencesProvider = true, + }, abortByFileUpdate = true, ---@async function (params) @@ -404,6 +419,9 @@ m.register 'textDocument/references' { } m.register 'textDocument/documentHighlight' { + capability = { + documentHighlightProvider = true, + }, abortByFileUpdate = true, function (params) local core = require 'core.highlight' @@ -428,6 +446,11 @@ m.register 'textDocument/documentHighlight' { } m.register 'textDocument/rename' { + capability = { + renameProvider = { + prepareProvider = true, + }, + }, abortByFileUpdate = true, ---@async function (params) @@ -631,6 +654,11 @@ m.register 'completionItem/resolve' { } m.register 'textDocument/signatureHelp' { + capability = { + signatureHelpProvider = { + triggerCharacters = { '(', ',' }, + }, + }, abortByFileUpdate = true, ---@async function (params) @@ -677,6 +705,9 @@ m.register 'textDocument/signatureHelp' { } m.register 'textDocument/documentSymbol' { + capability = { + documentSymbolProvider = true, + }, abortByFileUpdate = true, ---@async function (params) @@ -723,6 +754,17 @@ m.register 'textDocument/documentSymbol' { } m.register 'textDocument/codeAction' { + capability = { + codeActionProvider = { + codeActionKinds = { + '', + 'quickfix', + 'refactor.rewrite', + 'refactor.extract', + }, + resolveProvider = false, + }, + }, abortByFileUpdate = true, function (params) local core = require 'core.code-action' @@ -757,6 +799,17 @@ m.register 'textDocument/codeAction' { } m.register 'workspace/executeCommand' { + capability = { + executeCommandProvider = { + commands = { + 'lua.removeSpace', + 'lua.solve', + 'lua.jsonToLua', + 'lua.setConfig', + 'lua.autoRequire', + }, + }, + }, ---@async function (params) local command = params.command:gsub(':.+', '') @@ -780,6 +833,9 @@ m.register 'workspace/executeCommand' { } m.register 'workspace/symbol' { + capability = { + workspaceSymbolProvider = true, + }, abortByFileUpdate = true, ---@async function (params) @@ -826,7 +882,29 @@ m.register 'textDocument/semanticTokens/full' { end } +local function toArray(map) + local array = {} + for k in pairs(map) do + array[#array+1] = k + end + table.sort(array, function (a, b) + return map[a] < map[b] + end) + return array +end + + m.register 'textDocument/semanticTokens/range' { + capability = { + semanticTokensProvider = { + legend = { + tokenTypes = toArray(define.TokenTypes), + tokenModifiers = toArray(define.TokenModifiers), + }, + range = true, + full = false, + }, + }, ---@async function (params) log.debug('textDocument/semanticTokens/range') @@ -843,6 +921,9 @@ m.register 'textDocument/semanticTokens/range' { } m.register 'textDocument/foldingRange' { + capability = { + foldingRangeProvider = true, + }, abortByFileUpdate = true, ---@async function (params) @@ -915,6 +996,9 @@ m.register '$/status/click' { } m.register 'textDocument/formatting' { + capability = { + documentFormattingProvider = true, + }, ---@async function(params) local uri = files.getRealUri(params.textDocument.uri) @@ -949,6 +1033,9 @@ m.register 'textDocument/formatting' { } m.register 'textDocument/rangeFormatting' { + capability = { + documentRangeFormattingProvider = true, + }, ---@async function(params) local uri = files.getRealUri(params.textDocument.uri) @@ -983,6 +1070,12 @@ m.register 'textDocument/rangeFormatting' { } m.register 'textDocument/onTypeFormatting' { + capability = { + documentOnTypeFormattingProvider = { + firstTriggerCharacter = '\n', + moreTriggerCharacter = nil, -- string[] + }, + }, abortByFileUpdate = true, ---@async function (params) |