From 2c709d3fcd0d14c521137bf1d5cb79bb27303e07 Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.uk>
Date: Tue, 5 Sep 2023 07:24:34 +0100
Subject: [PATCH] fix(nvim): re-add completion configuration

---
 config/neovim/after/plugin/completion.lua | 75 +++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 config/neovim/after/plugin/completion.lua

diff --git a/config/neovim/after/plugin/completion.lua b/config/neovim/after/plugin/completion.lua
new file mode 100644
index 00000000..b7d05af3
--- /dev/null
+++ b/config/neovim/after/plugin/completion.lua
@@ -0,0 +1,75 @@
+local cmp_status_ok, cmp = pcall(require, "cmp")
+if not cmp_status_ok then
+  return
+end
+
+local snip_status_ok, luasnip = pcall(require, "luasnip")
+if not snip_status_ok then
+  return
+end
+
+vim.opt.shortmess:append "c"
+
+cmp.setup {
+  snippet = {
+    expand = function(args)
+      luasnip.lsp_expand(args.body)
+    end,
+  },
+
+  mapping = cmp.mapping.preset.insert {
+    ["<C-d>"] = cmp.mapping.scroll_docs(-4),
+    ["<C-e>"] = cmp.mapping.close(),
+    ["<C-f>"] = cmp.mapping.scroll_docs(4),
+    ["<C-y>"] = cmp.mapping.confirm { select = true },
+    ["<tab>"] = cmp.config.disable,
+  },
+
+  sources = {
+    { name = "nvim_lsp_signature_help" },
+    { name = "nvim_lsp" },
+    { name = "nvim_lua" },
+    { name = "cmp_tabnine" },
+    { name = "path" },
+    { name = "luasnip" },
+    { name = "buffer", keyword_length = 5, max_item_count = 5 },
+  },
+
+  sorting = {
+    comparators = {
+      cmp.config.compare.offset,
+      cmp.config.compare.exact,
+      cmp.config.compare.score,
+      cmp.config.compare.kind,
+      cmp.config.compare.sort_text,
+      cmp.config.compare.length,
+      cmp.config.compare.order,
+    },
+  },
+
+  formatting = {
+    format = require("lspkind").cmp_format {
+      with_text = true,
+      menu = {
+        buffer = "[buf]",
+        cmp_tabnine = "[tn]",
+        luasnip = "[snip]",
+        nvim_lsp = "[lsp]",
+        nvim_lua = "[lua]",
+        path = "[path]",
+      },
+    },
+  },
+
+  experimental = {
+    ghost_text = false,
+    native_menu = false,
+  },
+}
+
+vim.cmd [[
+  augroup DadbodSql
+    au!
+    autocmd FileType sql,mysql,plsql lua require('cmp').setup.buffer { sources = { { name = 'vim-dadbod-completion' } } }
+  augroup END
+]]