From 0792328281e2bc899b966191f599719fda52b8ba Mon Sep 17 00:00:00 2001 From: rootiest Date: Sun, 4 Aug 2024 17:59:32 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20perf(nvim-cmp):=20toggle?= =?UTF-8?q?=20cmp=20sources=20based=20on=20ft?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow some/all cmp sources to be enabled/disabled depending on the filetype of the buffer --- lua/plugins/coding.lua | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/lua/plugins/coding.lua b/lua/plugins/coding.lua index f86ed49..79ea6b0 100644 --- a/lua/plugins/coding.lua +++ b/lua/plugins/coding.lua @@ -72,13 +72,37 @@ return { "hrsh7th/nvim-cmp", ---@param opts cmp.ConfigSchema opts = function(_, opts) - table.insert(opts.sources, { name = "emoji" }) - table.insert(opts.sources, { name = "cmp_yanky" }) - table.insert(opts.sources, { name = "dotenv" }) - table.insert(opts.sources, { name = "calc" }) - table.insert(opts.sources, { name = "conventionalcommits" }) - table.insert(opts.sources, { name = "gitmoji" }) local cmp = require("cmp") + + -- Global sources + opts.sources = { + { name = "emoji" }, + { name = "cmp_yanky" }, + { name = "dotenv" }, + { name = "calc" }, + { name = "conventionalcommits" }, + { name = "gitmoji" }, + } + + -- General setup + cmp.setup(opts) + + -- Filetype-specific setup + cmp.setup.filetype("config", { + sources = vim.tbl_filter(function(source) + return source.name ~= "emoji" and source.name ~= "gitmoji" + end, opts.sources), + }) + + -- List of filetypes to disable completion + local disabled_filetypes = { "dashboard", "qalc" } + for _, filetype in ipairs(disabled_filetypes) do + cmp.setup.filetype(filetype, { + sources = {}, + }) + end + + -- Key mappings cmp.setup({ mapping = { [""] = cmp.mapping.select_prev_item(),