|
| 1 | +if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE |
| 2 | + |
| 3 | +-- AstroLSP allows you to customize the features in AstroNvim's LSP configuration engine |
| 4 | +-- Configuration documentation can be found with `:h astrolsp` |
| 5 | +-- NOTE: We highly recommend setting up the Lua Language Server (`:LspInstall lua_ls`) |
| 6 | +-- as this provides autocomplete and documentation while editing |
| 7 | + |
| 8 | +---@type LazySpec |
| 9 | +return { |
| 10 | + "AstroNvim/astrolsp", |
| 11 | + ---@type AstroLSPOpts |
| 12 | + opts = { |
| 13 | + -- Configuration table of features provided by AstroLSP |
| 14 | + features = { |
| 15 | + codelens = true, -- enable/disable codelens refresh on start |
| 16 | + inlay_hints = false, -- enable/disable inlay hints on start |
| 17 | + semantic_tokens = true, -- enable/disable semantic token highlighting |
| 18 | + }, |
| 19 | + -- customize lsp formatting options |
| 20 | + formatting = { |
| 21 | + -- control auto formatting on save |
| 22 | + format_on_save = { |
| 23 | + enabled = true, -- enable or disable format on save globally |
| 24 | + allow_filetypes = { -- enable format on save for specified filetypes only |
| 25 | + -- "go", |
| 26 | + }, |
| 27 | + ignore_filetypes = { -- disable format on save for specified filetypes |
| 28 | + -- "python", |
| 29 | + }, |
| 30 | + }, |
| 31 | + disabled = { -- disable formatting capabilities for the listed language servers |
| 32 | + -- disable lua_ls formatting capability if you want to use StyLua to format your lua code |
| 33 | + -- "lua_ls", |
| 34 | + }, |
| 35 | + timeout_ms = 1000, -- default format timeout |
| 36 | + -- filter = function(client) -- fully override the default formatting function |
| 37 | + -- return true |
| 38 | + -- end |
| 39 | + }, |
| 40 | + -- enable servers that you already have installed without mason |
| 41 | + servers = { |
| 42 | + -- "pyright" |
| 43 | + }, |
| 44 | + -- customize language server configuration options passed to `lspconfig` |
| 45 | + ---@diagnostic disable: missing-fields |
| 46 | + config = { |
| 47 | + -- clangd = { capabilities = { offsetEncoding = "utf-8" } }, |
| 48 | + }, |
| 49 | + -- customize how language servers are attached |
| 50 | + handlers = { |
| 51 | + -- a function without a key is simply the default handler, functions take two parameters, the server name and the configured options table for that server |
| 52 | + -- function(server, opts) require("lspconfig")[server].setup(opts) end |
| 53 | + |
| 54 | + -- the key is the server that is being setup with `lspconfig` |
| 55 | + -- rust_analyzer = false, -- setting a handler to false will disable the set up of that language server |
| 56 | + -- pyright = function(_, opts) require("lspconfig").pyright.setup(opts) end -- or a custom handler function can be passed |
| 57 | + }, |
| 58 | + -- Configure buffer local auto commands to add when attaching a language server |
| 59 | + autocmds = { |
| 60 | + -- first key is the `augroup` to add the auto commands to (:h augroup) |
| 61 | + lsp_codelens_refresh = { |
| 62 | + -- Optional condition to create/delete auto command group |
| 63 | + -- can either be a string of a client capability or a function of `fun(client, bufnr): boolean` |
| 64 | + -- condition will be resolved for each client on each execution and if it ever fails for all clients, |
| 65 | + -- the auto commands will be deleted for that buffer |
| 66 | + cond = "textDocument/codeLens", |
| 67 | + -- cond = function(client, bufnr) return client.name == "lua_ls" end, |
| 68 | + -- list of auto commands to set |
| 69 | + { |
| 70 | + -- events to trigger |
| 71 | + event = { "InsertLeave", "BufEnter" }, |
| 72 | + -- the rest of the autocmd options (:h nvim_create_autocmd) |
| 73 | + desc = "Refresh codelens (buffer)", |
| 74 | + callback = function(args) |
| 75 | + if require("astrolsp").config.features.codelens then vim.lsp.codelens.refresh { bufnr = args.buf } end |
| 76 | + end, |
| 77 | + }, |
| 78 | + }, |
| 79 | + }, |
| 80 | + -- mappings to be set up on attaching of a language server |
| 81 | + mappings = { |
| 82 | + n = { |
| 83 | + -- a `cond` key can provided as the string of a server capability to be required to attach, or a function with `client` and `bufnr` parameters from the `on_attach` that returns a boolean |
| 84 | + gD = { |
| 85 | + function() vim.lsp.buf.declaration() end, |
| 86 | + desc = "Declaration of current symbol", |
| 87 | + cond = "textDocument/declaration", |
| 88 | + }, |
| 89 | + ["<Leader>uY"] = { |
| 90 | + function() require("astrolsp.toggles").buffer_semantic_tokens() end, |
| 91 | + desc = "Toggle LSP semantic highlight (buffer)", |
| 92 | + cond = function(client) |
| 93 | + return client.supports_method "textDocument/semanticTokens/full" and vim.lsp.semantic_tokens ~= nil |
| 94 | + end, |
| 95 | + }, |
| 96 | + }, |
| 97 | + }, |
| 98 | + -- A custom `on_attach` function to be run after the default `on_attach` function |
| 99 | + -- takes two parameters `client` and `bufnr` (`:h lspconfig-setup`) |
| 100 | + on_attach = function(client, bufnr) |
| 101 | + -- this would disable semanticTokensProvider for all clients |
| 102 | + -- client.server_capabilities.semanticTokensProvider = nil |
| 103 | + end, |
| 104 | + }, |
| 105 | +} |
0 commit comments