1
0

lsp.nix 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. {
  2. autoCmd = [
  3. {
  4. event = "LspAttach";
  5. desc = "Keymaps for when LSP is attached";
  6. group = "kickstart-lsp-attach";
  7. callback.__raw = ''
  8. function(event)
  9. local map = function(keys, func, desc)
  10. vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
  11. end
  12. -- Jump to the definition of the word under your cursor.
  13. -- This is where a variable was first declared, or where a function is defined, etc.
  14. -- To jump back, press <C-t>.
  15. map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
  16. -- Find references for the word under your cursor.
  17. map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
  18. -- Jump to the implementation of the word under your cursor.
  19. -- Useful when your language has ways of declaring types without an actual implementation.
  20. map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
  21. -- Jump to the type of the word under your cursor.
  22. -- Useful when you're not sure what type a variable is and you want to see
  23. -- the definition of its *type*, not where it was *defined*.
  24. map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
  25. -- Fuzzy find all the symbols in your current document.
  26. -- Symbols are things like variables, functions, types, etc.
  27. map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
  28. -- Fuzzy find all the symbols in your current workspace.
  29. -- Similar to document symbols, except searches over your entire project.
  30. map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
  31. -- Rename the variable under your cursor.
  32. -- Most Language Servers support renaming across files, etc.
  33. map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
  34. -- Execute a code action, usually your cursor needs to be on top of an error
  35. -- or a suggestion from your LSP for this to activate.
  36. map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
  37. -- WARN: This is not Goto Definition, this is Goto Declaration.
  38. -- For example, in C this would take you to the header.
  39. map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
  40. -- The following two autocommands are used to highlight references of the
  41. -- word under your cursor when your cursor rests there for a little while.
  42. -- See `:help CursorHold` for information about when this is executed
  43. --
  44. -- When you move your cursor, the highlights will be cleared (the second autocommand).
  45. local client = vim.lsp.get_client_by_id(event.data.client_id)
  46. if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then
  47. local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false })
  48. vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
  49. buffer = event.buf,
  50. group = highlight_augroup,
  51. callback = vim.lsp.buf.document_highlight,
  52. })
  53. vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
  54. buffer = event.buf,
  55. group = highlight_augroup,
  56. callback = vim.lsp.buf.clear_references,
  57. })
  58. vim.api.nvim_create_autocmd('LspDetach', {
  59. group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }),
  60. callback = function(event2)
  61. vim.lsp.buf.clear_references()
  62. vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf }
  63. end,
  64. })
  65. end
  66. -- The following code creates a keymap to toggle inlay hints in your
  67. -- code, if the language server you are using supports them
  68. --
  69. -- This may be unwanted, since they displace some of your code
  70. if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
  71. map('<leader>th', function()
  72. vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
  73. end, '[T]oggle Inlay [H]ints')
  74. end
  75. end
  76. '';
  77. }
  78. ];
  79. autoGroups = {
  80. "kickstart-lsp-attach".clear = true;
  81. };
  82. keymaps = [
  83. {
  84. key = "<C-h>";
  85. action.__raw = "vim.lsp.buf.signature_help";
  86. mode = "i";
  87. }
  88. ];
  89. plugins.lsp = {
  90. enable = true;
  91. keymaps = {
  92. diagnostic = {
  93. "<leader>vd" = "open_float";
  94. "[d" = "goto_next";
  95. "]d" = "goto_prev";
  96. };
  97. lspBuf = {
  98. "<leader>f" = "format";
  99. "gd" = "definition";
  100. "K" = "hover";
  101. "<leader>vws" = "workspace_symbol";
  102. "<leader>vca" = "code_action";
  103. "<leader>vrr" = "references";
  104. "<leader>vrn" = "rename";
  105. };
  106. };
  107. servers = {
  108. astro.enable = true;
  109. bashls.enable = true;
  110. denols = {
  111. enable = true;
  112. rootDir = "require('lspconfig').util.root_pattern('deno.json')";
  113. extraOptions.init_options = {
  114. lint = true;
  115. unstable = true;
  116. };
  117. };
  118. gopls.enable = true;
  119. # elixirls.enable = true;
  120. nextls.enable = true;
  121. nil_ls.enable = true;
  122. tailwindcss.enable = true;
  123. ts_ls = {
  124. enable = true;
  125. extraOptions.single_file_support = false;
  126. rootDir = ''
  127. require('lspconfig').util.root_pattern("tsconfig.json")
  128. '';
  129. };
  130. volar.enable = true;
  131. # rootDir = ''
  132. # # root_pattern = { 'vite.config.ts', 'nuxt.config.ts' },
  133. #
  134. #
  135. # require('lspconfig').util.root_pattern("vite.config.mts")
  136. # '';
  137. # };
  138. };
  139. };
  140. }