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.

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