Skip to content
Closed
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
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,27 @@
{
"category": "(neo) Git Graph",
"command": "neo-git-graph.view",
"title": "%command.view%"
"title": "%command.view%",
"icon": {
"light": "resources/webview-icon-light.svg",
"dark": "resources/webview-icon-dark.svg"
}
Comment thread
Chzxxuanzheng marked this conversation as resolved.
},
{
"category": "(neo) Git Graph",
"command": "neo-git-graph.clearAvatarCache",
"title": "%command.clearAvatarCache%"
}
],
"menus": {
"scm/title": [
{
"command": "neo-git-graph.view",
"group": "navigation",
"when": "scmProvider == git"
}
]
},
Comment on lines +80 to +100

@asispts asispts Apr 9, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This code alone can do the job without modifying/adding any other code. The existing command handler can handle the active/current repo state by itself.

So, you can remove the other changes. Any future issues will be solved independently.

@Chzxxuanzheng Chzxxuanzheng Apr 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only adding this code will result in it only open the last repo when face multi repo. I think if without the auto switch repo function, the PR will give a scm title button with bug.

You mean I should put it split into two PR, or you will solve this questions yourself?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yeah, I think we can split the PR. You can propose the fix for the multi-repo issue. But be aware that I'm preparing to release a new version. After releasing it, I'll be working on the initialization logic that may affect this issue.

"configuration": {
"type": "object",
"title": "%config.title%",
Expand Down
35 changes: 32 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from "vscode";

import { AvatarManager } from "./avatarManager";
import { gitClientFactory } from "./backend/gitClient";
import { buildExtensionUri } from "./backend/utils/path.util";
import { buildExtensionUri, getPathFromStr } from "./backend/utils/path.util";
import { config } from "./config";
import { DiffDocProvider } from "./diffDocProvider";
import { registerMessageHandlers } from "./extension/messageHandler";
Expand All @@ -28,6 +28,7 @@ export function activate(context: vscode.ExtensionContext) {
const repoSearch = createRepoSearch(repoManager, config);
const repoWatcher = createRepoWatcher(repoManager, config, repoSearch);
let currentPanel: WebviewPanel | undefined;
let currentBridge: WebviewBridge | undefined;

void (async () => {
repoManager.removeReposNotInWorkspace();
Expand All @@ -38,9 +39,34 @@ export function activate(context: vscode.ExtensionContext) {

context.subscriptions.push(
outputChannel,
vscode.commands.registerCommand("neo-git-graph.view", () => {
vscode.commands.registerCommand("neo-git-graph.view", (resource) => {
let repoPath: string | undefined;

if (resource && typeof resource === "object") {
if (typeof resource?.rootUri?.fsPath === "string") {
repoPath = getPathFromStr(resource.rootUri.fsPath);
} else if (typeof resource?.uri?.fsPath === "string") {
repoPath = getPathFromStr(resource.uri.fsPath);
}
}
Comment thread
Chzxxuanzheng marked this conversation as resolved.

Comment on lines +48 to +52

Copilot AI Apr 9, 2026

Copy link

Choose a reason for hiding this comment

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

repoPath is derived from resource.rootUri.fsPath / resource.uri.fsPath, but this codebase normalizes repo paths to forward slashes (see getPathFromUri/getPathFromStr). On Windows, using fsPath directly will leave backslashes and fail the repos[repoPath] lookup, so the SCM-title button won’t select the intended repo. Normalize the URI before comparing/using it (and consider the case where resource itself is a vscode.Uri).

Copilot uses AI. Check for mistakes.
const repos = repoManager.getRepos();

if (repoPath && !repos[repoPath]) repoPath = undefined;

const column = vscode.window.activeTextEditor?.viewColumn;
if (currentPanel) {
Comment thread
Chzxxuanzheng marked this conversation as resolved.
if (repoPath) {
gitClient.setRepo(repoPath);
extensionState.setLastActiveRepo(repoPath);
if (currentBridge) {
currentBridge.post({
command: "loadRepos",
repos: repos,
lastActiveRepo: repoPath
});
}
}
currentPanel.reveal(column);
return;
}
Expand All @@ -61,6 +87,7 @@ export function activate(context: vscode.ExtensionContext) {
if (panel.visible) bridge.post({ command: "refresh" });
});
bridge = webviewBridgeFactory(panel.webview, repoFileWatcher);
currentBridge = bridge;
avatarManager.registerBridge(bridge.post.bind(bridge));
const { onPanelShown } = registerMessageHandlers(bridge, {
config,
Expand All @@ -81,8 +108,10 @@ export function activate(context: vscode.ExtensionContext) {
repoManager,
onDispose: () => {
currentPanel = undefined;
currentBridge = undefined;
},
onPanelShown
onPanelShown,
initialRepo: repoPath
});
}),
vscode.commands.registerCommand("neo-git-graph.clearAvatarCache", () => {
Expand Down
8 changes: 7 additions & 1 deletion src/extension/webviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function createWebviewPanel(opts: {
repoManager: RepoManager;
onDispose: () => void;
onPanelShown: () => void;
initialRepo?: string;
}) {
const {
panel,
Expand All @@ -33,9 +34,14 @@ export function createWebviewPanel(opts: {
avatarManager,
repoManager,
onDispose,
onPanelShown
onPanelShown,
initialRepo
} = opts;

if (initialRepo) {
extensionState.setLastActiveRepo(initialRepo);
}

const disposables: vscode.Disposable[] = [];
let isGraphViewLoaded = false;
let isPanelVisible = true;
Expand Down
14 changes: 13 additions & 1 deletion src/webview/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,19 @@ class GitGraphView {

let repoPaths = Object.keys(repos),
changedRepo = false;
if (typeof repos[this.currentRepo] === "undefined") {

// Check if we need to update the current repo
if (
lastActiveRepo !== null &&
typeof repos[lastActiveRepo] !== "undefined" &&
lastActiveRepo !== this.currentRepo
) {
// Explicitly switching to a different repo
Comment thread
Chzxxuanzheng marked this conversation as resolved.
this.currentRepo = lastActiveRepo;
this.saveState();
changedRepo = true;
Comment thread
Chzxxuanzheng marked this conversation as resolved.
} else if (typeof repos[this.currentRepo] === "undefined") {
// Current repo no longer exists
this.currentRepo =
lastActiveRepo !== null && typeof repos[lastActiveRepo] !== "undefined"
? lastActiveRepo
Expand Down
Loading