feat(copilot)!: move from copilot.vim to copilot.lua and copilot-cmp

Breaking change: Tab completion no longer does anything - it just adds a
tab as it should
- To use completion use CTRL + J and CTRL + K
This commit is contained in:
Jiří Štefka 2023-09-22 21:53:13 +02:00
parent 730d24f51d
commit fb861daa38
Signed by: jiriks74
GPG Key ID: 1D5E30D3DB2264DE

147
init.lua

@ -9,15 +9,15 @@
local config = { local config = {
-- Configure AstroNvim updates -- Configure AstroNvim updates
updater = { updater = {
remote = "origin", -- remote to use remote = "origin", -- remote to use
channel = "nightly", -- "stable" or "nightly" channel = "nightly", -- "stable" or "nightly"
version = "latest", -- "latest", tag name, or regex search like "v1.*" to only do updates before v2 (STABLE ONLY) version = "latest", -- "latest", tag name, or regex search like "v1.*" to only do updates before v2 (STABLE ONLY)
branch = "nightly", -- branch name (NIGHTLY ONLY) branch = "nightly", -- branch name (NIGHTLY ONLY)
commit = nil, -- commit hash (NIGHTLY ONLY) commit = nil, -- commit hash (NIGHTLY ONLY)
pin_plugins = nil, -- nil, true, false (nil will pin plugins on stable only) pin_plugins = nil, -- nil, true, false (nil will pin plugins on stable only)
skip_prompts = false, -- skip prompts about breaking changes skip_prompts = false, -- skip prompts about breaking changes
show_changelog = true, -- show the changelog after performing an update show_changelog = true, -- show the changelog after performing an update
auto_quit = false, -- automatically quit the current session after a successful update auto_quit = false, -- automatically quit the current session after a successful update
-- remotes = { -- easily add new remotes to track -- remotes = { -- easily add new remotes to track
-- ["remote_name"] = "https://remote_url.come/repo.git", -- full remote url -- ["remote_name"] = "https://remote_url.come/repo.git", -- full remote url
-- ["remote2"] = "github_user/repo", -- GitHub user/repo shortcut, -- ["remote2"] = "github_user/repo", -- GitHub user/repo shortcut,
@ -41,23 +41,19 @@ local config = {
opt = { opt = {
-- set to true or false etc. -- set to true or false etc.
relativenumber = true, -- sets vim.opt.relativenumber relativenumber = true, -- sets vim.opt.relativenumber
number = true, -- sets vim.opt.number number = true, -- sets vim.opt.number
spell = false, -- sets vim.opt.spell spell = false, -- sets vim.opt.spell
signcolumn = "auto", -- sets vim.opt.signcolumn to auto signcolumn = "auto", -- sets vim.opt.signcolumn to auto
wrap = false, -- sets vim.opt.wrap wrap = false, -- sets vim.opt.wrap
}, },
g = { g = {
mapleader = " ", -- sets vim.g.mapleader mapleader = " ", -- sets vim.g.mapleader
autoformat_enabled = true, -- enable or disable auto formatting at start (lsp.formatting.format_on_save must be enabled) autoformat_enabled = true, -- enable or disable auto formatting at start (lsp.formatting.format_on_save must be enabled)
cmp_enabled = true, -- enable completion at start cmp_enabled = true, -- enable completion at start
autopairs_enabled = true, -- enable autopairs at start autopairs_enabled = true, -- enable autopairs at start
diagnostics_mode = 3, -- set the visibility of diagnostics in the UI (0=off, 1=only show in status line, 2=virtual text off, 3=all on) diagnostics_mode = 3, -- set the visibility of diagnostics in the UI (0=off, 1=only show in status line, 2=virtual text off, 3=all on)
icons_enabled = true, -- disable icons in the UI (disable if no nerd font is available, requires :PackerSync after changing) icons_enabled = true, -- disable icons in the UI (disable if no nerd font is available, requires :PackerSync after changing)
ui_notifications_enabled = true, -- disable notifications when toggling UI elements ui_notifications_enabled = true, -- disable notifications when toggling UI elements
-- Copilot
copilot_no_tab_map = true,
copilot_assume_mapped = true,
copilot_tab_fallback = "",
-- Taglist -- Taglist
Tlist_Use_Right_Window = 1, Tlist_Use_Right_Window = 1,
Tlist_GainFocus_On_ToggleOpen = 1, Tlist_GainFocus_On_ToggleOpen = 1,
@ -91,7 +87,7 @@ local config = {
formatting = { formatting = {
-- control auto formatting on save -- control auto formatting on save
format_on_save = { format_on_save = {
enabled = false, -- enable or disable format on save globally enabled = false, -- enable or disable format on save globally
allow_filetypes = { -- enable format on save for specified filetypes only allow_filetypes = { -- enable format on save for specified filetypes only
-- "go", -- "go",
}, },
@ -184,7 +180,7 @@ local config = {
["<leader>dl"] = { name = "Load launch.json" }, ["<leader>dl"] = { name = "Load launch.json" },
["<leader>L"] = { ["<leader>L"] = {
"<cmd>LiveServer<cr>", "<cmd>LiveServer<cr>",
desc = " Live server" desc = " Live server",
}, },
-- Config loading -- Config loading
["<leader>dlc"] = { ["<leader>dlc"] = {
@ -346,6 +342,10 @@ local config = {
{ {
-- override nvim-cmp plugin -- override nvim-cmp plugin
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-emoji", -- add cmp source as dependency of cmp
"zbirenbaum/copilot.lua",
},
-- override the options table that is used in the `require("cmp").setup()` call -- override the options table that is used in the `require("cmp").setup()` call
opts = function(_, opts) opts = function(_, opts)
-- opts parameter is the default options table -- opts parameter is the default options table
@ -353,29 +353,58 @@ local config = {
local cmp = require "cmp" local cmp = require "cmp"
local luasnip = require "luasnip" local luasnip = require "luasnip"
-- modify the mapping part of the table -- modify the mapping part of the table
-- Disable tab completion, use CTRL + J or CTRL + K instead
opts.mapping["<CR>"] = cmp.mapping.confirm { select = false } opts.mapping["<CR>"] = cmp.mapping.confirm { select = false }
opts.mapping["<Tab>"] = cmp.mapping( opts.mapping["<TAB>"] = cmp.mapping.confirm { select = false }
function(fallback)
vim.api.nvim_feedkeys(
vim.fn["copilot#Accept"](vim.api.nvim_replace_termcodes("<Tab>", true, true, true)),
"n",
true
)
end
)
if luasnip.expandable() then if luasnip.expandable() then
luasnip.expand() luasnip.expand()
elseif luasnip.expand_or_jumpable() then elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
fallback() fallback()
end end
opts.experimental = { opts.sources = cmp.config.sources {
ghost_text = false, -- this feature conflict with copilot.vim's preview. -- Copilot Source
{ name = "copilot", group_index = 2 },
{ name = "nvim_lsp", priority = 1000 },
{ name = "luasnip", priority = 750 },
{ name = "buffer", priority = 500 },
{ name = "path", priority = 250 },
{ name = "emoji", priority = 700 }, -- add new source
} }
-- return the new table to be used
return opts return opts
end, end,
}, },
{
"onsails/lspkind.nvim",
opts = {
mode = "symbol",
symbol_map = {
-- Copilot icon
Copilot = "",
Array = "󰅪",
Boolean = "",
Class = "󰌗",
Constructor = "",
Key = "󰌆",
Namespace = "󰅪",
Null = "NULL",
Number = "#",
Object = "󰀚",
Package = "󰏗",
Property = "",
Reference = "",
Snippet = "",
String = "󰀬",
TypeParameter = "󰊄",
Unit = "",
},
menu = {},
},
enabled = vim.g.icons_enabled,
config = require "plugins.configs.lspkind",
},
-- Editorconfig -- Editorconfig
{ {
@ -430,8 +459,8 @@ local config = {
-- keywords recognized as todo comments -- keywords recognized as todo comments
keywords = { keywords = {
FIX = { FIX = {
icon = "", -- icon used for the sign, and in search results icon = "", -- icon used for the sign, and in search results
color = "error", -- can be a hex color, or a named color (see below) color = "error", -- can be a hex color, or a named color (see below)
alt = { "FIXME", "BUG", "FIXIT", "ISSUE" }, -- a set of other keywords that all map to this FIX keywords alt = { "FIXME", "BUG", "FIXIT", "ISSUE" }, -- a set of other keywords that all map to this FIX keywords
-- signs = false, -- configure signs for some keywords individually -- signs = false, -- configure signs for some keywords individually
}, },
@ -443,8 +472,8 @@ local config = {
TEST = { icon = "", color = "test", alt = { "TESTING", "PASSED", "FAILED" } }, TEST = { icon = "", color = "test", alt = { "TESTING", "PASSED", "FAILED" } },
}, },
gui_style = { gui_style = {
fg = "NONE", -- The gui style to use for the fg highlight group. fg = "NONE", -- The gui style to use for the fg highlight group.
bg = "BOLD", -- The gui style to use for the bg highlight group. bg = "BOLD", -- The gui style to use for the bg highlight group.
}, },
merge_keywords = true, -- when true, custom keywords will be merged with the defaults merge_keywords = true, -- when true, custom keywords will be merged with the defaults
-- highlighting of the line containing the todo comment -- highlighting of the line containing the todo comment
@ -452,16 +481,16 @@ local config = {
-- * keyword: highlights of the keyword -- * keyword: highlights of the keyword
-- * after: highlights after the keyword (todo text) -- * after: highlights after the keyword (todo text)
highlight = { highlight = {
multiline = true, -- enable multine todo comments multiline = true, -- enable multine todo comments
multiline_pattern = "^.", -- lua pattern to match the next multiline from the start of the matched keyword multiline_pattern = "^.", -- lua pattern to match the next multiline from the start of the matched keyword
multiline_context = 10, -- extra lines that will be re-evaluated when changing a line multiline_context = 10, -- extra lines that will be re-evaluated when changing a line
before = "", -- "fg" or "bg" or empty before = "", -- "fg" or "bg" or empty
keyword = "wide", -- "fg", "bg", "wide", "wide_bg", "wide_fg" or empty. (wide and wide_bg is the same as bg, but will also highlight surrounding characters, wide_fg acts accordingly but with fg) keyword = "wide", -- "fg", "bg", "wide", "wide_bg", "wide_fg" or empty. (wide and wide_bg is the same as bg, but will also highlight surrounding characters, wide_fg acts accordingly but with fg)
after = "fg", -- "fg" or "bg" or empty after = "fg", -- "fg" or "bg" or empty
pattern = [[.*<(KEYWORDS)\s*:]], -- pattern or table of patterns, used for highlighting (vim regex) pattern = [[.*<(KEYWORDS)\s*:]], -- pattern or table of patterns, used for highlighting (vim regex)
comments_only = true, -- uses treesitter to match keywords in comments only comments_only = true, -- uses treesitter to match keywords in comments only
max_line_len = 400, -- ignore lines longer than this max_line_len = 400, -- ignore lines longer than this
exclude = {}, -- list of file types to exclude highlighting exclude = {}, -- list of file types to exclude highlighting
}, },
-- list of named colors where we try to extract the guifg from the -- list of named colors where we try to extract the guifg from the
-- list of highlight groups or use the hex color if hl not found as a fallback -- list of highlight groups or use the hex color if hl not found as a fallback
@ -471,7 +500,7 @@ local config = {
info = { "DiagnosticInfo", "#2563EB" }, info = { "DiagnosticInfo", "#2563EB" },
hint = { "DiagnosticHint", "#10B981" }, hint = { "DiagnosticHint", "#10B981" },
default = { "Identifier", "#7C3AED" }, default = { "Identifier", "#7C3AED" },
test = { "Identifier", "#FF00FF" } test = { "Identifier", "#FF00FF" },
}, },
search = { search = {
command = "rg", command = "rg",
@ -503,7 +532,19 @@ local config = {
-- Code completion -- Code completion
{ {
"github/copilot.vim", "zbirenbaum/copilot.lua",
cmd = "Copilot",
event = "User AstroFile",
config = function()
require("copilot").setup {
suggestion = { enabled = false },
panel = { enabled = false },
}
end,
},
{
"zbirenbaum/copilot-cmp",
config = function() require("copilot_cmp").setup() end,
event = "User AstroFile", event = "User AstroFile",
}, },
@ -517,9 +558,7 @@ local config = {
-- Live server -- Live server
{ {
"aurum77/live-server.nvim", "aurum77/live-server.nvim",
run = function() run = function() require("live_server.util").install() end,
require"live_server.util".install()
end,
cmd = { "LiveServer", "LiveServerStart", "LiveServerStop" }, cmd = { "LiveServer", "LiveServerStart", "LiveServerStop" },
}, },