summaryrefslogtreecommitdiff
path: root/neovim/.config/nvim/lua/plugins/nvim_lspconfig.lua
blob: 65420dbfae40273d0b148954b79a2da040b62887 (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
return {
  {
    'neovim/nvim-lspconfig',
    lazy = false,
    priority = 800,
    config = function()
      local nvim_lsp = require('lspconfig')
      local capabilities = require('cmp_nvim_lsp').default_capabilities()
      -- Use a loop to conveniently call 'setup' on multiple servers and
      -- map buffer local keybindings when the language server attaches
      local servers = { "bashls", "clangd", "cssls", "dockerls", "gopls", "html", "htmx", "jsonls", "marksman",
        "rust_analyzer", "yamlls" }
      for _, lsp in ipairs(servers) do
        nvim_lsp[lsp].setup {
          capabilities = capabilities,
          flags = {
            debounce_text_changes = 150,
          }
        }
      end

      require 'lspconfig'.lua_ls.setup {
        on_init = function(client)
          local path = client.workspace_folders[1].name
          if vim.loop.fs_stat(path .. '/.luarc.json') or vim.loop.fs_stat(path .. '/.luarc.jsonc') then
            return
          end

          client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
            runtime = {
              -- Tell the language server which version of Lua you're using
              -- (most likely LuaJIT in the case of Neovim)
              version = 'LuaJIT'
            },
            -- Make the server aware of Neovim runtime files
            workspace = {
              checkThirdParty = false,
              library = {
                vim.env.VIMRUNTIME
                -- Depending on the usage, you might want to add additional paths here.
                -- "${3rd}/luv/library"
                -- "${3rd}/busted/library",
              }
              -- or pull in all of 'runtimepath'. NOTE: this is a lot slower
              -- library = vim.api.nvim_get_runtime_file("", true)
            }
          })
        end,
        settings = {
          Lua = {
            format = {
              enable = true,
              defaultConfig = {
                indent_style = "space",
                indent_size = "2",
              }
            },
          },

        },
        capabilities = capabilities,
      }

      require 'lspconfig'.tsserver.setup {
        filetypes = { 'typescript', 'typescriptreact', 'typescript.tsx' },
        capabilities = capabilities,
        flags = {
          debounce_text_changes = 150,
        },
      }

      require 'lspconfig'.pylsp.setup {
        settings = {
          pylsp = {
            plugins = {
              black = {
                enabled = false,
              },
              ruff = {
                enabled = true,
                formatEnabled = true,
                extendSelect = { 'I' },
                format = { 'I' },
              }
            }
          }
        },
        capabilities = capabilities,
        flags = {
          debounce_text_changes = 150,
        },
      }

      -- Use LspAttach autocommand to only map the following keys
      -- after the language server attaches to the current buffer
      vim.api.nvim_create_autocmd('LspAttach', {
        group = vim.api.nvim_create_augroup('UserLspConfig', {}),
        callback = function(ev)
          -- Enable completion triggered by <c-x><c-o>
          vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'

          local opts = { buffer = ev.buf }
          vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', { noremap = true })
          vim.keymap.set('v', '<leader>f', vim.lsp.buf.format, { noremap = true, silent = true })
          vim.keymap.set('n', '<leader>f', function()
            vim.lsp.buf.format { async = true }
          end, opts)
        end,
      })
    end,
  },
}