@@ -101,6 +101,7 @@ require('copilot').setup({
101
101
root_dir = function ()
102
102
return vim .fs .dirname (vim .fs .find (" .git" , { upward = true })[1 ])
103
103
end ,
104
+ should_attach = nil , -- type is fun(bufnr: integer, bufname: string): boolean
104
105
server_opts_overrides = {},
105
106
})
106
107
```
@@ -126,7 +127,6 @@ require("copilot.panel").refresh()
126
127
### suggestion
127
128
128
129
When ` auto_trigger ` is ` true ` , copilot starts suggesting as soon as you enter insert mode.
129
-
130
130
When ` auto_trigger ` is ` false ` , use the ` next ` , ` prev ` or ` accept ` keymap to trigger copilot suggestion.
131
131
132
132
To toggle auto trigger for the current buffer, use ` require("copilot.suggestion").toggle_auto_trigger() ` .
@@ -305,6 +305,26 @@ They can also be added runtime, using the command `:Copilot workspace add [folde
305
305
This allows changing the function that gets the root folder, the default looks for a parent folder that contains the folder ` .git ` .
306
306
If none is found, it will use the current working directory.
307
307
308
+ ### should_attach
309
+
310
+ This function is called to determine if copilot should attach to the buffer or not.
311
+ It is useful if you would like to go beyond the filetypes and have more control over when copilot should attach.
312
+ Since this happens before attaching to the buffer, it is good to prevent Copilot from reading sensitive files.
313
+
314
+ An example of this would be:
315
+
316
+ ``` lua
317
+ require (" copilot" ).setup {
318
+ should_attach = function (_ , bufname )
319
+ if string.match (bufname , " env" ) then
320
+ return false
321
+ end
322
+
323
+ return true
324
+ end
325
+ }
326
+ ```
327
+
308
328
## Commands
309
329
310
330
` copilot.lua ` defines the ` :Copilot ` command that can perform various actions. It has completion support, so try it out.
0 commit comments