Skip to content

Commit 0f74cc3

Browse files
authored
Polish TreeItem description === true (#3284)
Fixes #3283
1 parent ceb7116 commit 0f74cc3

File tree

4 files changed

+32
-23
lines changed

4 files changed

+32
-23
lines changed

src/common/uri.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as pathUtils from 'path';
99
import * as vscode from 'vscode';
1010
import { Repository } from '../api/api';
1111
import { PullRequestModel } from '../github/pullRequestModel';
12+
import { FILECHANGE_FILE_SCHEME } from '../view/compareChangesTreeDataProvider';
1213
import { GitChangeType } from './file';
1314
import { TemporaryState } from './temporaryState';
1415

@@ -130,7 +131,7 @@ export function toResourceUri(uri: vscode.Uri, prNumber: number, fileName: strin
130131
};
131132

132133
return uri.with({
133-
scheme: 'filechange',
134+
scheme: FILECHANGE_FILE_SCHEME,
134135
query: JSON.stringify(params),
135136
});
136137
}

src/view/compareChangesTreeDataProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { GitHubFileChangeNode } from './treeNodes/fileChangeNode';
1616
import { TreeNode } from './treeNodes/treeNode';
1717

1818
export const GITHUB_FILE_SCHEME = 'githubpr';
19+
export const FILECHANGE_FILE_SCHEME = 'filechange';
1920

2021
export class CompareChangesTreeProvider implements vscode.TreeDataProvider<TreeNode> {
2122
private _view: vscode.TreeView<TreeNode>;

src/view/fileTypeDecorationProvider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import * as vscode from 'vscode';
77
import { GitChangeType } from '../common/file';
88
import { fromFileChangeNodeUri, fromPRUri } from '../common/uri';
9-
import { GITHUB_FILE_SCHEME } from './compareChangesTreeDataProvider';
109

1110
export class FileTypeDecorationProvider implements vscode.FileDecorationProvider {
1211
private _disposables: vscode.Disposable[];
@@ -20,7 +19,7 @@ export class FileTypeDecorationProvider implements vscode.FileDecorationProvider
2019
uri: vscode.Uri,
2120
_token: vscode.CancellationToken,
2221
): vscode.ProviderResult<vscode.FileDecoration> {
23-
if (uri.scheme !== 'filechange' && uri.scheme !== GITHUB_FILE_SCHEME) {
22+
if (!uri.query) {
2423
return;
2524
}
2625

src/view/treeNodes/fileChangeNode.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { asImageDataURI, EMPTY_IMAGE_URI, fromReviewUri, ReviewUriParams, toReso
1414
import { groupBy } from '../../common/utils';
1515
import { FolderRepositoryManager, SETTINGS_NAMESPACE } from '../../github/folderRepositoryManager';
1616
import { IResolvedPullRequestModel, PullRequestModel } from '../../github/pullRequestModel';
17-
import { GITHUB_FILE_SCHEME } from '../compareChangesTreeDataProvider';
17+
import { FILECHANGE_FILE_SCHEME, GITHUB_FILE_SCHEME } from '../compareChangesTreeDataProvider';
1818
import { FileViewedDecorationProvider } from '../fileViewedDecorationProvider';
1919
import { DecorationProvider } from '../treeDecorationProvider';
2020
import { TreeNode, TreeNodeParent } from './treeNode';
@@ -75,7 +75,7 @@ export class RemoteFileChangeNode extends TreeNode implements vscode.TreeItem {
7575
| { light: string | vscode.Uri; dark: string | vscode.Uri }
7676
| vscode.ThemeIcon;
7777
public command: vscode.Command;
78-
public resourceUri: vscode.Uri;
78+
public fileChangeResourceUri: vscode.Uri;
7979
public contextValue: string;
8080
public childrenDisposables: vscode.Disposable[] = [];
8181
private _viewed: ViewedState;
@@ -92,15 +92,15 @@ export class RemoteFileChangeNode extends TreeNode implements vscode.TreeItem {
9292
) {
9393
super();
9494
const viewed = this.pullRequest.fileChangeViewedState[fileName] ?? ViewedState.UNVIEWED;
95-
this.contextValue = `filechange:${GitChangeType[status]}:${viewed === ViewedState.VIEWED ? 'viewed' : 'unviewed'
95+
this.contextValue = `${FILECHANGE_FILE_SCHEME}:${GitChangeType[status]}:${viewed === ViewedState.VIEWED ? 'viewed' : 'unviewed'
9696
}`;
9797
this.label = path.basename(fileName);
9898
this.description = vscode.workspace.asRelativePath(path.dirname(fileName), false);
9999
if (this.description === '.') {
100100
this.description = '';
101101
}
102102
this.iconPath = vscode.ThemeIcon.File;
103-
this.resourceUri = toResourceUri(vscode.Uri.parse(this.blobUrl), pullRequest.number, fileName, status);
103+
this.fileChangeResourceUri = toResourceUri(vscode.Uri.parse(this.blobUrl), pullRequest.number, fileName, status);
104104
this.updateViewed(viewed);
105105
this.command = {
106106
command: 'pr.openFileOnGitHub',
@@ -120,16 +120,20 @@ export class RemoteFileChangeNode extends TreeNode implements vscode.TreeItem {
120120
this.accessibilityInformation = { label: `View diffs and comments for file ${this.label}`, role: 'link' };
121121
}
122122

123+
get resourceUri(): vscode.Uri {
124+
return this.filePath.with({ query: this.fileChangeResourceUri.query });
125+
}
126+
123127
updateViewed(viewed: ViewedState) {
124128
if (this._viewed === viewed) {
125129
return;
126130
}
127131

128132
this._viewed = viewed;
129-
this.contextValue = `filechange:${GitChangeType[this.status]}:${viewed === ViewedState.VIEWED ? 'viewed' : 'unviewed'
133+
this.contextValue = `${FILECHANGE_FILE_SCHEME}:${GitChangeType[this.status]}:${viewed === ViewedState.VIEWED ? 'viewed' : 'unviewed'
130134
}`;
131135
FileViewedDecorationProvider.updateFileViewedState(
132-
this.resourceUri,
136+
this.fileChangeResourceUri,
133137
this.pullRequest.number,
134138
this.fileName,
135139
viewed,
@@ -150,7 +154,7 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
150154
| vscode.Uri
151155
| { light: string | vscode.Uri; dark: string | vscode.Uri }
152156
| vscode.ThemeIcon;
153-
public resourceUri: vscode.Uri;
157+
public fileChangeResourceUri: vscode.Uri;
154158
public parentSha: string;
155159
public contextValue: string;
156160
public command: vscode.Command;
@@ -199,15 +203,15 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
199203
) {
200204
super();
201205
const viewed = this.pullRequest.fileChangeViewedState[this.fileName] ?? ViewedState.UNVIEWED;
202-
this.contextValue = `filechange:${GitChangeType[this.status]}:${viewed === ViewedState.VIEWED ? 'viewed' : 'unviewed'
206+
this.contextValue = `${FILECHANGE_FILE_SCHEME}:${GitChangeType[this.status]}:${viewed === ViewedState.VIEWED ? 'viewed' : 'unviewed'
203207
}`;
204208
this.label = path.basename(this.fileName);
205209
this.iconPath = vscode.ThemeIcon.File;
206210
this.opts = {
207211
preserveFocus: true,
208212
};
209213
this.updateShowOptions();
210-
this.resourceUri = toResourceUri(
214+
this.fileChangeResourceUri = toResourceUri(
211215
vscode.Uri.file(this.fileName),
212216
this.pullRequest.number,
213217
this.fileName,
@@ -246,14 +250,14 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
246250
this.accessibilityInformation = { label: `View diffs and comments for file ${this.label}`, role: 'link' };
247251
}
248252

249-
get description(): string {
253+
get resourceUri(): vscode.Uri {
254+
return this.filePath.with({ query: this.fileChangeResourceUri.query });
255+
}
256+
257+
get description(): string | true {
250258
const layout = vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<string>(FILE_LIST_LAYOUT);
251259
if (layout === 'flat') {
252-
let description = vscode.workspace.asRelativePath(path.dirname(this.fileName), false);
253-
if (description === '.') {
254-
description = '';
255-
}
256-
return description;
260+
return true;
257261
} else {
258262
return '';
259263
}
@@ -265,10 +269,10 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
265269
}
266270

267271
this._viewed = viewed;
268-
this.contextValue = `filechange:${GitChangeType[this.status]}:${viewed === ViewedState.VIEWED ? 'viewed' : 'unviewed'
272+
this.contextValue = `${FILECHANGE_FILE_SCHEME}:${GitChangeType[this.status]}:${viewed === ViewedState.VIEWED ? 'viewed' : 'unviewed'
269273
}`;
270274
FileViewedDecorationProvider.updateFileViewedState(
271-
this.resourceUri,
275+
this.fileChangeResourceUri,
272276
this.pullRequest.number,
273277
this.fileName,
274278
viewed,
@@ -281,7 +285,7 @@ export class FileChangeNode extends TreeNode implements vscode.TreeItem {
281285
const reviewThreadsForNode = (reviewThreadsByFile[this.fileName] || []).filter(thread => !thread.isOutdated);
282286

283287
DecorationProvider.updateFileComments(
284-
this.resourceUri,
288+
this.fileChangeResourceUri,
285289
this.pullRequest.number,
286290
this.fileName,
287291
reviewThreadsForNode.length > 0,
@@ -484,7 +488,7 @@ export class GitFileChangeNode extends FileChangeNode implements vscode.TreeItem
484488
export class GitHubFileChangeNode extends TreeNode implements vscode.TreeItem {
485489
public description: string;
486490
public iconPath: vscode.ThemeIcon;
487-
public resourceUri: vscode.Uri;
491+
public fileChangeResourceUri: vscode.Uri;
488492

489493
public command: vscode.Command;
490494

@@ -499,7 +503,7 @@ export class GitHubFileChangeNode extends TreeNode implements vscode.TreeItem {
499503
super();
500504
this.label = fileName;
501505
this.iconPath = vscode.ThemeIcon.File;
502-
this.resourceUri = vscode.Uri.file(fileName).with({
506+
this.fileChangeResourceUri = vscode.Uri.file(fileName).with({
503507
scheme: GITHUB_FILE_SCHEME,
504508
query: JSON.stringify({ status, fileName }),
505509
});
@@ -542,6 +546,10 @@ export class GitHubFileChangeNode extends TreeNode implements vscode.TreeItem {
542546
};
543547
}
544548

549+
get resourceUri(): vscode.Uri {
550+
return vscode.Uri.file(this.fileName).with({ query: this.fileChangeResourceUri.query });
551+
}
552+
545553
getTreeItem() {
546554
return this;
547555
}

0 commit comments

Comments
 (0)