Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- assuming you have a function "register" to wire up keymaps and crap depending on server capabilities
- -- for jdtls, it isn't enough to just do this on LspAttach like the neovim docs suggest
- -- you need to also handle "dynamic registration".. which jdtls seems to use heavily?
- -- Static registration of server's capabilities
- vim.api.nvim_create_autocmd('LspAttach', {
- callback = function(args)
- local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
- register(client, args.buf)
- end,
- })
- --- original handler that sets Neovim defaults
- local register_capability_handler = vim.lsp.handlers[ms.client_registerCapability]
- --- Dynamic registration of server's capabilities
- --- @param err lsp.ResponseError?
- --- @param params lsp.RegistrationParams
- --- @param ctx lsp.HandlerContext
- --- @return any
- vim.lsp.handlers[ms.client_registerCapability] = function(err, params, ctx)
- --- @type any
- local res = register_capability_handler(err, params, ctx)
- local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
- for bufnr in pairs(client.attached_buffers) do
- register(client, bufnr)
- end
- return res
- end
- --- VSCode command: show references in the quickfix list
- --- this one is really expected to exist by the language servers
- --- you need it e.g. to execute code lens commands to show references/implementations
- vim.lsp.commands['editor.action.showReferences'] = function(command, context)
- --- @type lsp.Location[]
- local locations = command.arguments[3]
- local client = assert(vim.lsp.get_client_by_id(context.client_id))
- if locations and #locations > 0 then
- local items = vim.lsp.util.locations_to_items(locations, client.offset_encoding)
- vim.fn.setqflist({}, ' ', { title = 'Code Lens: ' .. command.title, items = items, context = context })
- vim.api.nvim_command(':copen')
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment