From b6016b3df6ba4083289a5a89d4532f6c2a5c0c2a Mon Sep 17 00:00:00 2001 From: Fey Naomi Schrewe Date: Wed, 11 Sep 2024 11:50:37 +0200 Subject: [PATCH] feat: support typescript lsp --- lazy-lock.json | 11 +++++++---- lua/lsp-setup.lua | 34 +++++++++++++++++++++++++++------- lua/plugins.lua | 42 +++++++++++++++++++++++++++++------------- 3 files changed, 63 insertions(+), 24 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index 95628ce..fba1000 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -9,7 +9,7 @@ "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp-under-comparator": { "branch": "master", "commit": "6857f10272c3cfe930cece2afa2406e1385bfef8" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, - "conform.nvim": { "branch": "master", "commit": "0ebe875d9c306f5fc829db38492ffff2a70d8e9d" }, + "conform.nvim": { "branch": "master", "commit": "936f2413e6c57185cd873623a29a0685bce4b423" }, "crates.nvim": { "branch": "main", "commit": "b3b9ac6ed9618955b24bf9adede7530ef608495b" }, "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, "direnv.vim": { "branch": "master", "commit": "ab2a7e08dd630060cd81d7946739ac7442a4f269" }, @@ -21,6 +21,8 @@ "lazydev.nvim": { "branch": "main", "commit": "491452cf1ca6f029e90ad0d0368848fac717c6d2" }, "lualine.nvim": { "branch": "master", "commit": "b431d228b7bbcdaea818bdc3e25b8cdbe861f056" }, "luvit-meta": { "branch": "main", "commit": "ce76f6f6cdc9201523a5875a4471dcfe0186eb60" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" }, + "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, "neo-tree.nvim": { "branch": "v3.x", "commit": "29f7c215332ba95e470811c380ddbce2cebe2af4" }, "neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" }, "neogit": { "branch": "master", "commit": "bc0c609e3568a171e0549b449aa1b2b4b5b20e8c" }, @@ -31,10 +33,10 @@ "nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" }, "nvim-coverage": { "branch": "main", "commit": "aa4b4400588e2259e87e372b1e4e90ae13cf5a39" }, "nvim-dap": { "branch": "master", "commit": "20a4859ebde1c9bc8e96f8cc11a20667e7fdd516" }, - "nvim-lspconfig": { "branch": "master", "commit": "bdbc65aadc708ce528efb22bca5f82a7cca6b54d" }, + "nvim-lspconfig": { "branch": "master", "commit": "8c45e7270302f5a0e5371147c46ac56715117872" }, "nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" }, "nvim-surround": { "branch": "main", "commit": "ec2dc7671067e0086cdf29c2f5df2dd909d5f71f" }, - "nvim-treesitter": { "branch": "master", "commit": "4770d9a1a77b0cc2b723c646c3dbe43a9133e5db" }, + "nvim-treesitter": { "branch": "master", "commit": "d22166e3d8d375b761c32b303176f3e955560b0c" }, "nvim-treesitter-endwise": { "branch": "master", "commit": "8b34305ffc28bd75a22f5a0a9928ee726a85c9a6" }, "nvim-ts-autotag": { "branch": "main", "commit": "e239a560f338be31337e7abc3ee42515daf23f5e" }, "nvim-web-devicons": { "branch": "master", "commit": "9793801f974bba70e4ac5d7eae6c4f5659993d8e" }, @@ -46,9 +48,10 @@ "sentiment.nvim": { "branch": "main", "commit": "54a6db15b630eccfa98c32a76baf90f21c6f1e40" }, "spaceport.nvim": { "branch": "main", "commit": "f57a6848903adcb6bf2dd9f56bb0b8c33a51d4be" }, "suda.vim": { "branch": "master", "commit": "b97fab52f9cdeabe2bbb5eb98d82356899f30829" }, - "telescope.nvim": { "branch": "master", "commit": "5972437de807c3bc101565175da66a1aa4f8707a" }, + "telescope.nvim": { "branch": "master", "commit": "fe999db6e0c39c8984519ead75660e0e2d3245d3" }, "trouble.nvim": { "branch": "main", "commit": "6efc446226679fda0547c0fd6a7892fd5f5b15d8" }, "twilight.nvim": { "branch": "main", "commit": "1584c0b0a979b71fd86b18d302ba84e9aba85b1b" }, + "typescript-tools.nvim": { "branch": "master", "commit": "f8c2e0b36b651c85f52ad5c5373ff8b07adc15a7" }, "which-key.nvim": { "branch": "main", "commit": "bfec3d6bc0a9b0b2cb11644642f78c2c3915eef0" }, "zen-mode.nvim": { "branch": "main", "commit": "29b292bdc58b76a6c8f294c961a8bf92c5a6ebd6" } } diff --git a/lua/lsp-setup.lua b/lua/lsp-setup.lua index a6f07a1..8e0c4a4 100644 --- a/lua/lsp-setup.lua +++ b/lua/lsp-setup.lua @@ -1,11 +1,31 @@ local lspconfig = require('lspconfig') -lspconfig.lua_ls.setup {} -lspconfig.ts_ls.setup {} -lspconfig.eslint.setup {} -lspconfig.angularls.setup {} -lspconfig.ccls.setup {} -lspconfig.nixd.setup{} +local capabilities = require("cmp_nvim_lsp").default_capabilities() + +lspconfig.lua_ls.setup { + root_dir = function() return vim.fs.root(0, '.git') end, + capabilities = capabilities +} +lspconfig.ts_ls.setup { + root_dir = function() return vim.fs.root(0, '.git') end, + capabilities = capabilities +} +lspconfig.eslint.setup { + root_dir = function() return vim.fs.root(0, '.git') end, + capabilities = capabilities +} +lspconfig.angularls.setup { + root_dir = function() return vim.fs.root(0, '.git') end, + capabilities = capabilities +} +lspconfig.ccls.setup { + root_dir = function() return vim.fs.root(0, '.git') end, + capabilities = capabilities +} +lspconfig.nixd.setup { + root_dir = function() return vim.fs.root(0, '.git') end, + capabilities = capabilities +} -- Global mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions @@ -29,7 +49,7 @@ vim.api.nvim_create_autocmd('LspAttach', { -- Buffer local mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions - local opts = function (desc) return { buffer = ev.buf, desc = desc } end + local opts = function(desc) return { buffer = ev.buf, desc = desc } end vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts('Go to declaration')) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts('Go to definition')) vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts('Show LSP info')) diff --git a/lua/plugins.lua b/lua/plugins.lua index 3745e68..b9954a4 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -52,7 +52,21 @@ return { } }, 'lukas-reineke/cmp-under-comparator', - { 'neovim/nvim-lspconfig', config = function() require 'lsp-setup' end, event = 'VeryLazy' }, + { + 'neovim/nvim-lspconfig', + config = function() require 'lsp-setup' end, + event = { "BufReadPre", "BufNewFile" }, + dependencies = { { + 'williamboman/mason.nvim', + config = true + }, { "williamboman/mason-lspconfig.nvim", config = true }, } + }, + { + "pmizio/typescript-tools.nvim", + dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, + opts = {}, + event = { "BufReadPre", "BufNewFile" } + }, { 'folke/neodev.nvim', opts = { @@ -64,17 +78,17 @@ return { enabled = not hasversion(0, 10), lazy = false }, - { - "folke/lazydev.nvim", - ft = "lua", -- only load on lua files - opts = { - library = { - { path = "luvit-meta/library", words = { "vim%.uv" } }, - }, - }, + { + "folke/lazydev.nvim", + ft = "lua", -- only load on lua files + opts = { + library = { + { path = "luvit-meta/library", words = { "vim%.uv" } }, + }, + }, enabled = hasversion(0, 10), - }, - { "Bilal2453/luvit-meta", lazy = true }, + }, + { "Bilal2453/luvit-meta", lazy = true }, 'simrat39/rust-tools.nvim', 'mfussenegger/nvim-dap', { @@ -100,12 +114,14 @@ return { end, event = 'VeryLazy' }, - 'lambdalisue/suda.vim', + { + 'lambdalisue/suda.vim', + cmd = { 'SudaRead', 'SudaWrite' } + }, { 'kylechui/nvim-surround', version = '*', opts = {}, - cmd = { 'SudaRead', 'SudaWrite' } }, { 'nvim-treesitter/nvim-treesitter',