Skip to content

Commit

Permalink
✨ disableInFiles option for autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj authored and pzaback committed Apr 22, 2024
1 parent 1cb0455 commit f05df63
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 9 deletions.
39 changes: 32 additions & 7 deletions core/autocomplete/completionProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Handlebars from "handlebars";
import ignore from "ignore";
import path from "path";
import { v4 as uuidv4 } from "uuid";
import { IDE, ILLM, Position, TabAutocompleteOptions } from "..";
import { RangeInFileWithContents } from "../commands/util";
Expand Down Expand Up @@ -367,13 +369,6 @@ export class CompletionProvider {
input: AutocompleteInput,
token: AbortSignal | undefined,
): Promise<AutocompleteOutcome | undefined> {
// Create abort signal if not given
if (!token) {
const controller = new AbortController();
token = controller.signal;
this._abortControllers.set(input.completionId, controller);
}

try {
// Debounce
const uuid = uuidv4();
Expand All @@ -385,6 +380,36 @@ export class CompletionProvider {
...config.tabAutocompleteOptions,
};

// Check whether autocomplete is disabled for this file
if (options.disableInFiles) {
// Relative path needed for `ignore`
const workspaceDirs = await this.ide.getWorkspaceDirs();
let filepath = input.filepath;
for (const workspaceDir of workspaceDirs) {
if (filepath.startsWith(workspaceDir)) {
filepath = path.relative(workspaceDir, filepath);
break;
}
}

// Worst case we can check filetype glob patterns
if (filepath === input.filepath) {
filepath = getBasename(filepath);
}

const pattern = ignore().add(options.disableInFiles);
if (pattern.ignores(filepath)) {
return undefined;
}
}

// Create abort signal if not given
if (!token) {
const controller = new AbortController();
token = controller.signal;
this._abortControllers.set(input.completionId, controller);
}

// Allow disabling autocomplete from config.json
if (options.disable) {
return undefined;
Expand Down
5 changes: 3 additions & 2 deletions core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ export type ModelName =
| "claude-3-haiku-20240307"
| "claude-2.1"
// Cohere
|"command-r"
|"command-r-plus"
| "command-r"
| "command-r-plus"
// Gemini
| "gemini-pro"
| "gemini-1.5-pro-latest"
Expand Down Expand Up @@ -677,6 +677,7 @@ export interface TabAutocompleteOptions {
useCache: boolean;
onlyMyCode: boolean;
useOtherFiles: boolean;
disableInFiles?: string[];
}

export interface ContinueUIConfig {
Expand Down
1 change: 1 addition & 0 deletions core/util/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const DEFAULT_AUTOCOMPLETE_OPTS: TabAutocompleteOptions = {
useCache: true,
onlyMyCode: true,
useOtherFiles: false,
disableInFiles: undefined,
};

export const RETRIEVAL_PARAMS = {
Expand Down
4 changes: 4 additions & 0 deletions docs/static/schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,10 @@
"useOtherFiles": {
"type": "boolean",
"description": "Defaults to true. If set to false, Continue will not attempt to include snippets from other files."
},
"disableInFiles": {
"type": "boolean",
"description": "A list of files / glob patterns in which to disable tab autocomplete. For example, *.csv if you'd like to disable autocomplete in .csv files."
}
},
"required": []
Expand Down
4 changes: 4 additions & 0 deletions extensions/intellij/src/main/resources/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,10 @@
"useOtherFiles": {
"type": "boolean",
"description": "Defaults to true. If set to false, Continue will not attempt to include snippets from other files."
},
"disableInFiles": {
"type": "boolean",
"description": "A list of files / glob patterns in which to disable tab autocomplete. For example, *.csv if you'd like to disable autocomplete in .csv files."
}
},
"required": []
Expand Down
7 changes: 7 additions & 0 deletions extensions/vscode/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,13 @@
"useOtherFiles": {
"type": "boolean",
"description": "Defaults to true. If set to false, Continue will not attempt to include snippets from other files."
},
"disableInFiles": {
"description": "A list of files / glob patterns in which to disable tab autocomplete. For example, *.csv if you'd like to disable autocomplete in .csv files.",
"type": "array",
"items": {
"type": "string"
}
}
},
"required": []
Expand Down
4 changes: 4 additions & 0 deletions extensions/vscode/continue_rc_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,10 @@
"useOtherFiles": {
"type": "boolean",
"description": "Defaults to true. If set to false, Continue will not attempt to include snippets from other files."
},
"disableInFiles": {
"type": "boolean",
"description": "A list of files / glob patterns in which to disable tab autocomplete. For example, *.csv if you'd like to disable autocomplete in .csv files."
}
},
"required": []
Expand Down

0 comments on commit f05df63

Please sign in to comment.