Skip to content

assistant: fix copilot inline completions for ipynb #8498

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions extensions/positron-assistant/src/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class OpenAILegacyCompletion extends CompletionModel {
token: vscode.CancellationToken
): Promise<vscode.InlineCompletionItem[] | vscode.InlineCompletionList> {
// Check if the file should be excluded from AI features
if (await positron.ai.areCompletionsEnabled(document.uri)) {
if (!await positron.ai.areCompletionsEnabled(document.uri)) {
return [];
}

Expand Down Expand Up @@ -386,7 +386,7 @@ abstract class FimPromptCompletion extends CompletionModel {
token: vscode.CancellationToken
): Promise<vscode.InlineCompletionItem[] | vscode.InlineCompletionList> {
// Check if the file should be excluded from AI features
if (await positron.ai.areCompletionsEnabled(document.uri)) {
if (!await positron.ai.areCompletionsEnabled(document.uri)) {
return [];
}

Expand Down Expand Up @@ -649,7 +649,7 @@ export class CopilotCompletion implements vscode.InlineCompletionItemProvider {
token: vscode.CancellationToken
): Promise<vscode.InlineCompletionItem[] | vscode.InlineCompletionList | undefined> {
// Check if the file should be excluded from AI features
if (await positron.ai.areCompletionsEnabled(document.uri)) {
if (!await positron.ai.areCompletionsEnabled(document.uri)) {
return [];
}
return await this._copilotService.inlineCompletion(document, position, context, token);
Expand Down
8 changes: 4 additions & 4 deletions src/positron-dts/positron.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2120,10 +2120,10 @@ declare module 'positron' {
}

/**
* Checks the file for exclusion from AI completion.
* @param file The file to check for exclusion.
* @returns A Thenable that resolves to true if the file should be excluded, false otherwise.
* Checks if completions are enabled for the given file.
* @param uri The file URI to check if completions are enabled.
* @returns A Thenable that resolves to true if completions should be enabled for the file, false otherwise.
*/
export function areCompletionsEnabled(file: vscode.Uri): Thenable<boolean>;
export function areCompletionsEnabled(uri: vscode.Uri): Thenable<boolean>;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class MainThreadAiFeatures extends Disposable implements MainThreadAiFeat
}

/**
* Check if a file should be excluded from AI completions based on configuration settings.
* Check if a file should be enabled for AI completions based on configuration settings.
*/
async $areCompletionsEnabled(file: UriComponents): Promise<boolean> {
const uri = URI.revive(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,17 @@ export class PositronAssistantService extends Disposable implements IPositronAss
const globPattern = this._configurationService.getValue<string[]>('positron.assistant.inlineCompletionExcludes');

if (!globPattern || globPattern.length === 0) {
return false; // No glob patterns configured, so no files are excluded
return true; // No glob patterns configured, so completions are enabled
}

// Check all of the glob patterns and return true if any match
// Check all of the glob patterns and return false if any match
for (const pattern of globPattern) {
if (glob.match(pattern, uri.path)) {
return true; // File matches an exclusion pattern
return false; // File matches an exclusion pattern, so it is excluded from completions
}
}

return false; // No patterns matched, so the file is not excluded
return true; // No patterns matched, so completions are enabled
Comment on lines +220 to +230
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I saw the name of the function areCompletionsEnabled, I expected the function to return true when no globs are provided or matched, but this was returning the opposite.

I inverted the logic here so that the returned value aligns with the function name. Somehow, this seems to resolve the issue with ipynb?? 🧐

}

//#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ export interface IPositronAssistantService {
removeLanguageModelConfig(source: IPositronLanguageModelSource): void;

/**
* Check if a file should be excluded from AI completions.
* @param uri The URI of the file to check.
* @returns True if the file should be excluded from the Positron Assistant, false otherwise.
* Checks if completions are enabled for the given file.
* @param uri The file URI to check if completions are enabled.
* @returns true if completions should be enabled for the file, false otherwise.
*/
areCompletionsEnabled(uri: URI): boolean;

Expand Down