lsp.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. signature = { enabled = true }
  20. })
  21. -- Load custom snippets from ~/.config/nvim/snips
  22. require("luasnip.loaders.from_vscode").lazy_load({ paths = { "~/.config/nvim/snips" } })
  23. require("luasnip.loaders.from_snipmate").lazy_load({ paths = { "~/.config/nvim/snips" } })
  24. -- 2. Define on_attach
  25. local on_attach = function(client, bufnr)
  26. -- Keymaps are handled globally in bindings.vim
  27. end
  28. -- 3. Configure Servers using Neovim 0.11 API where possible
  29. local capabilities = blink.get_lsp_capabilities()
  30. -- Basic servers
  31. local servers = { 'pyright', 'bashls', 'html', 'cssls', 'jdtls' }
  32. for _, server in ipairs(servers) do
  33. vim.lsp.config(server, {
  34. capabilities = capabilities,
  35. on_attach = on_attach,
  36. })
  37. vim.lsp.enable(server)
  38. end
  39. -- Custom Veridian setup (Verilog)
  40. vim.lsp.config('veridian', {
  41. cmd = { 'veridian' },
  42. filetypes = { 'systemverilog', 'verilog' },
  43. capabilities = capabilities,
  44. on_attach = on_attach,
  45. })
  46. vim.lsp.enable('veridian')
  47. -- Custom CCLS setup (C/C++)
  48. vim.lsp.config('ccls', {
  49. init_options = {
  50. cache = { directory = "/tmp/ccls-cache" },
  51. client = { snippetSupport = true }
  52. },
  53. root_patterns = { ".ccls-root", "compile_commands.json", ".git" },
  54. capabilities = capabilities,
  55. on_attach = on_attach,
  56. })
  57. vim.lsp.enable('ccls')
  58. -- 4. Formatting (Replaces coc's formatOnSave)
  59. local conform = require("conform")
  60. conform.setup({
  61. formatters_by_ft = {
  62. python = { "black" },
  63. java = { "google-java-format" },
  64. sh = { "shfmt" },
  65. },
  66. format_on_save = {
  67. timeout_ms = 500,
  68. lsp_fallback = true,
  69. },
  70. })
  71. -- 5. Linting (Replaces coc's pylint and shellcheck)
  72. local lint = require("lint")
  73. lint.linters_by_ft = {
  74. python = { "pylint" },
  75. sh = { "shellcheck" },
  76. }
  77. vim.api.nvim_create_autocmd({ "BufWritePost" }, {
  78. callback = function()
  79. lint.try_lint()
  80. end,
  81. })
  82. -- 6. Diagnostics config
  83. vim.diagnostic.config({
  84. virtual_text = true,
  85. signs = true,
  86. update_in_insert = false,
  87. underline = true,
  88. severity_sort = true,
  89. float = { border = 'rounded' },
  90. })
  91. -- 7. Diagnostic & Spell Highlighting
  92. vim.api.nvim_set_hl(0, 'DiagnosticUnderlineError', { undercurl = true, sp = '#ff0000' })
  93. vim.api.nvim_set_hl(0, 'DiagnosticUnderlineWarn', { undercurl = true, sp = '#ff8800' })
  94. vim.api.nvim_set_hl(0, 'SpellBad', { undercurl = true, sp = '#ffff00' })
  95. vim.api.nvim_set_hl(0, 'SpellCap', { undercurl = true, sp = '#ffff00' })
  96. vim.api.nvim_set_hl(0, 'SpellLocal', { undercurl = true, sp = '#ffff00' })
  97. vim.api.nvim_set_hl(0, 'SpellRare', { undercurl = true, sp = '#ffff00' })