completion.lua 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. -- return {
  2. -- { "hrsh7th/nvim-cmp", enabled = true },
  3. -- {
  4. -- "saghen/blink.cmp",
  5. -- lazy = false, -- lazy loading handled internally
  6. -- -- optional: provides snippets for the snippet source
  7. -- dependencies = "rafamadriz/friendly-snippets",
  8. --
  9. -- -- use a release tag to download pre-built binaries
  10. -- version = "v0.*",
  11. -- -- OR build from source, requires nightly: https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust
  12. -- -- build = 'cargo build --release',
  13. -- -- On musl libc based systems you need to add this flag
  14. -- -- build = 'RUSTFLAGS="-C target-feature=-crt-static" cargo build --release',
  15. --
  16. -- opts = {
  17. -- highlight = {
  18. -- -- sets the fallback highlight groups to nvim-cmp's highlight groups
  19. -- -- useful for when your theme doesn't support blink.cmp
  20. -- -- will be removed in a future release, assuming themes add support
  21. -- use_nvim_cmp_as_default = true,
  22. -- },
  23. -- keymap = {
  24. --
  25. -- }
  26. -- -- set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
  27. -- -- adjusts spacing to ensure icons are aligned
  28. -- nerd_font_variant = "normal",
  29. --
  30. -- -- experimental auto-brackets support
  31. -- accept = { auto_brackets = { enabled = true } },
  32. --
  33. -- -- experimental signature help support
  34. -- trigger = { signature_help = { enabled = true } }
  35. -- },
  36. -- },
  37. -- { "hrsh7th/cmp-nvim-lsp", lazy = false },
  38. -- }
  39. return {
  40. { "hrsh7th/cmp-nvim-lsp" },
  41. {
  42. "L3MON4D3/LuaSnip",
  43. -- follow latest release.
  44. version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
  45. -- install jsregexp (optional!).
  46. build = "make install_jsregexp",
  47. dependencies = { "saadparwaiz1/cmp_luasnip", "rafamadriz/friendly-snippets" },
  48. },
  49. {
  50. "hrsh7th/nvim-cmp",
  51. dependencies = {
  52. "hrsh7th/cmp-buffer",
  53. "f3fora/cmp-spell",
  54. "hrsh7th/cmp-path",
  55. "hrsh7th/cmp-emoji",
  56. "R-nvim/cmp-r",
  57. "hrsh7th/cmp-nvim-lsp-signature-help",
  58. "onsails/lspkind.nvim",
  59. },
  60. config = function()
  61. local cmp = require("cmp")
  62. local luasnip = require("luasnip")
  63. local lspkind = require("lspkind")
  64. -- gray
  65. vim.api.nvim_set_hl(0, "CmpItemAbbrDeprecated", { bg = "NONE", strikethrough = true, fg = "#808080" })
  66. -- blue
  67. vim.api.nvim_set_hl(0, "CmpItemAbbrMatch", { bg = "NONE", fg = "#569CD6" })
  68. vim.api.nvim_set_hl(0, "CmpItemAbbrMatchFuzzy", { link = "CmpIntemAbbrMatch" })
  69. -- light blue
  70. vim.api.nvim_set_hl(0, "CmpItemKindVariable", { bg = "NONE", fg = "#9CDCFE" })
  71. vim.api.nvim_set_hl(0, "CmpItemKindInterface", { link = "CmpItemKindVariable" })
  72. vim.api.nvim_set_hl(0, "CmpItemKindText", { link = "CmpItemKindVariable" })
  73. -- pink
  74. vim.api.nvim_set_hl(0, "CmpItemKindFunction", { bg = "NONE", fg = "#C586C0" })
  75. vim.api.nvim_set_hl(0, "CmpItemKindMethod", { link = "CmpItemKindFunction" })
  76. -- front
  77. vim.api.nvim_set_hl(0, "CmpItemKindKeyword", { bg = "NONE", fg = "#D4D4D4" })
  78. vim.api.nvim_set_hl(0, "CmpItemKindProperty", { link = "CmpItemKindKeyword" })
  79. vim.api.nvim_set_hl(0, "CmpItemKindUnit", { link = "CmpItemKindKeyword" })
  80. require("luasnip.loaders.from_vscode").lazy_load()
  81. cmp.setup({
  82. snippet = {
  83. -- REQUIRED - you must specify a snippet engine
  84. expand = function(args)
  85. -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
  86. require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
  87. -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
  88. -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
  89. -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
  90. end,
  91. },
  92. view = {
  93. entries = "custom", -- can be "custom", "wildmenu" or "native"
  94. },
  95. window = {
  96. documentation = {
  97. -- max_height = math.floor(WIDE_HEIGHT * (WIDE_HEIGHT / vim.o.lines)),
  98. -- max_width = math.floor((WIDE_HEIGHT * 2) * (vim.o.columns / (WIDE_HEIGHT * 2 * 16 / 9))),
  99. border = { "", "", "", " ", "", "", "", " " },
  100. winhighlight = "Normal:Pmenu",
  101. winblend = vim.o.pumblend,
  102. },
  103. -- completion = cmp.config.window.bordered(),
  104. -- documentation = cmp.config.window.bordered(),
  105. },
  106. formatting = {
  107. format = lspkind.cmp_format(),
  108. },
  109. mapping = cmp.mapping.preset.insert({
  110. ["<C-b>"] = cmp.mapping.scroll_docs(-4),
  111. ["<C-f>"] = cmp.mapping.scroll_docs(4),
  112. ["<C-Space>"] = cmp.mapping.complete(),
  113. ["<C-e>"] = cmp.mapping.abort(),
  114. ["<CR>"] = cmp.mapping(function(fallback)
  115. if cmp.visible() then
  116. if luasnip.expandable() then
  117. luasnip.expand()
  118. else
  119. cmp.confirm({
  120. select = true,
  121. })
  122. end
  123. else
  124. fallback()
  125. end
  126. end),
  127. ["<Tab>"] = cmp.mapping(function(fallback)
  128. if cmp.visible() then
  129. cmp.select_next_item()
  130. elseif luasnip.locally_jumpable(1) then
  131. luasnip.jump(1)
  132. else
  133. fallback()
  134. end
  135. end, { "i", "s" }),
  136. ["<S-Tab>"] = cmp.mapping(function(fallback)
  137. if cmp.visible() then
  138. cmp.select_prev_item()
  139. elseif luasnip.locally_jumpable(-1) then
  140. luasnip.jump(-1)
  141. else
  142. fallback()
  143. end
  144. end, { "i", "s" }),
  145. }),
  146. sources = cmp.config.sources({
  147. { name = "nvim_lsp" },
  148. { name = "buffer" },
  149. { name = "luasnip" }, -- For luasnip users.
  150. { name = "emoji" },
  151. { name = "crates" }, -- cf rust
  152. { name = "cmp_r" },
  153. { name = "nvim_lsp_signature_help" },
  154. {
  155. name = "spell",
  156. option = {
  157. keep_all_entries = false,
  158. enable_in_context = function()
  159. return true
  160. end,
  161. preselect_correct_word = true,
  162. },
  163. },
  164. {
  165. name = "path",
  166. option = {
  167. -- Options go into this table
  168. },
  169. },
  170. -- { name = 'ultisnips' }, -- For ultisnips users.
  171. -- { name = 'snippy' }, -- For snippy users.
  172. }, {
  173. { name = "buffer" },
  174. }),
  175. })
  176. --
  177. -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
  178. cmp.setup.cmdline({ "/", "?" }, {
  179. mapping = cmp.mapping.preset.cmdline(),
  180. sources = {
  181. { name = "buffer" },
  182. },
  183. })
  184. -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
  185. -- cmp.setup.cmdline(":", {
  186. -- mapping = cmp.mapping.preset.cmdline(),
  187. -- sources = cmp.config.sources({
  188. -- { name = "path" },
  189. -- }, {
  190. -- { name = "cmdline" },
  191. -- }),
  192. -- matching = { disallow_symbol_nonprefix_matching = false },
  193. -- })
  194. end,
  195. },
  196. }