vim-files

Форк
0
/
lsp.lua 
249 строк · 10.1 Кб
1
require('nvim-config-loader').add_pack {
2
  lsp = {
3
    vim_plug_bundle = {
4
      -- 'nvim-treesitter/playground',
5
      -- " 'neovim/nvim-lsp'
6
      -- " 'ray-x/lsp_signature.nvim'
7
      -- " 'folke/lsp-colors.nvim'
8
      'neovim/nvim-lspconfig',
9
      'onsails/lspkind.nvim',
10
      'RishabhRD/popfix',
11
      'RishabhRD/nvim-lsputils',
12
      'zeioth/garbage-day.nvim', -- stop inactive lsp servers
13
    },
14
    setup = function()
15
      local lsp_config = require('lspconfig')
16
      local navic = require("nvim-navic")
17

18
      -- vim.lsp.set_log_level("debug")
19

20
      vim.diagnostic.config({
21
        virtual_text = true,
22
        signs = true,
23
        underline = false,
24
        update_in_insert = false,
25
        severity_sort = false,
26
        float = false
27
      })
28

29
      local on_attach = function(client, bufnr)
30
        if client.server_capabilities.documentSymbolProvider then
31
          navic.attach(client, bufnr)
32
        end
33

34
        local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
35
        local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
36
        local opts = { noremap=true, silent=true }
37

38
        buf_set_keymap('n', 'gA', '<Cmd>lua vim.lsp.buf.code_action()<CR>', opts)
39

40
        -- buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
41
        -- buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
42
        -- buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
43
        -- buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
44
        -- buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
45
        -- buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
46
        -- buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
47
        -- buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
48
        -- buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
49
        -- buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
50
        -- buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
51
      end
52

53
      -- vim.lsp.inlay_hint.enable(true)
54

55
      -- local on_attach = function(client, bufnr)
56

57
      --   local opts = { noremap=true, silent=true }
58

59
      --   -- buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
60
      --   -- buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
61
      --   -- buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
62
      --   -- buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
63
      --   -- buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
64
      --   -- buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
65
      --   -- buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
66
      --   -- buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
67
      --   -- buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
68
      --   -- buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
69
      --   -- buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
70

71
      --   -- require "lsp_signature".on_attach({
72
      --   --   bind = true,
73
      --   --   hint_prefix = "🔸",
74
      --   --   max_width = 70,
75
      --   --   extra_trigger_chars = {","},
76
      --   --   handler_opts = {
77
      --   --     border = "shadow"
78
      --   --   }
79
      --   -- })
80

81
      --   -- vim.lsp.inlay_hint.enable(bufnr)
82
      -- end
83

84
      -- go development
85
      lsp_config.gopls.setup {
86
        on_attach = on_attach
87
      }
88

89
      -- ruby development
90

91
      lsp_config.rubocop.setup {
92
        on_attach = on_attach,
93
        cmd = { "bundle", "exec", "rubocop", "--lsp" }
94
      }
95

96
      lsp_config.solargraph.setup {
97
        on_attach = on_attach,
98
        settings = {
99
          useBunlder = true,
100
          solargraph = {
101
            diagnostics = false,
102
          }
103
        }
104
      }
105

106
      -- vim development
107
      lsp_config.vimls.setup({
108
        on_attach = on_attach,
109
      })
110

111
      -- nvim development
112
      require("neodev").setup({
113
        on_attach = on_attach,
114
      })
115

116
      -- lua development
117
      lsp_config.lua_ls.setup({
118
        on_attach = on_attach,
119
        on_init = function(client)
120
          local path = client.workspace_folders[1].name
121
          if vim.loop.fs_stat(path..'/.luarc.json') or vim.loop.fs_stat(path..'/.luarc.jsonc') then
122
            return
123
          end
124

125
          client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
126
            runtime = {
127
              -- Tell the language server which version of Lua you're using
128
              -- (most likely LuaJIT in the case of Neovim)
129
              version = 'LuaJIT'
130
            },
131
            -- Make the server aware of Neovim runtime files
132
            workspace = {
133
              checkThirdParty = false,
134
              library = {
135
                vim.env.VIMRUNTIME
136
                -- Depending on the usage, you might want to add additional paths here.
137
                -- "${3rd}/luv/library"
138
                -- "${3rd}/busted/library",
139
              }
140
              -- or pull in all of 'runtimepath'. NOTE: this is a lot slower
141
              -- library = vim.api.nvim_get_runtime_file("", true)
142
            }
143
          })
144
        end,
145
        settings = {
146
          Lua = {}
147
        }
148
      })
149

150
      -- rust development
151
      lsp_config.rust_analyzer.setup {
152
          cmd = { "rust-analyzer" },
153
          filetypes = { "rust" },
154
          on_attach = on_attach,
155
          root_dir = lsp_config.util.root_pattern("Cargo.toml", "rust-project.json"),
156
          settings = {
157
            ["rust-analyzer"] = {
158
                assist = {
159
                    importMergeBehavior = "last",
160
                    importPrefix = "by_self",
161
                },
162
                cargo = {
163
                    loadOutDirsFromCheck = true
164
                },
165
                procMacro = {
166
                    enable = true
167
                },
168
            }
169
        }
170
      }
171

172
      -- ~ ray-x/go.nvim
173
      --
174
      -- Example:
175
      --   goimport='goimports', -- goimport command
176
      --   gofmt = 'gofmt', --gofmt cmd,
177
      --   max_line_len = 120, -- max line length in goline format
178
      --   tag_transform = false, -- tag_transfer  check gomodifytags for details
179
      --   test_template = '', -- default to testify if not set; g:go_nvim_tests_template  check gotests for details
180
      --   test_template_dir = '', -- default to nil if not set; g:go_nvim_tests_template_dir  check gotests for details
181
      --   comment_placeholder = '' ,  -- comment_placeholder your cool placeholder
182
      --   verbose = false,  -- output loginf in messages
183
      --   lsp_cfg = true, -- true: apply go.nvim non-default gopls setup
184
      --   lsp_gofumpt = false, -- true: set default gofmt in gopls format to gofumpt
185
      --   lsp_on_attach = true, -- if a on_attach function provided:  attach on_attach function to gopls
186
      --                         -- true: will use go.nvim on_attach if true
187
      --                         -- nil/false do nothing
188
      --   gopls_cmd = nil,
189
      --   lsp_diag_hdlr = false, -- hook lsp diag handler
190
      --   dap_debug = false, -- set to true to enable dap
191
      --   dap_debug_keymap = true, -- set keymaps for debugger
192
      --   dap_debug_gui = true, -- set to true to enable dap gui, highly recommand
193
      --   dap_debug_vt = true, -- set to true to enable dap virtual text
194
      require('go').setup({
195
        goimports = 'gopls', -- if set to 'gopls' will use golsp format
196
        gofmt = 'gopls', -- if set to gopls will use golsp format
197
        lsp_cfg = false,
198
        -- lsp_on_attach = true,
199
        -- on_attach = on_attach,
200
      })
201

202
      -- hover events
203
      require("hover").setup {
204
          init = function()
205
              -- Require providers
206
              require("hover.providers.lsp")
207
              -- require('hover.providers.gh')
208
              -- require('hover.providers.gh_user')
209
              -- require('hover.providers.jira')
210
              -- require('hover.providers.man')
211
              -- require('hover.providers.dictionary')
212
          end,
213
          preview_opts = {
214
              -- border = 'none'
215
              -- border = 'shadow'
216
              border = 'solid'
217
          },
218
          -- Whether the contents of a currently open hover window should be moved
219
          -- to a :h preview-window when pressing the hover keymap.
220
          preview_window = false,
221
          title = false,
222
          mouse_providers = {
223
              'LSP'
224
          },
225
          mouse_delay = 1000
226
      }
227

228
      -- Setup hover keymaps
229
      vim.keymap.set("n", "K", require("hover").hover, {desc = "hover.nvim"})
230
      vim.keymap.set("n", "gK", require("hover").hover_select, {desc = "hover.nvim (select)"})
231
      vim.keymap.set("n", "<C-p>", function() require("hover").hover_switch("previous") end, {desc = "hover.nvim (previous source)"})
232
      vim.keymap.set("n", "<C-n>", function() require("hover").hover_switch("next") end, {desc = "hover.nvim (next source)"})
233

234
      -- Mouse hover support
235
      vim.keymap.set('n', '<MouseMove>', require('hover').hover_mouse, { desc = "hover.nvim (mouse)" })
236
      vim.o.mousemoveevent = true
237

238
      -- lsp code actions
239
      vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler
240
      vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler
241
      vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler
242
      vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler
243
      vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler
244
      vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler
245
      vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler
246
      vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler
247
    end
248
  }
249
}
250

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.