My dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.3 KiB

  1. -- TODO: show function signature help on hover
  2. -- web, vimtex
  3. -- Mappings.
  4. -- See `:help vim.diagnostic.*` for documentation on any of the below functions
  5. local opts = { noremap = true, silent = true }
  6. vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
  7. vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
  8. vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
  9. vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
  10. -- Use an on_attach function to only map the following keys
  11. -- after the language server attaches to the current buffer
  12. local on_attach = function(client, bufnr)
  13. -- Enable completion triggered by <c-x><c-o>
  14. vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
  15. -- Mappings.
  16. -- See `:help vim.lsp.*` for documentation on any of the below functions
  17. local bufopts = { noremap = true, silent = true, buffer = bufnr }
  18. vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
  19. vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
  20. vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
  21. vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
  22. vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
  23. vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
  24. vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
  25. vim.keymap.set('n', '<space>wl', function()
  26. print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
  27. end, bufopts)
  28. vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
  29. vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
  30. vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
  31. vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
  32. vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
  33. end
  34. local lsp_flags = {
  35. -- This is the default in Nvim 0.7+
  36. debounce_text_changes = 150,
  37. }
  38. local servers = { 'tsserver', 'rust_analyzer', 'clangd', 'sumneko_lua' }
  39. local lspconfig = require('lspconfig')
  40. lspconfig['sumneko_lua'].setup {
  41. on_attach = on_attach,
  42. flags = lsp_flags,
  43. settings = {
  44. Lua = {
  45. runtime = {
  46. -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
  47. version = 'LuaJIT',
  48. },
  49. diagnostics = {
  50. -- Get the language server to recognize the `vim` global
  51. globals = { 'vim' },
  52. },
  53. workspace = {
  54. -- Make the server aware of Neovim runtime files
  55. library = vim.api.nvim_get_runtime_file("", true),
  56. },
  57. -- Do not send telemetry data containing a randomized but unique identifier
  58. telemetry = {
  59. enable = false,
  60. },
  61. },
  62. },
  63. }
  64. local capabilities = vim.lsp.protocol.make_client_capabilities()
  65. capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
  66. for _, lsp in ipairs(servers) do
  67. lspconfig[lsp].setup {
  68. on_attach = on_attach,
  69. flags = lsp_flags,
  70. capabilities = capabilities,
  71. }
  72. end
  73. local luasnip = require 'luasnip'
  74. local cmp = require 'cmp'
  75. cmp.setup {
  76. snippet = {
  77. expand = function(args)
  78. luasnip.lsp_expand(args.body)
  79. end,
  80. },
  81. mapping = cmp.mapping.preset.insert({
  82. ['<C-d>'] = cmp.mapping.scroll_docs(-4),
  83. ['<C-f>'] = cmp.mapping.scroll_docs(4),
  84. ['<C-Space>'] = cmp.mapping.complete(),
  85. ['<CR>'] = cmp.mapping.confirm {
  86. behavior = cmp.ConfirmBehavior.Replace,
  87. select = true,
  88. },
  89. ['<Tab>'] = cmp.mapping(function(fallback)
  90. if cmp.visible() then
  91. cmp.select_next_item()
  92. elseif luasnip.expand_or_jumpable() then
  93. luasnip.expand_or_jump()
  94. else
  95. fallback()
  96. end
  97. end, { 'i', 's' }),
  98. ['<S-Tab>'] = cmp.mapping(function(fallback)
  99. if cmp.visible() then
  100. cmp.select_prev_item()
  101. elseif luasnip.jumpable(-1) then
  102. luasnip.jump(-1)
  103. else
  104. fallback()
  105. end
  106. end, { 'i', 's' }),
  107. }),
  108. sources = {
  109. { name = 'nvim_lsp' },
  110. { name = 'luasnip' },
  111. },
  112. }