Created
December 15, 2024 13:36
-
-
Save rodrigore/5546632a5e13e67f461ca4c0f5fe92ae to your computer and use it in GitHub Desktop.
Revisions
-
rodrigore created this gist
Dec 15, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ local cmp = require("cmp") return { "hrsh7th/nvim-cmp", enabled = false, opts = function(_, opts) local has_words_before = function() unpack = unpack or table.unpack local line, col = unpack(vim.api.nvim_win_get_cursor(0)) return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil end local cmp = require("cmp") opts.completion = vim.tbl_extend("force", opts.completion, { autocomplete = false, }) opts.mapping = vim.tbl_extend("force", opts.mapping, { ["<Tab>"] = cmp.mapping(function(fallback) local copilot_ok, copilot_suggestion = pcall(require, "copilot.suggestion") if vim.snippet.active({ direction = 1 }) then vim.schedule(function() vim.snippet.jump(1) end) elseif copilot_ok and copilot_suggestion.is_visible() then copilot_suggestion.accept() elseif has_words_before() then cmp.complete() else fallback() end end, { "i", "s" }), ["<S-Tab>"] = cmp.mapping(function(fallback) local copilot_ok, copilot_suggestion = pcall(require, "copilot.suggestion") if vim.snippet.active({ direction = -1 }) then vim.schedule(function() vim.snippet.jump(-1) end) elseif copilot_ok and copilot_suggestion.is_visible() then copilot_suggestion.next() else fallback() end end, { "i", "s" }), }) end,