|
1 | 1 | return {
|
2 |
| - "neovim/nvim-lspconfig", |
3 |
| - event = { "BufReadPre", "BufNewFile" }, |
4 |
| - dependencies = { |
5 |
| - "hrsh7th/cmp-nvim-lsp", |
6 |
| - { "antosha417/nvim-lsp-file-operations", config = true }, |
7 |
| - { "folke/neodev.nvim", opts = {} }, |
8 |
| - }, |
9 |
| - config = function() |
10 |
| - -- import lspconfig plugin |
11 |
| - local lspconfig = require("lspconfig") |
12 |
| - |
13 |
| - -- import mason_lspconfig plugin |
14 |
| - local mason_lspconfig = require("mason-lspconfig") |
15 |
| - |
16 |
| - -- import cmp-nvim-lsp plugin |
17 |
| - local cmp_nvim_lsp = require("cmp_nvim_lsp") |
18 |
| - |
19 |
| - local keymap = vim.keymap -- for conciseness |
20 |
| - |
21 |
| - vim.api.nvim_create_autocmd("LspAttach", { |
22 |
| - group = vim.api.nvim_create_augroup("UserLspConfig", {}), |
23 |
| - callback = function(ev) |
24 |
| - -- Buffer local mappings. |
25 |
| - -- See `:help vim.lsp.*` for documentation on any of the below functions |
26 |
| - local opts = { buffer = ev.buf, silent = true } |
27 |
| - |
28 |
| - -- set keybinds |
29 |
| - opts.desc = "Show LSP references" |
30 |
| - keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts) -- show definition, references |
31 |
| - |
32 |
| - opts.desc = "Go to declaration" |
33 |
| - keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration |
34 |
| - |
35 |
| - opts.desc = "Show LSP definitions" |
36 |
| - keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts) -- show lsp definitions |
37 |
| - |
38 |
| - opts.desc = "Show LSP implementations" |
39 |
| - keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts) -- show lsp implementations |
40 |
| - |
41 |
| - opts.desc = "Show LSP type definitions" |
42 |
| - keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts) -- show lsp type definitions |
43 |
| - |
44 |
| - opts.desc = "See available code actions" |
45 |
| - keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection |
46 |
| - |
47 |
| - opts.desc = "Smart rename" |
48 |
| - keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- smart rename |
49 |
| - |
50 |
| - opts.desc = "Show buffer diagnostics" |
51 |
| - keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file |
52 |
| - |
53 |
| - opts.desc = "Show line diagnostics" |
54 |
| - keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts) -- show diagnostics for line |
55 |
| - |
56 |
| - opts.desc = "Go to previous diagnostic" |
57 |
| - keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer |
58 |
| - |
59 |
| - opts.desc = "Go to next diagnostic" |
60 |
| - keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer |
61 |
| - |
62 |
| - opts.desc = "Show documentation for what is under cursor" |
63 |
| - keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor |
64 |
| - |
65 |
| - opts.desc = "Restart LSP" |
66 |
| - keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary |
67 |
| - end, |
68 |
| - }) |
69 |
| - |
70 |
| - -- used to enable autocompletion (assign to every lsp server config) |
71 |
| - local capabilities = cmp_nvim_lsp.default_capabilities() |
72 |
| - |
73 |
| - -- Change the Diagnostic symbols in the sign column (gutter) |
74 |
| - -- (not in youtube nvim video) |
75 |
| - local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } |
76 |
| - for type, icon in pairs(signs) do |
77 |
| - local hl = "DiagnosticSign" .. type |
78 |
| - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) |
79 |
| - end |
80 |
| - |
81 |
| - mason_lspconfig.setup_handlers({ |
82 |
| - -- default handler for installed servers |
83 |
| - function(server_name) |
84 |
| - lspconfig[server_name].setup({ |
85 |
| - capabilities = capabilities, |
86 |
| - }) |
87 |
| - end, |
88 |
| - ["graphql"] = function() |
89 |
| - -- configure graphql language server |
90 |
| - lspconfig["graphql"].setup({ |
91 |
| - capabilities = capabilities, |
92 |
| - filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" }, |
93 |
| - }) |
94 |
| - end, |
95 |
| - ["emmet_ls"] = function() |
96 |
| - -- configure emmet language server |
97 |
| - lspconfig["emmet_ls"].setup({ |
98 |
| - capabilities = capabilities, |
99 |
| - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, |
100 |
| - }) |
101 |
| - end, |
102 |
| - ["lua_ls"] = function() |
103 |
| - -- configure lua server (with special settings) |
104 |
| - lspconfig["lua_ls"].setup({ |
105 |
| - capabilities = capabilities, |
106 |
| - settings = { |
107 |
| - Lua = { |
108 |
| - -- make the language server recognize "vim" global |
109 |
| - diagnostics = { |
110 |
| - globals = { "vim" }, |
111 |
| - }, |
112 |
| - completion = { |
113 |
| - callSnippet = "Replace", |
114 |
| - }, |
115 |
| - }, |
116 |
| - }, |
117 |
| - }) |
118 |
| - end, |
119 |
| - ["gopls"] = function() |
120 |
| - -- configure gopls for Go development |
121 |
| - lspconfig["gopls"].setup({ |
122 |
| - capabilities = capabilities, |
123 |
| - cmd = { "gopls", "serve" }, |
124 |
| - filetypes = { "go", "gomod", "gowork", "gotmpl" }, |
125 |
| - root_dir = lspconfig.util.root_pattern("go.mod", ".git"), |
126 |
| - settings = { |
127 |
| - gopls = { |
128 |
| - experimentalPostfixCompletions = true, |
129 |
| - analyses = { |
130 |
| - unusedparams = true, |
131 |
| - shadow = true, |
132 |
| - }, |
133 |
| - staticcheck = true, |
134 |
| - gofumpt = true, |
135 |
| - }, |
136 |
| - }, |
137 |
| - }) |
138 |
| - end, |
139 |
| - }) |
140 |
| - end, |
| 2 | + "neovim/nvim-lspconfig", |
| 3 | + event = { "BufReadPre", "BufNewFile" }, |
| 4 | + dependencies = { |
| 5 | + "hrsh7th/cmp-nvim-lsp", |
| 6 | + { "antosha417/nvim-lsp-file-operations", config = true }, |
| 7 | + { "folke/neodev.nvim", opts = {} }, |
| 8 | + }, |
| 9 | + config = function() |
| 10 | + -- import lspconfig plugin |
| 11 | + local lspconfig = require("lspconfig") |
| 12 | + |
| 13 | + -- import mason_lspconfig plugin |
| 14 | + local mason_lspconfig = require("mason-lspconfig") |
| 15 | + |
| 16 | + -- import cmp-nvim-lsp plugin |
| 17 | + local cmp_nvim_lsp = require("cmp_nvim_lsp") |
| 18 | + |
| 19 | + local keymap = vim.keymap -- for conciseness |
| 20 | + |
| 21 | + vim.api.nvim_create_autocmd("LspAttach", { |
| 22 | + group = vim.api.nvim_create_augroup("UserLspConfig", {}), |
| 23 | + callback = function(ev) |
| 24 | + -- Buffer local mappings. |
| 25 | + -- See `:help vim.lsp.*` for documentation on any of the below functions |
| 26 | + local opts = { buffer = ev.buf, silent = true } |
| 27 | + |
| 28 | + -- set keybinds |
| 29 | + opts.desc = "Show LSP references" |
| 30 | + keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts) -- show definition, references |
| 31 | + |
| 32 | + opts.desc = "Go to declaration" |
| 33 | + keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration |
| 34 | + |
| 35 | + opts.desc = "Show LSP definitions" |
| 36 | + keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts) -- show lsp definitions |
| 37 | + |
| 38 | + opts.desc = "Show LSP implementations" |
| 39 | + keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts) -- show lsp implementations |
| 40 | + |
| 41 | + opts.desc = "Show LSP type definitions" |
| 42 | + keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts) -- show lsp type definitions |
| 43 | + |
| 44 | + opts.desc = "See available code actions" |
| 45 | + keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection |
| 46 | + |
| 47 | + opts.desc = "Smart rename" |
| 48 | + keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- smart rename |
| 49 | + |
| 50 | + opts.desc = "Show buffer diagnostics" |
| 51 | + keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file |
| 52 | + |
| 53 | + opts.desc = "Show line diagnostics" |
| 54 | + keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts) -- show diagnostics for line |
| 55 | + |
| 56 | + opts.desc = "Go to previous diagnostic" |
| 57 | + keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer |
| 58 | + |
| 59 | + opts.desc = "Go to next diagnostic" |
| 60 | + keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer |
| 61 | + |
| 62 | + opts.desc = "Show documentation for what is under cursor" |
| 63 | + keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor |
| 64 | + |
| 65 | + opts.desc = "Restart LSP" |
| 66 | + keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary |
| 67 | + end, |
| 68 | + }) |
| 69 | + |
| 70 | + -- used to enable autocompletion (assign to every lsp server config) |
| 71 | + local capabilities = cmp_nvim_lsp.default_capabilities() |
| 72 | + |
| 73 | + -- Change the Diagnostic symbols in the sign column (gutter) |
| 74 | + -- (not in youtube nvim video) |
| 75 | + local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } |
| 76 | + for type, icon in pairs(signs) do |
| 77 | + local hl = "DiagnosticSign" .. type |
| 78 | + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) |
| 79 | + end |
| 80 | + |
| 81 | + mason_lspconfig.setup_handlers({ |
| 82 | + -- default handler for installed servers |
| 83 | + function(server_name) |
| 84 | + lspconfig[server_name].setup({ |
| 85 | + capabilities = capabilities, |
| 86 | + }) |
| 87 | + end, |
| 88 | + ["graphql"] = function() |
| 89 | + -- configure graphql language server |
| 90 | + lspconfig["graphql"].setup({ |
| 91 | + capabilities = capabilities, |
| 92 | + filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" }, |
| 93 | + }) |
| 94 | + end, |
| 95 | + ["emmet_ls"] = function() |
| 96 | + -- configure emmet language server |
| 97 | + lspconfig["emmet_ls"].setup({ |
| 98 | + capabilities = capabilities, |
| 99 | + filetypes = { |
| 100 | + "html", |
| 101 | + "typescriptreact", |
| 102 | + "javascriptreact", |
| 103 | + "css", |
| 104 | + "sass", |
| 105 | + "scss", |
| 106 | + "less", |
| 107 | + "svelte", |
| 108 | + }, |
| 109 | + }) |
| 110 | + end, |
| 111 | + ["lua_ls"] = function() |
| 112 | + -- configure lua server (with special settings) |
| 113 | + lspconfig["lua_ls"].setup({ |
| 114 | + capabilities = capabilities, |
| 115 | + settings = { |
| 116 | + Lua = { |
| 117 | + -- make the language server recognize "vim" global |
| 118 | + diagnostics = { |
| 119 | + globals = { "vim" }, |
| 120 | + }, |
| 121 | + completion = { |
| 122 | + callSnippet = "Replace", |
| 123 | + }, |
| 124 | + }, |
| 125 | + }, |
| 126 | + }) |
| 127 | + end, |
| 128 | + ["gopls"] = function() |
| 129 | + -- configure gopls for Go development |
| 130 | + lspconfig["gopls"].setup({ |
| 131 | + capabilities = capabilities, |
| 132 | + cmd = { "gopls", "serve" }, |
| 133 | + filetypes = { "go", "gomod", "gowork", "gotmpl" }, |
| 134 | + root_dir = lspconfig.util.root_pattern("go.mod", ".git"), |
| 135 | + settings = { |
| 136 | + gopls = { |
| 137 | + experimentalPostfixCompletions = true, |
| 138 | + analyses = { |
| 139 | + unusedparams = true, |
| 140 | + shadow = true, |
| 141 | + }, |
| 142 | + staticcheck = true, |
| 143 | + gofumpt = true, |
| 144 | + }, |
| 145 | + }, |
| 146 | + }) |
| 147 | + end, |
| 148 | + }) |
| 149 | + end, |
141 | 150 | }
|
142 |
| - |
|
0 commit comments