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.

112 lines
2.5 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. local cmp = require('cmp')
  6. local cmp_select = { behavior = cmp.SelectBehavior.Select }
  7. local cmp_mappings = lsp.defaults.cmp_mappings({
  8. ['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
  9. ['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
  10. ['<C-s>'] = cmp.mapping.confirm({ select = true }),
  11. ["<C-Space>"] = cmp.mapping.complete(),
  12. })
  13. cmp_mappings['<Tab>'] = nil
  14. cmp_mappings['<S-Tab>'] = nil
  15. lsp.setup_nvim_cmp({
  16. mapping = cmp_mappings,
  17. experimental = {
  18. ghost_text = true,
  19. },
  20. })
  21. -- (Optional) Configure lua language server for neovim
  22. lsp.nvim_workspace()
  23. local servers = {
  24. 'tailwindcss',
  25. 'tsserver',
  26. 'texlab',
  27. 'pyright',
  28. 'ltex',
  29. 'jsonls'
  30. }
  31. lsp.ensure_installed(servers)
  32. lsp.configure("tsserver", {
  33. on_init = function(client)
  34. client.server_capabilities.documentFormattingProvider = false
  35. client.server_capabilities.documentFormattingRangeProvider = false
  36. end
  37. })
  38. lsp.on_attach(function(client, bufnr)
  39. local opts = { buffer = bufnr, remap = false }
  40. vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
  41. vim.keymap.set("n", "<leader>rn", function() vim.lsp.buf.rename() end, opts)
  42. end)
  43. lsp.setup()
  44. vim.diagnostic.config({
  45. virtual_text = true,
  46. underline = true,
  47. float = true,
  48. })
  49. local null_ls = require('null-ls')
  50. local null_opts = lsp.build_options('null-ls', {})
  51. null_ls.setup({
  52. on_attach = function(client, bufnr)
  53. null_opts.on_attach(client, bufnr)
  54. local format_cmd = function(input)
  55. vim.lsp.buf.format({
  56. id = client.id,
  57. timeout_ms = 5000,
  58. async = input.bang,
  59. })
  60. end
  61. local bufcmd = vim.api.nvim_buf_create_user_command
  62. bufcmd(bufnr, 'NullFormat', format_cmd, {
  63. bang = true,
  64. range = true,
  65. desc = 'Format using null-ls'
  66. })
  67. end,
  68. sources = {
  69. }
  70. })
  71. vim.api.nvim_create_autocmd("BufWritePre", {
  72. pattern = { "*.go", "*.py", "*.lua", "*.rs" },
  73. callback = function(args)
  74. vim.lsp.buf.format {
  75. timeout_ms = 5000
  76. }
  77. end
  78. })
  79. vim.keymap.set("n", "<leader>ft", function()
  80. vim.lsp.buf.format()
  81. end)
  82. require('mason').setup()
  83. require('mason-nvim-dap').setup({
  84. automatic_setup = true,
  85. })
  86. require('mason-null-ls').setup({
  87. ensure_installed = { "autopep8", "eslint", "gofmt", "rustfmt", "shellcheck" },
  88. automatic_installation = true,
  89. automatic_setup = true,
  90. })
  91. require("mason-null-ls").setup({
  92. handlers = {},
  93. })