lsp.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 keymaps.lua (formerly bindings.vim)
  30. -- Enable CodeLens if supported
  31. if client.supports_method("textDocument/codeLens") then
  32. vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "InsertLeave" }, {
  33. buffer = bufnr,
  34. callback = function()
  35. vim.lsp.codelens.refresh({ bufnr = bufnr })
  36. end,
  37. })
  38. end
  39. -- Format on Type (Commented out - prefer Format on Save in conform.nvim)
  40. -- if client.supports_method("textDocument/onTypeFormatting") then
  41. -- vim.api.nvim_create_autocmd("InsertLeave", {
  42. -- buffer = bufnr,
  43. -- callback = function()
  44. -- vim.lsp.buf.format({ bufnr = bufnr, async = true })
  45. -- end,
  46. -- })
  47. -- end
  48. end
  49. -- 3. Configure Servers using Neovim 0.11 API where possible
  50. local capabilities = blink.get_lsp_capabilities()
  51. -- Basic servers
  52. local servers = { 'pyright', 'ruff', 'bashls', 'html', 'cssls', 'jdtls', 'rust_analyzer', 'clangd' }
  53. for _, server in ipairs(servers) do
  54. vim.lsp.config(server, {
  55. capabilities = capabilities,
  56. on_attach = on_attach,
  57. })
  58. vim.lsp.enable(server)
  59. end
  60. -- Custom Veridian setup (Verilog)
  61. vim.lsp.config('veridian', {
  62. cmd = { 'veridian' },
  63. filetypes = { 'systemverilog', 'verilog' },
  64. capabilities = capabilities,
  65. on_attach = on_attach,
  66. })
  67. vim.lsp.enable('veridian')
  68. -- 4. Formatting (Replaces coc's formatOnSave)
  69. local conform = require("conform")
  70. conform.setup({
  71. formatters_by_ft = {
  72. python = { "black" },
  73. java = { "google-java-format" },
  74. sh = { "shfmt" },
  75. rust = { "rustfmt" },
  76. c = { "clang-format" },
  77. cpp = { "clang-format" },
  78. cmake = { "cmake_format" },
  79. },
  80. format_on_save = {
  81. timeout_ms = 2000,
  82. lsp_fallback = true,
  83. },
  84. })
  85. -- 5. Linting (Replaces coc's pylint and shellcheck)
  86. local lint = require("lint")
  87. lint.linters_by_ft = {
  88. python = { "pylint" },
  89. sh = { "shellcheck" },
  90. rust = { "clippy", "cspell" },
  91. }
  92. vim.api.nvim_create_autocmd({ "BufWritePost" }, {
  93. callback = function()
  94. lint.try_lint()
  95. end,
  96. })
  97. -- 6. Diagnostics config
  98. vim.diagnostic.config({
  99. virtual_text = true,
  100. signs = true,
  101. update_in_insert = false,
  102. underline = true,
  103. severity_sort = true,
  104. float = { border = 'rounded' },
  105. })
  106. -- 7. Diagnostic & Spell Highlighting
  107. vim.api.nvim_set_hl(0, 'DiagnosticUnderlineError', { undercurl = true, sp = '#ff0000' })
  108. vim.api.nvim_set_hl(0, 'DiagnosticUnderlineWarn', { undercurl = true, sp = '#ff8800' })
  109. vim.api.nvim_set_hl(0, 'SpellBad', { undercurl = true, sp = '#ffff00' })
  110. vim.api.nvim_set_hl(0, 'SpellCap', { undercurl = true, sp = '#ffff00' })
  111. vim.api.nvim_set_hl(0, 'SpellLocal', { undercurl = true, sp = '#ffff00' })
  112. vim.api.nvim_set_hl(0, 'SpellRare', { undercurl = true, sp = '#ffff00' })