From f19ed9fcaa9c14c86919aa11376aaf20bf041c2a Mon Sep 17 00:00:00 2001 From: Stefan Winkler Date: Mon, 13 Oct 2025 23:53:20 +0200 Subject: [PATCH] Fix for #16412 (incomplete) Adds the necessary code to resolve the URI back to the ScmGroup. Missing: handling of PluginScmProvider Signed-off-by: Stefan Winkler --- packages/git/src/browser/git-scm-provider.ts | 15 +++++++++++++++ packages/scm/src/browser/scm-provider.ts | 9 ++++++++- packages/scm/src/browser/scm-tree-model.ts | 8 +++++++- packages/scm/src/browser/scm-tree-widget.tsx | 5 +++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/git/src/browser/git-scm-provider.ts b/packages/git/src/browser/git-scm-provider.ts index 41c5f6f3f8957..dc6ecfc5c5a60 100644 --- a/packages/git/src/browser/git-scm-provider.ts +++ b/packages/git/src/browser/git-scm-provider.ts @@ -144,6 +144,21 @@ export class GitScmProvider implements ScmProvider { get groups(): ScmResourceGroup[] { return this.state.groups; } + + /** + * Find the group that contains the given URI. + * @param uri The URI to find. + * @returns The resource group that contains the URI, or undefined if not found. + */ + getScmGroupIdForUri(uri: URI): string | undefined { + if (uri.query === 'HEAD') { + return 'workingTree'; + } else if (uri.query === 'index') { + return 'index'; + } + return undefined; + } + get stagedChanges(): GitFileChange[] { return this.state.stagedChanges; } diff --git a/packages/scm/src/browser/scm-provider.ts b/packages/scm/src/browser/scm-provider.ts index d513dcabb933b..1a0b9193bcb54 100644 --- a/packages/scm/src/browser/scm-provider.ts +++ b/packages/scm/src/browser/scm-provider.ts @@ -1,4 +1,4 @@ -// ***************************************************************************** +// ***************************************************************************// // Copyright (C) 2019 Red Hat, Inc. and others. // // This program and the accompanying materials are made available under the @@ -36,6 +36,13 @@ export interface ScmProvider extends Disposable { readonly onDidChangeCommitTemplate: Event; readonly amendSupport?: ScmAmendSupport; + + /** + * Returns the SCM resource group that contains the given URI, or undefined if not found. + * @param uri The URI to search for + * @returns The SCM resource group containing the URI, or undefined if not found + */ + readonly getScmGroupIdForUri?: (uri: URI) => string | undefined; } export const ScmResourceGroup = Symbol('ScmResourceGroup'); diff --git a/packages/scm/src/browser/scm-tree-model.ts b/packages/scm/src/browser/scm-tree-model.ts index 58ef770d57ced..0f5bfffcb4f1e 100644 --- a/packages/scm/src/browser/scm-tree-model.ts +++ b/packages/scm/src/browser/scm-tree-model.ts @@ -79,7 +79,6 @@ export namespace ScmFileChangeNode { @injectable() export abstract class ScmTreeModel extends TreeModelImpl { - private _languageId: string | undefined; protected provider: ScmProvider | undefined; @@ -389,6 +388,13 @@ export abstract class ScmTreeModel extends TreeModelImpl { return this.groups.find(g => g.id === groupId); } + getScmGroupIdForUri(uri: URI): string | undefined { + if (this.provider?.getScmGroupIdForUri) { + return this.provider?.getScmGroupIdForUri(uri); + } + return undefined; + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any override storeState(): any { return { diff --git a/packages/scm/src/browser/scm-tree-widget.tsx b/packages/scm/src/browser/scm-tree-widget.tsx index 46c39fe2382ce..d2cab2eff7cc7 100644 --- a/packages/scm/src/browser/scm-tree-widget.tsx +++ b/packages/scm/src/browser/scm-tree-widget.tsx @@ -361,7 +361,12 @@ export class ScmTreeWidget extends TreeWidget { } selectNodeByUri(uri: URI): void { + const groupId = this.model.getScmGroupIdForUri(uri); for (const group of this.model.groups) { + if (groupId && group.id !== groupId) { + continue; + } + const sourceUri = new URI(uri.path.toString()); const id = `${group.id}:${sourceUri.toString()}`; const node = this.model.getNode(id);