cmp.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. local cmp = require("cmp")
  2. cmp.setup(
  3. {
  4. experimental = {
  5. ghost_text = true
  6. },
  7. snippet = {
  8. expand = function(args)
  9. require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
  10. end
  11. },
  12. window = {
  13. completion = cmp.config.window.bordered(),
  14. documentation = cmp.config.window.bordered(),
  15. },
  16. mapping = cmp.mapping.preset.insert(
  17. {
  18. ["<C-k>"] = cmp.mapping.scroll_docs(-4),
  19. ["<C-j>"] = cmp.mapping.scroll_docs(4),
  20. ["<C-Space>"] = cmp.mapping.complete(),
  21. ["<C-e>"] = cmp.mapping.abort(),
  22. ["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
  23. ["<Tab>"] = cmp.mapping(
  24. function(fallback)
  25. local col = vim.fn.col(".") - 1
  26. if cmp.visible() then
  27. cmp.select_next_item(select_opts)
  28. elseif col == 0 or vim.fn.getline("."):sub(col, col):match("%s") then
  29. fallback()
  30. else
  31. cmp.complete()
  32. end
  33. end,
  34. { "i", "s" }
  35. )
  36. }
  37. ),
  38. sources = cmp.config.sources(
  39. {
  40. { name = "nvim_lsp" },
  41. { name = "luasnip" }
  42. },
  43. {
  44. { name = "buffer" }
  45. }
  46. )
  47. }
  48. )
  49. -- Set configuration for specific filetype.
  50. cmp.setup.filetype(
  51. "gitcommit",
  52. {
  53. sources = cmp.config.sources(
  54. {
  55. { name = "cmp_git" } -- You can specify the `cmp_git` source if you were installed it.
  56. },
  57. {
  58. { name = "buffer" }
  59. }
  60. )
  61. }
  62. )
  63. -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
  64. cmp.setup.cmdline(
  65. { "/", "?" },
  66. {
  67. mapping = cmp.mapping.preset.cmdline(),
  68. sources = {
  69. { name = "buffer" }
  70. }
  71. }
  72. )
  73. -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
  74. cmp.setup.cmdline(
  75. ":",
  76. {
  77. mapping = cmp.mapping.preset.cmdline(),
  78. sources = cmp.config.sources(
  79. {
  80. { name = "path" }
  81. },
  82. {
  83. { name = "cmdline" }
  84. }
  85. )
  86. }
  87. )
  88. -- lsp-format
  89. require("lsp-format").setup {}
  90. local on_attach = function(client)
  91. require("lsp-format").on_attach(client)
  92. end
  93. local caps = vim.tbl_extend(
  94. 'keep',
  95. vim.lsp.protocol.make_client_capabilities(),
  96. require('cmp_nvim_lsp').default_capabilities()
  97. );
  98. -- Set up lspconfig.
  99. local capabilities = require("cmp_nvim_lsp").default_capabilities()
  100. require('lspconfig')["nil_ls"].setup {
  101. on_attach = on_attach,
  102. capabilities = capabilities,
  103. settings = {
  104. ['nil'] = {
  105. testSetting = 42,
  106. formatting = {
  107. command = { "alejandra" },
  108. },
  109. },
  110. },
  111. }
  112. require("lspconfig")["rust_analyzer"].setup {
  113. on_attach = on_attach,
  114. capabilities = capabilities
  115. }
  116. require("lspconfig")["zk"].setup {
  117. on_attach = on_attach,
  118. capabilities = capabilities
  119. }
  120. require("lspconfig")["lua_ls"].setup {
  121. on_attach = on_attach,
  122. capabilities = capabilities
  123. }