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.

102 lines
2.2 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
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. }
  65. })
  66. vim.api.nvim_create_autocmd("BufWritePre", {
  67. pattern = { "*.go", "*.py", "*.lua", "*.rs" },
  68. callback = function(args)
  69. vim.lsp.buf.format {
  70. timeout_ms = 5000
  71. }
  72. end
  73. })
  74. vim.keymap.set("n", "<leader>ft", function()
  75. vim.lsp.buf.format()
  76. end)
  77. require('mason').setup()
  78. require('mason-null-ls').setup({
  79. ensure_installed = { "prettier", "autopep8", "eslint", "gofmt", "rustfmt", "shellcheck" },
  80. automatic_installation = true,
  81. automatic_setup = true,
  82. })
  83. require('mason-null-ls').setup_handlers()