Skip to content

Rewrite#402

Draft
xhayper wants to merge 11 commits intomainfrom
rewrite
Draft

Rewrite#402
xhayper wants to merge 11 commits intomainfrom
rewrite

Conversation

@xhayper
Copy link
Collaborator

@xhayper xhayper commented Nov 23, 2025

No description provided.

@xhayper xhayper self-assigned this Nov 23, 2025
@xhayper xhayper mentioned this pull request Nov 23, 2025
5 tasks
@xhayper xhayper added the enhancement New feature or request label Nov 23, 2025
Copy link
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
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
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
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 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
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
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
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
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
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
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
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

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