From 6332f7b77073c43eb7b71ee3cb27af1cb148e9df Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Fri, 21 Mar 2025 18:06:08 +0100 Subject: [PATCH] [TypeScript] Enable all LSP functions --- nvim/lua/plugins/lsp/typescript-tools.lua | 105 ++++++++++++++++------ 1 file changed, 77 insertions(+), 28 deletions(-) diff --git a/nvim/lua/plugins/lsp/typescript-tools.lua b/nvim/lua/plugins/lsp/typescript-tools.lua index 03f4945..b4ed9e9 100755 --- a/nvim/lua/plugins/lsp/typescript-tools.lua +++ b/nvim/lua/plugins/lsp/typescript-tools.lua @@ -1,30 +1,79 @@ return { - 'pmizio/typescript-tools.nvim', - dependencies = { 'nvim-lua/plenary.nvim', 'neovim/nvim-lspconfig' }, - opts = {}, - ft = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'vue' }, - config = function() - require('typescript-tools').setup { - on_attach = function(client, bufnr) - client.server_capabilities.documentFormattingProvider = false - client.server_capabilities.documentRangeFormattingProvider = false - end, - filetypes = { - 'javascript', - 'javascriptreact', - 'typescript', - 'typescriptreact', - 'vue', - }, - settings = { - tsserver_plugins = { - '@vue/typescript-plugin', - }, - jsx_close_tag = { - enable = true, - filetypes = { 'javascriptreact', 'typescriptreact' }, - }, - }, - } - end, + "pmizio/typescript-tools.nvim", + dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, + opts = {}, + ft = { "javascript", "javascriptreact", "typescript", "typescriptreact", "vue" }, + config = function() + require("typescript-tools").setup({ + on_attach = function(client, bufnr) + local opts = { silent = true } + local keymap = vim.keymap + opts.buffer = bufnr + + -- set keybinds + opts.desc = "Show LSP references" + keymap.set("n", "gR", "Telescope lsp_references", opts) + + opts.desc = "Go to declaration" + keymap.set("n", "gD", ":lua vim.lsp.buf.declaration", opts) + + opts.desc = "Show LSP definitions" + keymap.set("n", "gd", "Telescope lsp_definitions", opts) + + opts.desc = "Show LSP implementations" + keymap.set("n", "gi", "Telescope lsp_implementations", opts) + + opts.desc = "Show LSP type definitions" + keymap.set("n", "gt", "Telescope lsp_type_definitions", opts) + + opts.desc = "See available code actions" + keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) + + opts.desc = "Format current file" + keymap.set("n", "gf", vim.lsp.buf.format, opts) + + opts.desc = "Smart rename" + keymap.set("n", "n", vim.lsp.buf.rename, opts) + + opts.desc = "Show buffer diagnostics" + keymap.set("n", "ga", "Telescope diagnostics bufnr=0", opts) + + opts.desc = "Show line diagnostics" + keymap.set("n", "gA", ":lua vim.diagnostic.open_float()", opts) + + opts.desc = "Go to previous diagnostic" + keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) + + opts.desc = "Go to next diagnostic" + keymap.set("n", "]d", vim.diagnostic.goto_next, opts) + + opts.desc = "Show documentation for what is under cursor" + keymap.set("n", "k", vim.lsp.buf.hover, opts) + + opts.desc = "Restart LSP" + keymap.set("n", "rs", ":LspRestart", opts) + + vim.opt.signcolumn = "yes" -- reserve space for diagnostics + + client.server_capabilities.documentFormattingProvider = false + client.server_capabilities.documentRangeFormattingProvider = false + end, + filetypes = { + "javascript", + "javascriptreact", + "typescript", + "typescriptreact", + "vue", + }, + settings = { + tsserver_plugins = { + "@vue/typescript-plugin", + }, + jsx_close_tag = { + enable = true, + filetypes = { "javascriptreact", "typescriptreact" }, + }, + }, + }) + end, }