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.

100 lines
2.1 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
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. lsp.ensure_installed(servers)
  21. lsp.configure("tsserver", {
  22. on_init = function(client)
  23. client.server_capabilities.documentFormattingProvider = false
  24. client.server_capabilities.documentFormattingRangeProvider = false
  25. end
  26. })
  27. lsp.on_attach(function(client, bufnr)
  28. local opts = { buffer = bufnr, remap = false }
  29. vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
  30. vim.keymap.set("n", "<leader>rn", function() vim.lsp.buf.rename() end, opts)
  31. end)
  32. lsp.setup()
  33. vim.diagnostic.config({
  34. virtual_text = true,
  35. underline = true,
  36. float = true,
  37. })
  38. local null_ls = require('null-ls')
  39. local null_opts = lsp.build_options('null-ls', {})
  40. null_ls.setup({
  41. on_attach = function(client, bufnr)
  42. null_opts.on_attach(client, bufnr)
  43. local format_cmd = function(input)
  44. vim.lsp.buf.format({
  45. id = client.id,
  46. timeout_ms = 5000,
  47. async = input.bang,
  48. })
  49. end
  50. local bufcmd = vim.api.nvim_buf_create_user_command
  51. bufcmd(bufnr, 'NullFormat', format_cmd, {
  52. bang = true,
  53. range = true,
  54. desc = 'Format using null-ls'
  55. })
  56. end,
  57. sources = {
  58. }
  59. })
  60. vim.api.nvim_create_autocmd("BufWritePre", {
  61. pattern = { "*.go", "*.py", "*.lua", "*.rs" },
  62. callback = function(args)
  63. vim.lsp.buf.format {
  64. timeout_ms = 5000
  65. }
  66. end
  67. })
  68. vim.keymap.set("n", "<leader>ft", function()
  69. vim.lsp.buf.format()
  70. end)
  71. require('mason').setup()
  72. require("mason-nvim-dap").setup({
  73. automatic_setup = true,
  74. })
  75. require 'mason-nvim-dap'.setup_handlers {}
  76. require('mason-null-ls').setup({
  77. ensure_installed = { "prettier", "autopep8", "eslint", "gofmt", "rustfmt", "shellcheck" },
  78. automatic_installation = true,
  79. automatic_setup = true,
  80. })
  81. require('mason-null-ls').setup_handlers()