|
@@ -79,19 +79,35 @@ vim.keymap.set('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
|
|
|
vim.keymap.set('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
|
|
|
vim.keymap.set('n', '<space>q', '<cmd>lua vim.diagnostic.setqflist({ severity = { min = vim.diagnostic.severity.WARN } })<CR>', opts)
|
|
|
|
|
|
-function on_attach(client, bufnr)
|
|
|
- local opts = { silent = true, buffer = bufnr }
|
|
|
-
|
|
|
- -- LSP-specific mappings
|
|
|
- vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
|
- vim.keymap.set('n', 'gd', '<cmd>Telescope lsp_definitions<CR>', opts)
|
|
|
- vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
|
- vim.keymap.set('n', 'gi', '<cmd>Telescope lsp_implementations<CR>', opts)
|
|
|
- vim.keymap.set({'n', 'i'}, '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
|
- vim.keymap.set('n', '<space>D', '<cmd>Telescope lsp_type_definitions<CR>', opts)
|
|
|
- vim.keymap.set('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
|
- vim.keymap.set('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
|
|
- vim.keymap.set('v', '<space>ca', '<cmd>lua vim.lsp.buf.range_code_action()<CR>', opts)
|
|
|
- vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
|
|
|
- vim.keymap.set('n', '<Leader>fs', '<cmd>Telescope lsp_document_symbols<CR>', opts)
|
|
|
-end
|
|
|
+-- LSP-specific
|
|
|
+vim.api.nvim_create_autocmd('LspAttach', {
|
|
|
+ callback = function(args)
|
|
|
+ local client = vim.lsp.get_client_by_id(args.data.client_id)
|
|
|
+
|
|
|
+ if client.name == 'dprint' or client.name == 'eslint' then
|
|
|
+ -- mappings should have been attached by typescript and re-attaching can
|
|
|
+ -- overwrite the typescript specific overrides
|
|
|
+ end
|
|
|
+
|
|
|
+ local opts = { silent = true, buffer = args.buf }
|
|
|
+
|
|
|
+ vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
|
+ vim.keymap.set('n', 'gd', '<cmd>Telescope lsp_definitions<CR>', opts)
|
|
|
+ vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
|
+ vim.keymap.set('n', 'gi', '<cmd>Telescope lsp_implementations<CR>', opts)
|
|
|
+ vim.keymap.set({'n', 'i'}, '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
|
+ vim.keymap.set('n', '<space>D', '<cmd>Telescope lsp_type_definitions<CR>', opts)
|
|
|
+ vim.keymap.set('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
|
+ vim.keymap.set('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
|
|
+ vim.keymap.set('v', '<space>ca', '<cmd>lua vim.lsp.buf.range_code_action()<CR>', opts)
|
|
|
+ vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
|
|
|
+ vim.keymap.set('n', '<Leader>fs', '<cmd>Telescope lsp_document_symbols<CR>', opts)
|
|
|
+
|
|
|
+ if client.name == 'tsserver' then
|
|
|
+ -- exclude import statements from reference search (may have false positives)
|
|
|
+ vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references default_text=!import\\ <CR>', opts)
|
|
|
+ vim.keymap.set('n', 'gD', '<cmd>Telescope lsp_definitions<CR>', opts)
|
|
|
+ vim.keymap.set('n', 'gd', '<cmd>TypescriptGoToSourceDefinition<CR>', opts)
|
|
|
+ end
|
|
|
+ end,
|
|
|
+})
|