激活 Copilot 仅限一个目录

huangapple go评论83阅读模式
英文:

activate copilot for only one directory

问题

如果重要的话,我正在使用neovim。

我有一个目录/home/laurent/dev,其中包含我的开发文件。我希望Copilot仅在该目录(及其子目录)上激活。

原因是,在其他目录中,我有个人数据。我不想在个人数据上使用copilot。

准重复:https://stackoverflow.com/questions/72617988/can-you-make-github-copilot-opt-in-on-a-per-project-basis
这里我询问的是关于neovim而不是Visual Studio。

英文:

If it matters, I'm using neovim.

I have a directory /home/laurent/dev containing my development files. I want Copilot to be activated only on that directory (and its subdirectories).

The reason is that, in other directories, I have personal data. I don't want to use copilot on personal data.

quasi duplicate: https://stackoverflow.com/questions/72617988/can-you-make-github-copilot-opt-in-on-a-per-project-basis
Here I'm asking for neovim instead of visual studio.

答案1

得分: 1

我没有自动驾驶助手,所以你需要自己测试,但通常情况下,这是我如何在具有特定路径的缓冲区中自动运行命令。

在neovim中,你可以使用autocmd的lua版本。下面有两个示例。

一个是在你的~/dev/目录中运行:Copilot enable

-- 强制启用
vim.api.nvim_create_autocmd({ 'BufEnter' }, {
    pattern = '/home/laurent/dev/*',
    -- 你可以选择替换为
    -- pattern = vim.fn.expand('~') .. '/dev/*',
    command = "Copilot enable"
})

第二个是可选的,在含有你的机密信息的地方运行:Copilot disable

-- 强制禁用
vim.api.nvim_create_autocmd({ 'BufEnter' }, {
    pattern = '/home/laurent/private/*',
    command = "Copilot disable"
})

编辑:

在评论中,@Laurent提到了一个可以禁用每个缓冲区,然后启用~/dev/的解决方案。以下是相关代码:

-- 强制在所有地方禁用
vim.api.nvim_create_autocmd({ 'BufEnter' }, {
    pattern = '*',
    command = "Copilot disable"
})

-- 强制启用~/dev/*
vim.api.nvim_create_autocmd({ 'BufEnter' }, {
    pattern = vim.fn.expand('~') .. '/dev/*',
    command = "Copilot enable"
})

希望这对你有所帮助。

英文:

I don't have coopilot, so you need to test it for yourself, but in general this is how I'm auto running commands in buffers with specific path.

In neovim you can use lua version of autocmd. Bellow you have 2 of them.

One is to run :Copilot enable in your ~/dev/ directory.


    -- Force enable
    vim.api.nvim_create_autocmd({ 'BufEnter' }, {
        pattern = '/home/laurent/dev/*',
        -- you could optionaly replace with
        -- pattern = vim.fn.expand('~') .. '/dev/*',
        command = "Copilot enable"
    })

Second is optional. :Copilot disable in place with your secrets.


    -- Force disable
    vim.api.nvim_create_autocmd({ 'BufEnter' }, {
        pattern = '/home/laurent/private/*',
        command = "Copilot disable"
    })

edit:

@Laurent mentioned in the comment, a solution that will disable every buffer and then enable ~/dev/. Here is the code for it.


    -- Force disable everywhere
    vim.api.nvim_create_autocmd({ 'BufEnter' }, {
        pattern = '*',
        command = "Copilot disable"
    })
    
    -- Force enable ~/dev/*
    vim.api.nvim_create_autocmd({ 'BufEnter' }, {
        pattern = vim.fn.expand('~') .. '/dev/*',
        command = "Copilot enable"
    })

huangapple
  • 本文由 发表于 2023年4月4日 16:10:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75926959.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定