summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/plugins/lsp.lua
diff options
context:
space:
mode:
authorYigit Sever2023-08-18 23:42:39 +0300
committerYigit Sever2023-08-18 23:42:39 +0300
commit387e08c52d9752bc839c71119f140ba8435c3d70 (patch)
tree3bb20c0e58ccf1e65ced4cfdfb6459e226a24672 /.config/nvim/lua/plugins/lsp.lua
parent14c14cfcc9aeb4bada6d2429162ded2917f26a94 (diff)
downloaddotfiles-387e08c52d9752bc839c71119f140ba8435c3d70.tar.gz
dotfiles-387e08c52d9752bc839c71119f140ba8435c3d70.tar.bz2
dotfiles-387e08c52d9752bc839c71119f140ba8435c3d70.zip
nvim: switch to lazy.nvim
revert this as whole, if you miss the good old days
Diffstat (limited to '.config/nvim/lua/plugins/lsp.lua')
-rw-r--r--.config/nvim/lua/plugins/lsp.lua236
1 files changed, 236 insertions, 0 deletions
diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua
new file mode 100644
index 0000000..d03d9af
--- /dev/null
+++ b/.config/nvim/lua/plugins/lsp.lua
@@ -0,0 +1,236 @@
1return {
2 {
3 "neovim/nvim-lspconfig",
4 dependencies = {
5 "williamboman/mason.nvim",
6 "williamboman/mason-lspconfig.nvim",
7 "j-hui/fidget.nvim",
8 "folke/neodev.nvim",
9 "RRethy/vim-illuminate",
10 "hrsh7th/cmp-nvim-lsp",
11 },
12 config = function()
13 local map = require("helpers.keys").map
14
15 map('n', '<leader>e', vim.diagnostic.open_float, "lsp: open diagnostics float")
16 map('n', '[d', vim.diagnostic.goto_prev, "lsp: goto previous diagnostic")
17 map('n', ']d', vim.diagnostic.goto_next, "lsp: goto next diagnostic")
18
19 -- set up mason before anything else
20 require("mason").setup()
21 require("mason-lspconfig").setup({
22 ensure_installed = {
23 "lua_ls",
24 "pylsp",
25 },
26 automatic_installation = true,
27 })
28
29 -- quick access via keymap
30 require("helpers.keys").map("n", "<leader>M", "<cmd>Mason<cr>", "show mason")
31
32 -- neodev setup before lsp config
33 require("neodev").setup()
34
35 -- set up cool signs for diagnostics
36 local signs = { Error = " ", Warn = "", Hint = "", Info = "" }
37 for type, icon in pairs(signs) do
38 local hl = "DiagnosticSign" .. type
39 vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
40 end
41
42 -- Diagnostic config
43 local config = {
44 virtual_text = false,
45 signs = {
46 active = signs,
47 },
48 update_in_insert = true,
49 underline = true,
50 severity_sort = true,
51 float = {
52 focusable = true,
53 style = "minimal",
54 border = "rounded",
55 source = "always",
56 header = "",
57 prefix = "",
58 },
59 }
60 vim.diagnostic.config(config)
61
62 -- this function gets run when an lsp connects to a particular buffer.
63 local on_attach = function(client, bufnr)
64 map = require("helpers.keys").lsp_map
65
66 map("<leader>lr", vim.lsp.buf.rename, bufnr, "lsp: rename symbol")
67 map("<leader>la", vim.lsp.buf.code_action, bufnr, "lsp: code action")
68 map("<leader>ld", vim.lsp.buf.type_definition, bufnr, "lsp: type definition")
69 map("<leader>ls", require("telescope.builtin").lsp_document_symbols, bufnr, "lsp: document symbols")
70
71 map("gd", vim.lsp.buf.definition, bufnr, "lsp: goto definition")
72 map("gD", vim.lsp.buf.declaration, bufnr, "lsp: goto declaration")
73 map("gr", require("telescope.builtin").lsp_references, bufnr, "lsp: goto references")
74 map("gI", vim.lsp.buf.implementation, bufnr, "lsp: goto implementation")
75 map("K", vim.lsp.buf.hover, bufnr, "lsp: hover documentation")
76 map("<c-k>", vim.lsp.buf.signature_help, bufnr, "lsp: signature help")
77
78 -- Create a command `:Format` local to the LSP buffer
79 vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_)
80 vim.lsp.buf.format()
81 end, { desc = "lsp: format current buffer" })
82
83 map("<leader>fm", "<cmd>Format<cr>", bufnr, "lsp: format current buffer")
84
85 -- Attach and configure vim-illuminate
86 -- apparently this is deprecated
87 -- https://github.com/RRethy/vim-illuminate/issues/111
88 require("illuminate").on_attach(client)
89 end
90
91 -- nvim-cmp supports additional completion capabilities, so broadcast that to servers
92 local capabilities = vim.lsp.protocol.make_client_capabilities()
93 capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
94
95 -- lua
96 require("lspconfig")["lua_ls"].setup({
97 on_attach = on_attach,
98 capabilities = capabilities,
99 settings = {
100 Lua = {
101 completion = {
102 callSnippet = "Replace",
103 },
104 diagnostics = {
105 globals = { "vim" },
106 },
107 workspace = {
108 library = {
109 [vim.fn.expand("$VIMRUNTIME/lua")] = true,
110 [vim.fn.stdpath("config") .. "/lua"] = true,
111 },
112 },
113 },
114 },
115 })
116
117 -- python
118 require("lspconfig")["pylsp"].setup({
119 on_attach = on_attach,
120 capabilities = capabilities,
121 settings = {
122 pylsp = {
123 plugins = {
124 flake8 = {
125 enabled = true,
126 maxLineLength = 88, -- black's line length
127 },
128 -- disable plugins overlapping with flake8
129 pycodestyle = {
130 enabled = false,
131 },
132 mccabe = {
133 enabled = false,
134 },
135 pyflakes = {
136 enabled = false,
137 },
138 -- use black as the formatter
139 autopep8 = {
140 enabled = false,
141 },
142 },
143 },
144 },
145 })
146
147 -- efm
148 require("lspconfig")["efm"].setup({
149 on_attach = on_attach,
150 filetypes = { 'sh' },
151 capabilities = capabilities
152 })
153
154 -- ltex
155 require("lspconfig")["ltex"].setup({
156 capabilities = capabilities,
157 on_attach = function(client, bufnr)
158 on_attach(client, bufnr)
159 require("ltex_extra").setup {
160 load_langs = { "en-GB" },
161 init_check = true,
162 log_level = "none",
163 }
164 end,
165 settings = {
166 ltex = {
167 -- my settings here
168 }
169 }
170 })
171
172 -- rust-tools
173 local rust_opts = {
174 tools = {
175 runnables = {
176 use_telescope = true,
177 },
178 inlay_hints = {
179 auto = true,
180 show_parameter_hints = true,
181 parameter_hints_prefix = "↸ ",
182 other_hints_prefix = "❱ ",
183 },
184 },
185
186 -- all the opts to send to nvim-lspconfig
187 -- these override the defaults set by rust-tools.nvim
188 -- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
189 server = {
190 on_attach = on_attach,
191 settings = {
192 -- to enable rust-analyzer settings visit:
193 -- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
194 ["rust-analyzer"] = {
195 -- enable clippy on save
196 checkOnSave = {
197 command = "clippy",
198 },
199 },
200 },
201 },
202 }
203
204 require('rust-tools').setup(rust_opts)
205 end,
206 },
207 {
208 "barreiroleo/ltex-extra.nvim",
209 event = "LspAttach",
210 },
211 {
212 "j-hui/fidget.nvim",
213 tag = "legacy",
214 event = "LspAttach",
215 opts = {
216 text = {
217 spinner = "triangle",
218 commenced = "started", -- message shown when task starts
219 completed = "done", -- message shown when task completes
220 },
221 },
222 },
223 {
224 "simrat39/rust-tools.nvim",
225 event = "LspAttach",
226 },
227 -- {
228 -- "RRethy/vim-illuminate",
229 -- opts = {
230 -- filetypes_denylist = {
231 -- 'NvimTree',
232 -- 'fugitive',
233 -- },
234 -- },
235 -- },
236}