summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/plugins/lsp.lua
blob: e8ff8639c4efa15001778721300f55de07ae4e1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
return {
    {
        "neovim/nvim-lspconfig",
        event = { "BufReadPost", "BufNewFile" },
        cmd = { "LspInfo", "LspInstall", "LspUninstall" },
        dependencies = {
            "j-hui/fidget.nvim",
            "RRethy/vim-illuminate",
            "hrsh7th/cmp-nvim-lsp",
        },
        config = function()
            local map = require("helpers.keys").map

            map('n', '<leader>e', vim.diagnostic.open_float, "lsp: open diagnostics float")
            map('n', '[d', vim.diagnostic.goto_prev, "lsp: goto previous diagnostic")
            map('n', ']d', vim.diagnostic.goto_next, "lsp: goto next diagnostic")

            -- set up cool signs for diagnostics
            local signs = { Error = " ", Warn = "", Hint = "", Info = "" }
            for type, icon in pairs(signs) do
                local hl = "DiagnosticSign" .. type
                vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
            end

            -- Diagnostic config
            local config = {
                virtual_text = false,
                signs = {
                    active = signs,
                },
                update_in_insert = true,
                underline = true,
                severity_sort = true,
                float = {
                    focusable = true,
                    style = "minimal",
                    border = "rounded",
                    source = "always",
                    header = "",
                    prefix = "",
                },
            }
            vim.diagnostic.config(config)

            -- this function gets run when an lsp connects to a particular buffer.
            local on_attach = function(_, bufnr)
                map = require("helpers.keys").lsp_map

                map("<leader>lr", vim.lsp.buf.rename, bufnr, "lsp: rename symbol")
                map("<leader>la", vim.lsp.buf.code_action, bufnr, "lsp: code action")
                map("<leader>ld", vim.lsp.buf.type_definition, bufnr, "lsp: type definition")
                map("<leader>ls", require("telescope.builtin").lsp_document_symbols, bufnr, "lsp: document symbols")

                map("gd", vim.lsp.buf.definition, bufnr, "lsp: goto definition")
                map("gD", vim.lsp.buf.declaration, bufnr, "lsp: goto declaration")
                map("gr", require("telescope.builtin").lsp_references, bufnr, "lsp: goto references")
                map("gI", vim.lsp.buf.implementation, bufnr, "lsp: goto implementation")
                map("K", vim.lsp.buf.hover, bufnr, "lsp: hover documentation")
                map("<c-k>", vim.lsp.buf.signature_help, bufnr, "lsp: signature help")

                -- Create a command `:Format` local to the LSP buffer
                vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_)
                    vim.lsp.buf.format()
                end, { desc = "lsp: format current buffer" })

                map("<leader>fm", "<cmd>Format<cr>", bufnr, "lsp: format current buffer")
            end

            -- nvim-cmp supports additional completion capabilities, so broadcast that to servers
            local capabilities = vim.lsp.protocol.make_client_capabilities()
            capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)

            -- misc.
            local lspconfig = require('lspconfig')
            local servers = { 'ts_ls', 'jsonls', 'eslint', 'cssls', 'html', 'vala_ls', 'gopls' }
            for _, lsp in pairs(servers) do
                lspconfig[lsp].setup {
                    on_attach = on_attach,
                    capabilites = capabilities,
                }
            end

            -- typst/tinymist
            require("lspconfig")["tinymist"].setup({
                on_attach = on_attach,
                capabilities = capabilities,
                single_file_support = true,
                root_dir = function()
                    return vim.fn.getcwd()
                end,
                settings = {
                    formatterMode = "typstyle",
                }
            })

            -- lua
            require("lspconfig")["lua_ls"].setup({
                on_attach = on_attach,
                capabilities = capabilities,
                settings = {
                    Lua = {
                        completion = {
                            callSnippet = "Replace",
                        },
                        diagnostics = {
                            globals = { "vim" },
                        },
                        workspace = {
                            library = {
                                [vim.fn.expand("$VIMRUNTIME/lua")] = true,
                                [vim.fn.stdpath("config") .. "/lua"] = true,
                            },
                        },
                    },
                },
            })

            -- python
            require("lspconfig")["pylsp"].setup({
                on_attach = on_attach,
                capabilities = capabilities,
                settings = {
                    pylsp = {
                        plugins = {
                            -- we had to disable this here for ruff + black to work
                            pycodestyle = {
                                enabled = false,
                            },
                            ruff = {
                                enabled = true,
                                extendSelect = { "I" },
                            },
                            black = {
                                enabled = true,
                            },
                        },
                    },
                },
            })

            -- efm
            require("lspconfig")["efm"].setup({
                on_attach = on_attach,
                settings = {
                    initializationOptions = {
                        documentFormatting = true,
                        documentRangeFormatting = true,
                        hover = true,
                        documentSymbol = true,
                        codeAction = true,
                        completion = true
                    }
                },
                capabilities = capabilities,
                filetypes = { 'sh', 'tex' },
            })

            require("lspconfig")["harper_ls"].setup {
                on_attach = on_attach,
                capabilities = capabilities,
                settings = {
                    ["harper-ls"] = {
                        linters = {
                            spell_check = true,
                            spelled_numbers = false,
                            an_a = true,
                            sentence_capitalization = true,
                            unclosed_quotes = true,
                            wrong_quotes = false,
                            long_sentences = true,
                            repeated_words = true,
                            spaces = true,
                            matcher = true,
                            correct_number_suffix = true,
                            number_suffix_capitalization = true,
                            multiple_sequential_pronouns = true,
                            linking_verbs = false,
                            avoid_curses = true,
                        }
                    }
                },
                filetypes = {
                    "markdown", "rust", "typescript", "typescriptreact", "javascript", "python", "c", "cpp", "ruby", "swift", "csharp", "toml", "lua", "gitcommit", "java", "html", "vimwiki", "tex"
                },
                root_dir = function(fname)
                    return vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1])
                end,
            }

            vim.g.rustaceanvim = {
                -- Plugin configuration
                tools = {
                },
                -- LSP configuration
                server = {
                    on_attach = on_attach,
                    vim.lsp.inlay_hint.enable(true),
                    default_settings = {
                        -- rust-analyzer language server configuration
                        ['rust-analyzer'] = {
                        },
                    },
                },
                -- DAP configuration
                dap = {
                },
            }
        end,
    },
    {
        "j-hui/fidget.nvim",
        event = "VeryLazy",
        opts = {
            progress = {
                suppress_on_insert = true,

                display = {
                    render_limit = 4,
                    progress_icon = {
                        pattern = "triangle",

                    },
                },
            },
        },
    },
    {
        'mrcjkb/rustaceanvim',
        version = '^5', -- Recommended
        lazy = false,   -- This plugin is already lazy
    },
    {
        "folke/lazydev.nvim",
        ft = "lua",
    },
    {
        'fatih/vim-go'
    },
    {
        "danymat/neogen",
        config = true,
        opts = {
            snippet_engine = "luasnip",
            languages = {
                python = {
                    template = {
                        annotation_convention = "reST",
                    }
                }
            }
        }
    },
    {
        'marcelofern/vale.nvim',
        config = function()
            require("vale").setup({
                bin = "/usr/bin/vale",
                vale_config_path = "$HOME/.config/vale/.vale.ini",
            })
        end,
    }
}