commit 803bf520ede76d0d2eca5e48d4cf68c76c9de159
parent aec38929dc87ec537a3d7ffa981ded3df5a7fc1d
Author: Tomas Nemec <owl@gtms.dev>
Date: Thu, 8 Jun 2023 08:03:05 +0200
update
Diffstat:
2 files changed, 68 insertions(+), 61 deletions(-)
diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua
@@ -6,66 +6,82 @@ local lspconfig = require 'lspconfig'
local lsp = require 'tms.lsp';
local lsp_group = vim.api.nvim_create_augroup('user-lsp', {})
+
+local function keymap(client, buf)
+ local lb = vim.lsp.buf
+ local function opt(desc)
+ return { buffer = buf, desc = desc }
+ end
+
+ -- cap.semanticTokensProvider = nil
+
+ if client.supports_method('textDocument/hover') then
+ vim.keymap.set('n', 'K', lb.hover, opt 'LSP Hover')
+ end
+ if client.supports_method('textDocument/definition') then
+ vim.keymap.set('n', 'gd', lb.definition, opt 'LSP Definition')
+ vim.keymap.set('n', 'gD', '<cmd>vsplit | lua vim.lsp.buf.definition()<cr>', opt('LSP definition in vsplit'))
+ end
+ -- collision with previous tab `gT`
+ -- if cap.typeDefinitionProvider then
+ -- vim.keymap.set('n', 'gT', lb.type_definition, opt('LSP Type Definition'))
+ -- end
+ if client.supports_method('textDocument/implementation') then
+ vim.keymap.set('n', 'gm', lb.implementation, opt('LSP Implementation'))
+ end
+ if client.supports_method('textDocument/signatureHelp') then
+ vim.keymap.set('n', '<c-p>', lb.signature_help, opt('LSP Signature Help'))
+ vim.keymap.set('i', '<c-p>', lb.signature_help, opt('LSP Signature Help'))
+ end
+ if client.supports_method('textDocument/references') then
+ vim.keymap.set('n', 'gr', lb.references, opt('LSP References'))
+ end
+ if client.supports_method('textDocument/codeAction') then
+ vim.keymap.set({ 'n', 'v' }, 'ga', lb.code_action, opt('LSP Code Actions'))
+ end
+ if client.supports_method('textDocument/documentHighlight') then
+ vim.keymap.set('n', '<leader>k', lb.document_highlight, opt('LSP Highlight'))
+ vim.api.nvim_create_autocmd('CursorMoved',
+ { group = lsp_group, buffer = buf, callback = vim.lsp.buf.clear_references })
+ end
+ if client.supports_method('textDocument/rename') then
+ vim.keymap.set('n', 'cd', lb.rename, opt('LSP Rename (change definition'))
+ end
+ if client.supports_method('textDocument/prepareTypeHierarchy') then
+ vim.keymap.set('n', 'gh', function()
+ require('tms.lsp.request').type_hierarchy('subtypes')
+ end, opt('LSP Subtypes'))
+ vim.keymap.set('n', 'gl', function()
+ require('tms.lsp.request').type_hierarchy('supertypes')
+ end, opt('LSP Supertypes'))
+ end
+end
+
vim.api.nvim_create_autocmd('LspAttach', {
group = lsp_group,
callback = function(args)
- local buf = args.buf
- local lb = vim.lsp.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
-
- local opt = function(desc)
- return { buffer = buf, desc = desc }
- end
-
- -- cap.semanticTokensProvider = nil
-
- if client.supports_method('textDocument/hover') then
- vim.keymap.set('n', 'K', lb.hover, opt 'LSP Hover')
- end
- if client.supports_method('textDocument/definition') then
- vim.keymap.set('n', 'gd', lb.definition, opt 'LSP Definition')
- vim.keymap.set('n', 'gD', '<cmd>vsplit | lua vim.lsp.buf.definition()<cr>', opt('LSP definition in vsplit'))
- end
- -- collision with previous tab `gT`
- -- if cap.typeDefinitionProvider then
- -- vim.keymap.set('n', 'gT', lb.type_definition, opt('LSP Type Definition'))
- -- end
- if client.supports_method('textDocument/implementation') then
- vim.keymap.set('n', 'gm', lb.implementation, opt('LSP Implementation'))
- end
- if client.supports_method('textDocument/signatureHelp') then
- vim.keymap.set('n', '<c-p>', lb.signature_help, opt('LSP Signature Help'))
- vim.keymap.set('i', '<c-p>', lb.signature_help, opt('LSP Signature Help'))
- end
- if client.supports_method('textDocument/references') then
- vim.keymap.set('n', 'gr', lb.references, opt('LSP References'))
- end
- if client.supports_method('textDocument/codeAction') then
- vim.keymap.set({ 'n', 'v' }, 'ga', lb.code_action, opt('LSP Code Actions'))
- end
- if client.supports_method('textDocument/documentHighlight') then
- vim.keymap.set('n', '<leader>k', lb.document_highlight, opt('LSP Highlight'))
- vim.api.nvim_create_autocmd('CursorMoved',
- { group = lsp_group, buffer = buf, callback = vim.lsp.buf.clear_references })
- end
- if client.supports_method('textDocument/rename') then
- vim.keymap.set('n', 'cd', lb.rename, opt('LSP Rename (change definition'))
- end
- if client.supports_method('textDocument/prepareTypeHierarchy') then
- vim.keymap.set('n', 'gh', function()
- require('tms.lsp.request').type_hierarchy('subtypes')
- end, opt('LSP Subtypes'))
- vim.keymap.set('n', 'gl', function()
- require('tms.lsp.request').type_hierarchy('supertypes')
- end, opt('LSP Supertypes'))
- end
+ keymap(client, args.buf)
end,
})
local handlers = vim.lsp.handlers
-local with = vim.lsp.with
-handlers['textDocument/hover'] = with(handlers.hover, { border = 'single' })
-handlers['textDocument/signatureHelp'] = with(handlers.signature_help, { border = 'single' })
+handlers['textDocument/hover'] = vim.lsp.with(handlers.hover, { border = 'single' })
+handlers['textDocument/signatureHelp'] = vim.lsp.with(handlers.signature_help, { border = 'single' })
+local crc = handlers['client/registerCapability']
+handlers['client/registerCapability'] = function(_, result, ctx)
+ local r = crc(_, result, ctx)
+
+ local client = vim.lsp.get_client_by_id(ctx.client_id)
+ keymap(client, ctx.buf)
+
+ return r
+end
+-- local cuc = handlers['client/unregisterCapability']
+-- handlers['client/unregisterCapability'] = function(_, result, ctx)
+-- return cuc(_, result, ctx)
+-- -- TODO(tms) 08.06.23: Remove bindings
+-- end
-- local progress = require('tms.lsp.progress')
-- handlers['$/progress'] = progress.handler
diff --git a/lua/tms/lsp/servers.lua b/lua/tms/lsp/servers.lua
@@ -73,15 +73,6 @@ function M.dartls(opts)
opts = dart_tools_lsp.make_opts(opts)
opts.settings.dart.lineLength = 120
end
-
- opts.capabilities.textDocument.definition.dnamicRegistration = false
- opts.capabilities.textDocument.formatting.dynamicRegistration = false
- opts.capabilities.textDocument.rangeFormatting.dynamicRegistration = false
- opts.capabilities.textDocument.hover.dynamicRegistration = false
- opts.capabilities.textDocument.rename.dynamicRegistration = false
- opts.capabilities.textDocument.codeAction.dynamicRegistration = false
- opts.capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = false
-
return opts
end