Neovim configs for 2023. Hopefully they last.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.0 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. -- Learn the keybindings, see :help lsp-zero-keybindings
  2. -- Learn to configure LSP servers, see :help lsp-zero-api-showcase
  3. local lsp = require('lsp-zero')
  4. lsp.preset('recommended')
  5. lsp.setup_nvim_cmp({
  6. experimental = {
  7. ghost_text = true,
  8. },
  9. })
  10. -- (Optional) Configure lua language server for neovim
  11. lsp.nvim_workspace()
  12. local servers = {
  13. 'tailwindcss',
  14. 'tsserver',
  15. 'texlab',
  16. 'pyright',
  17. 'ltex',
  18. 'jsonls'
  19. }
  20. local platform = require("mason-core.platform");
  21. if not (platform.is.linux_x64_musl or
  22. platform.is.linux_arm64_musl)
  23. then
  24. table.insert(servers, "sumneko_lua");
  25. end
  26. lsp.ensure_installed(servers)
  27. lsp.configure("tsserver", {
  28. on_init = function(client)
  29. client.server_capabilities.documentFormattingProvider = false
  30. client.server_capabilities.documentFormattingRangeProvider = false
  31. end
  32. })
  33. lsp.on_attach(function(client, bufnr)
  34. local opts = { buffer = bufnr, remap = false }
  35. vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
  36. vim.keymap.set("n", "<leader>rn", function() vim.lsp.buf.rename() end, opts)
  37. end)
  38. lsp.setup()
  39. vim.diagnostic.config({
  40. virtual_text = true,
  41. underline = true,
  42. float = true,
  43. })
  44. local null_ls = require('null-ls')
  45. local null_opts = lsp.build_options('null-ls', {})
  46. null_ls.setup({
  47. on_attach = function(client, bufnr)
  48. null_opts.on_attach(client, bufnr)
  49. local format_cmd = function(input)
  50. vim.lsp.buf.format({
  51. id = client.id,
  52. timeout_ms = 5000,
  53. async = input.bang,
  54. })
  55. end
  56. local bufcmd = vim.api.nvim_buf_create_user_command
  57. bufcmd(bufnr, 'NullFormat', format_cmd, {
  58. bang = true,
  59. range = true,
  60. desc = 'Format using null-ls'
  61. })
  62. end,
  63. sources = {
  64. null_ls.builtins.formatting.prettier,
  65. null_ls.builtins.formatting.autopep8,
  66. null_ls.builtins.formatting.gofmt,
  67. null_ls.builtins.diagnostics.eslint,
  68. null_ls.builtins.diagnostics.shellcheck,
  69. }
  70. })
  71. require('mason-null-ls').setup({
  72. ensure_installed = nil,
  73. automatic_installation = true,
  74. automatic_setup = false,
  75. })