Skip to content
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
15 changes: 15 additions & 0 deletions packages/git/src/browser/git-scm-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion packages/scm/src/browser/scm-provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// *****************************************************************************
// ***************************************************************************//
// Copyright (C) 2019 Red Hat, Inc. and others.
//
// This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -36,6 +36,13 @@ export interface ScmProvider extends Disposable {
readonly onDidChangeCommitTemplate: Event<string>;

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');
Expand Down
8 changes: 7 additions & 1 deletion packages/scm/src/browser/scm-tree-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export namespace ScmFileChangeNode {

@injectable()
export abstract class ScmTreeModel extends TreeModelImpl {

private _languageId: string | undefined;

protected provider: ScmProvider | undefined;
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions packages/scm/src/browser/scm-tree-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading