lsp.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. local blink = require('blink.cmp')
  2. local lspconfig = require('lspconfig')
  3. -- 1. Setup blink.cmp
  4. blink.setup({
  5. keymap = {
  6. preset = 'default',
  7. ['<CR>'] = { 'accept', 'fallback' },
  8. ['<Tab>'] = { 'select_next', 'fallback' },
  9. ['<S-Tab>'] = { 'select_prev', 'fallback' },
  10. },
  11. snippets = { preset = 'luasnip' },
  12. appearance = {
  13. use_nvim_cmp_as_default = true,
  14. nerd_font_variant = 'mono'
  15. },
  16. sources = {
  17. default = { 'lsp', 'path', 'buffer', 'snippets' },
  18. },
  19. fuzzy = {
  20. implementation = "prefer_rust",
  21. },
  22. signature = { enabled = true }
  23. })
  24. -- Load custom snippets from ~/.config/nvim/snips
  25. require("luasnip.loaders.from_vscode").lazy_load({ paths = { "~/.config/nvim/snips" } })
  26. require("luasnip.loaders.from_snipmate").lazy_load({ paths = { "~/.config/nvim/snips" } })
  27. -- 2. Define on_attach
  28. local on_attach = function(client, bufnr)
  29. -- Keymaps are handled globally in bindings.vim
  30. end
  31. -- 3. Configure Servers using Neovim 0.11 API where possible
  32. local capabilities = blink.get_lsp_capabilities()
  33. -- Basic servers
  34. local servers = { 'pyright', 'ruff', 'bashls', 'html', 'cssls', 'jdtls', 'rust_analyzer', 'clangd' }
  35. for _, server in ipairs(servers) do
  36. vim.lsp.config(server, {
  37. capabilities = capabilities,
  38. on_attach = on_attach,
  39. })
  40. vim.lsp.enable(server)
  41. end
  42. -- Custom Veridian setup (Verilog)
  43. vim.lsp.config('veridian', {
  44. cmd = { 'veridian' },
  45. filetypes = { 'systemverilog', 'verilog' },
  46. capabilities = capabilities,
  47. on_attach = on_attach,
  48. })
  49. vim.lsp.enable('veridian')
  50. -- 4. Formatting (Replaces coc's formatOnSave)
  51. local conform = require("conform")
  52. conform.setup({
  53. formatters_by_ft = {
  54. python = { "black" },
  55. java = { "google-java-format" },
  56. sh = { "shfmt" },
  57. rust = { "rustfmt" },
  58. c = { "clang-format" },
  59. cpp = { "clang-format" },
  60. cmake = { "cmake_format" },
  61. },
  62. format_on_save = {
  63. timeout_ms = 2000,
  64. lsp_fallback = true,
  65. },
  66. })
  67. -- 5. Linting (Replaces coc's pylint and shellcheck)
  68. local lint = require("lint")
  69. lint.linters_by_ft = {
  70. python = { "pylint" },
  71. sh = { "shellcheck" },
  72. rust = { "clippy", "cspell" },
  73. }
  74. vim.api.nvim_create_autocmd({ "BufWritePost" }, {
  75. callback = function()
  76. lint.try_lint()
  77. end,
  78. })
  79. -- 6. Diagnostics config
  80. vim.diagnostic.config({
  81. virtual_text = true,
  82. signs = true,
  83. update_in_insert = false,
  84. underline = true,
  85. severity_sort = true,
  86. float = { border = 'rounded' },
  87. })
  88. -- 7. Diagnostic & Spell Highlighting
  89. vim.api.nvim_set_hl(0, 'DiagnosticUnderlineError', { undercurl = true, sp = '#ff0000' })
  90. vim.api.nvim_set_hl(0, 'DiagnosticUnderlineWarn', { undercurl = true, sp = '#ff8800' })
  91. vim.api.nvim_set_hl(0, 'SpellBad', { undercurl = true, sp = '#ffff00' })
  92. vim.api.nvim_set_hl(0, 'SpellCap', { undercurl = true, sp = '#ffff00' })
  93. vim.api.nvim_set_hl(0, 'SpellLocal', { undercurl = true, sp = '#ffff00' })
  94. vim.api.nvim_set_hl(0, 'SpellRare', { undercurl = true, sp = '#ffff00' })