lsp.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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' }
  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. -- Custom CCLS setup (C/C++)
  51. vim.lsp.config('ccls', {
  52. init_options = {
  53. cache = { directory = "/tmp/ccls-cache" },
  54. client = { snippetSupport = true }
  55. },
  56. root_patterns = { ".ccls-root", "compile_commands.json", ".git" },
  57. capabilities = capabilities,
  58. on_attach = on_attach,
  59. })
  60. vim.lsp.enable('ccls')
  61. -- 4. Formatting (Replaces coc's formatOnSave)
  62. local conform = require("conform")
  63. conform.setup({
  64. formatters_by_ft = {
  65. python = { "black" },
  66. java = { "google-java-format" },
  67. sh = { "shfmt" },
  68. rust = { "rustfmt" },
  69. },
  70. format_on_save = {
  71. timeout_ms = 2000,
  72. lsp_fallback = true,
  73. },
  74. })
  75. -- 5. Linting (Replaces coc's pylint and shellcheck)
  76. local lint = require("lint")
  77. lint.linters_by_ft = {
  78. python = { "pylint" },
  79. sh = { "shellcheck" },
  80. rust = { "clippy", "cspell" },
  81. }
  82. vim.api.nvim_create_autocmd({ "BufWritePost" }, {
  83. callback = function()
  84. lint.try_lint()
  85. end,
  86. })
  87. -- 6. Diagnostics config
  88. vim.diagnostic.config({
  89. virtual_text = true,
  90. signs = true,
  91. update_in_insert = false,
  92. underline = true,
  93. severity_sort = true,
  94. float = { border = 'rounded' },
  95. })
  96. -- 7. Diagnostic & Spell Highlighting
  97. vim.api.nvim_set_hl(0, 'DiagnosticUnderlineError', { undercurl = true, sp = '#ff0000' })
  98. vim.api.nvim_set_hl(0, 'DiagnosticUnderlineWarn', { undercurl = true, sp = '#ff8800' })
  99. vim.api.nvim_set_hl(0, 'SpellBad', { undercurl = true, sp = '#ffff00' })
  100. vim.api.nvim_set_hl(0, 'SpellCap', { undercurl = true, sp = '#ffff00' })
  101. vim.api.nvim_set_hl(0, 'SpellLocal', { undercurl = true, sp = '#ffff00' })
  102. vim.api.nvim_set_hl(0, 'SpellRare', { undercurl = true, sp = '#ffff00' })