Skip to content

Feature Request: Disabled by Default? #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
0x4D5352 opened this issue Jul 24, 2024 · 8 comments
Open

Feature Request: Disabled by Default? #302

0x4D5352 opened this issue Jul 24, 2024 · 8 comments

Comments

@0x4D5352
Copy link

I'm using copilot.lua and copilot-cmp.lua and find the workflow great, but prefer to start my sessions with copilot disabled, then enable it when desired/needed. Could there be an option added to change the initialized state from enabled to disabled?

@nounder
Copy link

nounder commented Jul 28, 2024

Try:

return {
  {
    "zbirenbaum/copilot.lua",
    opts = {
      filetypes = {
        ["."] = false,
        go = true
      },
    },
  },
}

@0x4D5352
Copy link
Author

0x4D5352 commented Aug 5, 2024

Unfortunately, does not seem to change the behavior @nounderline.

@oyarsa
Copy link

oyarsa commented Oct 4, 2024

+1 to this. I expected the enabled option in setup to do this, but it doesn't and if I turn off all filetypes with ["*"] = false, I can't manually enable it with Copilot enable. I get [Copilot] 'filetype' python rejected by config filetypes[*].

I can enable it using Copilot! attach, but I don't know if always using that command is a good idea.

@StitiFatah
Copy link

StitiFatah commented Oct 12, 2024

I agree that an option like that is needed, copilot is for many people something that should be opt in and not opt out, using Copilot! attach is problematic because you might want to use it for a session or whatever and not want to have to do it for each buffer.

A workaround is just to have vim.cmd 'Copilot diable' in init.lua, which i do, but it unnecessarily loads the plugin.

@dj95
Copy link

dj95 commented Nov 29, 2024

+1

It would be great to have a way for disabling copilot by default. I share my neovim between different devices with and without copilot access. Thus it pops up on every completion request to login to copilot, which initially let me drop the plugin.


Edit found the issue on my side. cmp-copilot started copilot in the background, even if I did not source/setup cmp.

For loading it only on certain devices, I wrote the following code to just include the my config module based on the hostname.

local function get_hostname()
    local f = io.popen ("/bin/hostname")
    local hostname = f:read("*a") or ""
    f:close()
    hostname =string.gsub(hostname, "\n$", "")
    return hostname
end

if get_hostname() == "HOSTNAME_WITH_COPILOT" then
    require "config.general.copilot"
end

@tom-gora
Copy link

tom-gora commented Mar 9, 2025

see my setup that is losely based on what I used to have with supermaven and since then moved (can't get supermaven to work as source for blink)

plugin via plugins/copilot.lua

M = {
	"zbirenbaum/copilot.lua",
	cmd = "Copilot",
	event = "InsertEnter",
	config = function()
		-- only setup if global state control value is set ( and it's not by default )
		-- just an extra ensure check as setup is meant to only be called by toggling func
		local is_off = vim.g.copilot_enabled
		if not is_off then
			-- setup own false augroup to prevent inbuilt teardown from erroring out due to lack
			-- of internally set up augroup
			-- (setup's not been called yet. We are killing it right away in the womb xd)
			vim.api.nvim_create_augroup("copilot.client", { clear = true })
			-- wrap things down forcefully using inbuilt client function
			require("copilot.client").teardown()
		else
			local copilot = require("copilot")
			copilot.setup({
				suggestions = { enabled = false },
				panel = { enabled = false },
			})
		end
	end,
}
return M

setup toggling command in my user_commands.lua

-- custom toggle for AI
local toggleCopilot = function()
	local copilot = require("copilot")
	local client = require("copilot.client")
	-- toggle global variable for stop condition
	-- first toggle sets the none existing variable to true
	vim.g.copilot_enabled = not vim.g.copilot_enabled
	-- stop or start copilot
	local noti = require("notify")
	local noti_opts = { title = "Copilot", icon = "", timeout = 1000, hide_from_history = true }
	if vim.g.copilot_enabled then
		-- spin up lsp from scratch ang get client setup and attached
		copilot.setup()
		client.setup()
		noti("ON", "info", noti_opts)
	else
		-- detatch first to prevent lsp spamming it's own notifications when teardown is called
		client.buf_detach()
		-- destroy microsoft XD
		client.teardown()
		noti("OFF", "error", noti_opts)
	end
end

	api.nvim_create_user_command("ToggleCopilot", toggleCopilot, { range = false })

then we just set up a binding as we need

local map = vim.keymap.set
-- AI
map("n", "<leader>S", "<cmd>ToggleCopilot<cr>", { desc = " Toggle Copilot" })

@AntoineGS
Copy link
Collaborator

Is the goal to simply not have the suggestions?
If so you can use the auto_trigger config to achieve this.
When set to false it will not attach to the buffer, and you can then execute :Copilot suggestion toggle_auto_trigger to toggle it on and use it, then toggle it back to deactivate it. I believe the toggle is on a per_buffer basis though.

If you are looking to minimize the startup time then I could submit a PR with the option to have it 'enabled manually only', as right now it is enabled upon loading. Though @zbirenbaum might lose it if I create yet another PR 😂😭

@samyakbardiya
Copy link

This setup of mine works fine with LazyVim.

lua/config/options.lua:

vim.g.copilot_enabled = false -- sets the default

lua/plugins/copilot.lua:

return {
    "zbirenbaum/copilot.lua",
    cmd = "Copilot",
    build = ":Copilot auth",
    config = function()
        Snacks.toggle({
            name = "Github Copilot",
            get = function()
                if not vim.g.copilot_enabled then -- HACK: since it's disabled by default the below will throw error
                    return false
                end
                return not require("copilot.client").is_disabled()
            end,
            set = function(state)
                if state then
                    require("copilot").setup() -- setting up for the very first time
                    require("copilot.command").enable()
                    vim.g.copilot_enabled = true
                else
                    require("copilot.command").disable()
                    vim.g.copilot_enabled = false
                end
            end,
        }):map("<leader>ux")
    end,
}

KyleKing added a commit to KyleKing/nvim that referenced this issue Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants