1
0

lsp.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. vim.diagnostic.config({
  2. -- only show virtual text for WARN and higher
  3. virtual_text = { severity = { min = vim.diagnostic.severity.WARN } },
  4. })
  5. local capabilities = require('cmp_nvim_lsp').default_capabilities()
  6. local nvim_lsp = require('lspconfig')
  7. nvim_lsp.bashls.setup({
  8. capabilities = capabilities,
  9. on_attach = on_attach,
  10. });
  11. if vim.fn.executable("node_modules/.bin/eslint") == 1 then
  12. local options = {}
  13. -- some projects have local rules, this isn't exactly generic but is good
  14. -- enough
  15. if vim.fn.isdirectory("lint-rules") == 1 then
  16. options.rulePaths = { "./lint-rules" }
  17. end
  18. nvim_lsp.eslint.setup({
  19. settings = {
  20. options = options,
  21. },
  22. on_attach = function(client, bufnr)
  23. -- add formatting capability, the language server registers this
  24. -- dynamically but neovim does not support that yet
  25. -- https://github.com/microsoft/vscode-eslint/pull/1307
  26. client.server_capabilities.documentFormattingProvider = true
  27. client.server_capabilities.documentRangeFormattingProvider = true
  28. on_attach(client, bufnr)
  29. end,
  30. })
  31. end
  32. if vim.fn.executable("deno") == 1 then
  33. nvim_lsp.denols.setup({
  34. capabilities = capabilities,
  35. on_attach = on_attach,
  36. });
  37. else
  38. require('typescript').setup({
  39. server = {
  40. init_options = {
  41. completionDisableFilterText = true,
  42. },
  43. capabilities = capabilities,
  44. handlers = {
  45. ['$/typescriptVersion'] = function(err, result, ctx, config)
  46. vim.notify(string.format('Typescript %s', result.version))
  47. end
  48. },
  49. flags = {
  50. debounce_text_changes = 150,
  51. },
  52. on_attach = function(client, bufnr)
  53. -- mark tsserver as not having formatting available as we rely on
  54. -- eslint for that
  55. client.server_capabilities.documentFormattingProvider = false
  56. client.server_capabilities.documentRangeFormattingProvider = false
  57. on_attach(client, bufnr)
  58. -- override mappings for typescript
  59. local opts = { silent = true, buffer = bufnr }
  60. -- exclude import statements from reference search (may have false positives)
  61. vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references default_text=!import\\ <CR>', opts)
  62. end
  63. }
  64. })
  65. end
  66. if vim.fn.executable("gopls") == 1 then
  67. nvim_lsp.gopls.setup({
  68. capabilities = capabilities,
  69. on_attach = on_attach,
  70. });
  71. end
  72. if vim.fn.executable("solargraph") == 1 then
  73. nvim_lsp.solargraph.setup({
  74. capabilities = capabilities,
  75. on_attach = on_attach,
  76. init_options = {
  77. formatting = false,
  78. }
  79. })
  80. end
  81. if vim.fn.executable("nil") == 1 then
  82. nvim_lsp.nil_ls.setup({
  83. on_attach = on_attach,
  84. });
  85. end
  86. local group = vim.api.nvim_create_augroup('LspFormatting', { clear = false })
  87. -- custom LSP servers
  88. local configs = require('lspconfig.configs')
  89. if not configs.elvish then
  90. configs.elvish = {
  91. default_config = {
  92. cmd = {'elvish', '--lsp'},
  93. filetypes = {'elvish'},
  94. root_dir = nvim_lsp.util.root_pattern('*.elv'),
  95. settings = {},
  96. },
  97. }
  98. end
  99. nvim_lsp.elvish.setup({
  100. capabilities = capabilities,
  101. on_attach = on_attach,
  102. })
  103. -- show LSP progress bar
  104. require('fidget').setup()