Skip to content

Rewrite#402

Draft
Khaomi wants to merge 11 commits intomainfrom
rewrite
Draft

Rewrite#402
Khaomi wants to merge 11 commits intomainfrom
rewrite

Conversation

@Khaomi
Copy link
Copy Markdown
Collaborator

@Khaomi Khaomi commented Nov 23, 2025

No description provided.

@Khaomi Khaomi self-assigned this Nov 23, 2025
@Khaomi Khaomi mentioned this pull request Nov 23, 2025
5 tasks
@Khaomi Khaomi added the enhancement New feature or request label Nov 23, 2025
Copy link
Copy Markdown
Contributor

@Mopsgamer Mopsgamer left a comment

Choose a reason for hiding this comment

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

I dislike these Provider and ProviderManager classes.

I think the rewrite should be more functional. Any file is a module, and any module can be used like a class.

And yes... you repeated the Git bug issue; looks like the bike is still being invented. Except now, I really don't know how to fix it with this pattern. This pattern actively makes our world a worse place. / hj

Comment on lines +1 to +7
import { TextEditor, window } from "vscode";
import { Provider } from "./provider";

export class TextEditorBasedProvider extends Provider {
protected get textEditor() {
return window.activeTextEditor;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TextEditor is unused.

Suggested change
import { TextEditor, window } from "vscode";
import { Provider } from "./provider";
export class TextEditorBasedProvider extends Provider {
protected get textEditor() {
return window.activeTextEditor;
}
import { type TextEditor, window } from "vscode";
import { Provider } from "./provider";
export class TextEditorBasedProvider extends Provider {
protected get textEditor(): TextEditor | undefined {
return window.activeTextEditor;
}

}

public override shouldSkip(): boolean {
return !!!this.textEditor;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return !!!this.textEditor;
return !this.textEditor;

}

public override shouldSkip(): boolean {
return !!!this.notebookEditor;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return !!!this.notebookEditor;
return !this.notebookEditor;

Comment thread src/providers/provider.ts
Comment on lines +8 to +42
export class Provider extends Base {
public activated = false;
private variables = new Map<string, () => Promise<string | undefined>>();

constructor(
extension: Extension,
public id = "base",
public priority = 0
) {
super(extension);
this.registerVariables();
}

public subscribe() {
return;
}

public shouldSkip(): boolean {
return true;
}

public hasVariable(name: string): boolean {
return this.variables.has(name);
}

public async resolveVariable(name: string): Promise<string | undefined> {
return this.variables.has(name) ? await this.variables.get(name)!() : undefined;
}

protected registerVariables() {}

protected async provide(name: string, value: () => Promise<string | undefined>) {
this.variables.set(name, value);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The abstract keyword exists and you should use it here (probably). But again, I really dislike the whole idea.

Comment on lines +1 to +7
import { Provider } from "./provider";
import { window } from "vscode";

export class NotebookBasedProvider extends Provider {
protected get notebookEditor() {
return window.activeNotebookEditor;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { Provider } from "./provider";
import { window } from "vscode";
export class NotebookBasedProvider extends Provider {
protected get notebookEditor() {
return window.activeNotebookEditor;
}
import { Provider } from "./provider";
import { type NotebookEditor, window } from "vscode";
export class NotebookBasedProvider extends Provider {
protected get notebookEditor(): NotebookEditor | undefined {
return window.activeNotebookEditor;
}


protected override onExtensionActivate(): void {
this.gitApi = extensions
.getExtension<GitExtension>("vscode.git")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like the Git bug made a comeback. Please call .activate(): Promise<GitExtension> and await it.

Actually, see #402 (comment).

);

if (Object.values(this.extensionState).some((x) => !x)) this.onExtensionDeactivate();
else this.onExtensionActivate();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You cannot use await for Git here though (async constructor).

Suggested change
else this.onExtensionActivate();
else await this.onExtensionActivate(); // useless suggestion


const isAnyInactive = filtered.some((x) => !x.isActive);
if (isAnyInactive) this.onExtensionDeactivate();
else this.onExtensionActivate();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
else this.onExtensionActivate();
await else this.onExtensionActivate();

Comment on lines +30 to +32
extensions.onDidChange(() => {
this.updateState();
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

updateState waits for the Git extension to load, which is incorrect because Git should be loaded only once. This is the Git bug for code placed after updateState.

Suggested change
extensions.onDidChange(() => {
this.updateState();
})
extensions.onDidChange(async () => {
await this.updateState();
})

Comment on lines +17 to +21
public addProvider(provider: Provider) {
this.providers.push(provider);
this.providers.sort((a, b) => a.priority - b.priority);
if (this.extension.activated) provider.subscribe();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It can be faster by using a proper insert function, this code reminds me of microsoft/vscode#272155.

@lajczi
Copy link
Copy Markdown

lajczi commented Jan 24, 2026

hey @xhayper can you continue this pr? tysm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add .ipynb support PSA : How to make sure the extension works (VS Code's SCM issue)

3 participants