Skip to content

Commit ce6bc9a

Browse files
author
Rachel Macfarlane
authored
Make PR viewlet always visible
1 parent 0bc5021 commit ce6bc9a

File tree

8 files changed

+126
-678
lines changed

8 files changed

+126
-678
lines changed

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,24 @@
147147
{
148148
"id": "pr:github",
149149
"name": "GitHub Pull Requests",
150-
"when": "!config.githubPullRequests.showInSCM && config.git.enabled && github:hasGitHubRemotes && workspaceFolderCount != 0"
150+
"when": "!config.githubPullRequests.showInSCM && config.git.enabled"
151151
},
152152
{
153153
"id": "prStatus:github",
154154
"name": "Changes In Pull Request",
155-
"when": "!config.githubPullRequests.showInSCM && config.git.enabled && github:hasGitHubRemotes && github:inReviewMode"
155+
"when": "!config.githubPullRequests.showInSCM && config.git.enabled && github:inReviewMode"
156156
}
157157
],
158158
"scm": [
159159
{
160160
"id": "pr:scm",
161161
"name": "GitHub Pull Requests",
162-
"when": "config.githubPullRequests.showInSCM && config.git.enabled && github:hasGitHubRemotes && workspaceFolderCount != 0"
162+
"when": "config.githubPullRequests.showInSCM && config.git.enabled"
163163
},
164164
{
165165
"id": "prStatus:scm",
166166
"name": "Changes In Pull Request",
167-
"when": "config.githubPullRequests.showInSCM && config.git.enabled && github:hasGitHubRemotes && github:inReviewMode"
167+
"when": "config.githubPullRequests.showInSCM && config.git.enabled && github:inReviewMode"
168168
}
169169
]
170170
},
@@ -325,6 +325,11 @@
325325
"command": "pr.signinAndRefreshList",
326326
"title": "Sign in and Refresh",
327327
"category": "GitHub Pull Requests"
328+
},
329+
{
330+
"command": "pr.configureRemotes",
331+
"title": "Configure Remotes...",
332+
"category": "GitHub Pull Requests"
328333
}
329334
],
330335
"menus": {

src/commands.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,13 @@ export function registerCommands(context: vscode.ExtensionContext, prManager: Pu
340340
}
341341
}));
342342

343+
context.subscriptions.push(vscode.commands.registerCommand('pr.configureRemotes', async () => {
344+
const { name, publisher } = require('../package.json') as { name: string, publisher: string };
345+
const extensionId = `${publisher}.${name}`;
346+
347+
return vscode.commands.executeCommand('workbench.action.openSettings', `@ext:${extensionId} remotes`);
348+
}));
349+
343350
context.subscriptions.push(vscode.commands.registerCommand('pr.replyComment', async (handler: CommentHandler, thread: vscode.CommentThread) => {
344351
telemetry.on('pr.replyComment');
345352
handler.createOrReplyComment(thread);

src/extension.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { handler as uriHandler } from './common/uri';
1818
import { ITelemetry } from './github/interface';
1919
import * as Keychain from './authentication/keychain';
2020
import { FileTypeDecorationProvider } from './view/fileTypeDecorationProvider';
21+
import { PullRequestsTreeDataProvider } from './view/prsTreeDataProvider';
2122
import { ApiImpl } from './api/api1';
2223
import { Repository } from './api/api';
2324

@@ -28,7 +29,7 @@ fetch.Promise = PolyfillPromise;
2829

2930
let telemetry: ITelemetry;
3031

31-
async function init(context: vscode.ExtensionContext, git: ApiImpl, repository: Repository): Promise<void> {
32+
async function init(context: vscode.ExtensionContext, git: ApiImpl, repository: Repository, tree: PullRequestsTreeDataProvider): Promise<void> {
3233
context.subscriptions.push(Logger);
3334
Logger.appendLine('Git repository found, initializing review manager and pr tree view.');
3435

@@ -41,6 +42,7 @@ async function init(context: vscode.ExtensionContext, git: ApiImpl, repository:
4142
if (repository) {
4243
repository.status();
4344
}
45+
await tree.refresh();
4446
} catch (e) {
4547
vscode.window.showErrorMessage(formatError(e));
4648
}
@@ -50,7 +52,8 @@ async function init(context: vscode.ExtensionContext, git: ApiImpl, repository:
5052
context.subscriptions.push(vscode.window.registerUriHandler(uriHandler));
5153
context.subscriptions.push(new FileTypeDecorationProvider());
5254
const prManager = new PullRequestManager(repository, telemetry);
53-
const reviewManager = new ReviewManager(context, Keychain.onDidChange, repository, prManager, telemetry);
55+
const reviewManager = new ReviewManager(context, repository, prManager, tree, telemetry);
56+
tree.initialize(prManager);
5457
registerCommands(context, prManager, reviewManager, telemetry);
5558

5659
git.repositories.forEach(repo => {
@@ -88,10 +91,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<ApiImp
8891
Logger.appendLine('Looking for git repository');
8992
const firstRepository = apiImpl.repositories[0];
9093

94+
const prTree = new PullRequestsTreeDataProvider(telemetry);
95+
9196
if (firstRepository) {
92-
await init(context, apiImpl, firstRepository);
97+
await init(context, apiImpl, firstRepository, prTree);
9398
} else {
94-
onceEvent(apiImpl.onDidOpenRepository)(r => init(context, apiImpl, r));
99+
onceEvent(apiImpl.onDidOpenRepository)(r => init(context, apiImpl, r, prTree));
95100
}
96101

97102
return apiImpl;

src/github/pullRequestManager.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export class BadUpstreamError extends Error {
8080
}
8181
}
8282

83-
const SETTINGS_NAMESPACE = 'githubPullRequests';
84-
const REMOTES_SETTING = 'remotes';
83+
export const SETTINGS_NAMESPACE = 'githubPullRequests';
84+
export const REMOTES_SETTING = 'remotes';
8585

8686
interface NewCommentPosition {
8787
path: string;
@@ -366,7 +366,6 @@ export class PullRequestManager {
366366
} else {
367367
await vscode.commands.executeCommand('setContext', 'github:hasGitHubRemotes', false);
368368
Logger.appendLine('No GitHub remotes found');
369-
return;
370369
}
371370

372371
let serverAuthPromises = [];

src/view/prsTreeDataProvider.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PRCategoryActionNode, CategoryTreeNode, PRCategoryActionType } from './
99
import { PRType, ITelemetry } from '../github/interface';
1010
import { fromFileChangeNodeUri } from '../common/uri';
1111
import { getInMemPRContentProvider } from './inMemPRContentProvider';
12-
import { PullRequestManager } from '../github/pullRequestManager';
12+
import { PullRequestManager, SETTINGS_NAMESPACE, REMOTES_SETTING } from '../github/pullRequestManager';
1313

1414
export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<TreeNode>, vscode.DecorationProvider, vscode.Disposable {
1515
private _onDidChangeTreeData = new vscode.EventEmitter<TreeNode>();
@@ -19,14 +19,14 @@ export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<Tre
1919
private _disposables: vscode.Disposable[];
2020
private _childrenDisposables: vscode.Disposable[];
2121
private _view: vscode.TreeView<TreeNode>;
22+
private _prManager: PullRequestManager;
23+
private _initialized: boolean = false;
2224

2325
get view(): vscode.TreeView<TreeNode> {
2426
return this._view;
2527
}
2628

2729
constructor(
28-
onShouldReload: vscode.Event<any>,
29-
private _prManager: PullRequestManager,
3030
private _telemetry: ITelemetry
3131
) {
3232
this._disposables = [];
@@ -48,12 +48,19 @@ export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<Tre
4848
});
4949

5050
this._disposables.push(this._view);
51-
this._disposables.push(onShouldReload(e => {
52-
this._onDidChangeTreeData.fire();
53-
}));
5451
this._childrenDisposables = [];
5552
}
5653

54+
initialize(prManager: PullRequestManager) {
55+
if (this._initialized) {
56+
throw new Error('Tree has already been initialized!');
57+
}
58+
59+
this._initialized = true;
60+
this._prManager = prManager;
61+
this.refresh();
62+
}
63+
5764
async refresh(node?: TreeNode) {
5865
return node ? this._onDidChangeTreeData.fire(node) : this._onDidChangeTreeData.fire();
5966
}
@@ -63,6 +70,26 @@ export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<Tre
6370
}
6471

6572
async getChildren(element?: TreeNode): Promise<TreeNode[]> {
73+
if (!this._prManager) {
74+
if (!vscode.workspace.workspaceFolders) {
75+
return Promise.resolve([new PRCategoryActionNode(this._view, PRCategoryActionType.NoOpenFolder)]);
76+
} else {
77+
return Promise.resolve([new PRCategoryActionNode(this._view, PRCategoryActionType.NoGitRepositories)]);
78+
}
79+
}
80+
81+
if (!this._prManager.getGitHubRemotes().length) {
82+
const remotesSetting = vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<string[]>(REMOTES_SETTING);
83+
if (remotesSetting) {
84+
return Promise.resolve([
85+
new PRCategoryActionNode(this._view, PRCategoryActionType.NoMatchingRemotes),
86+
new PRCategoryActionNode(this._view, PRCategoryActionType.ConfigureRemotes)
87+
]);
88+
}
89+
90+
return Promise.resolve([new PRCategoryActionNode(this._view, PRCategoryActionType.NoRemotes)]);
91+
}
92+
6693
if (!element) {
6794
if (this._childrenDisposables && this._childrenDisposables.length) {
6895
this._childrenDisposables.forEach(dispose => dispose.dispose());

src/view/reviewManager.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export class ReviewManager implements vscode.DecorationProvider {
4040
private _validateStatusInProgress?: Promise<void>;
4141
private _reviewDocumentCommentProvider: ReviewDocumentCommentProvider;
4242

43-
private _prsTreeDataProvider: PullRequestsTreeDataProvider;
4443
private _prFileChangesProvider: PullRequestChangesTreeDataProvider | undefined;
4544
private _statusBarItem: vscode.StatusBarItem;
4645
private _prNumber?: number;
@@ -64,9 +63,9 @@ export class ReviewManager implements vscode.DecorationProvider {
6463

6564
constructor(
6665
private _context: vscode.ExtensionContext,
67-
private _onShouldReload: vscode.Event<any>,
6866
private _repository: Repository,
6967
private _prManager: PullRequestManager,
68+
private _prsTreeDataProvider: PullRequestsTreeDataProvider,
7069
private _telemetry: ITelemetry
7170
) {
7271
this._switchingToReviewMode = false;
@@ -78,7 +77,6 @@ export class ReviewManager implements vscode.DecorationProvider {
7877
this.registerCommands();
7978
this.registerListeners();
8079

81-
this._prsTreeDataProvider = new PullRequestsTreeDataProvider(_onShouldReload, _prManager, this._telemetry);
8280
this._disposables.push(this._prsTreeDataProvider);
8381
this._disposables.push(vscode.window.registerDecorationProvider(this));
8482

@@ -155,7 +153,8 @@ export class ReviewManager implements vscode.DecorationProvider {
155153
}
156154

157155
this._prsTreeDataProvider.dispose();
158-
this._prsTreeDataProvider = new PullRequestsTreeDataProvider(this._onShouldReload, this._prManager, this._telemetry);
156+
this._prsTreeDataProvider = new PullRequestsTreeDataProvider(this._telemetry);
157+
this._prsTreeDataProvider.initialize(this._prManager);
159158
this._disposables.push(this._prsTreeDataProvider);
160159
}
161160
}));

src/view/treeNodes/categoryNode.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ export enum PRCategoryActionType {
1616
Empty,
1717
More,
1818
TryOtherRemotes,
19-
Login
19+
Login,
20+
NoRemotes,
21+
NoGitRepositories,
22+
NoOpenFolder,
23+
NoMatchingRemotes,
24+
ConfigureRemotes
2025
}
2126

2227
export class PRCategoryActionNode extends TreeNode implements vscode.TreeItem {
@@ -63,6 +68,26 @@ export class PRCategoryActionNode extends TreeNode implements vscode.TreeItem {
6368
arguments: []
6469
};
6570
break;
71+
case PRCategoryActionType.NoRemotes:
72+
this.label = 'No GitHub repositories found.';
73+
break;
74+
case PRCategoryActionType.NoGitRepositories:
75+
this.label = 'No git repositories found.';
76+
break;
77+
case PRCategoryActionType.NoOpenFolder:
78+
this.label = 'You have not yet opened a folder.';
79+
break;
80+
case PRCategoryActionType.NoMatchingRemotes:
81+
this.label = 'No remotes match the current setting.';
82+
break;
83+
case PRCategoryActionType.ConfigureRemotes:
84+
this.label = 'Configure remotes...';
85+
this.command = {
86+
title: 'Configure remotes',
87+
command: 'pr.configureRemotes',
88+
arguments: []
89+
};
90+
break;
6691
default:
6792
break;
6893
}

0 commit comments

Comments
 (0)