Skip to content

Commit 7c8fe8f

Browse files
committed
Continuing cleanup work
* Merging error and end events for stream * No longer sending an empty string as item label for info * Removing "git" prefix from many variables
1 parent 4e5bdf7 commit 7c8fe8f

File tree

10 files changed

+240
-190
lines changed

10 files changed

+240
-190
lines changed

package-lock.json

Lines changed: 61 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
"test": "node ./node_modules/vscode/bin/test"
3434
},
3535
"dependencies": {
36-
"moment": "^2.20.1",
36+
"moment": "^2.21.0",
3737
"valid-url": "^1.0.9"
3838
},
3939
"devDependencies": {
4040
"@types/mocha": "^2.2.48",
4141
"@types/node": "^9.4.6",
4242
"mocha": "^5.0.1",
43-
"nock": "^9.1.6",
44-
"typescript": "^2.7.1",
43+
"nock": "^9.2.3",
44+
"typescript": "^2.7.2",
4545
"vscode": "^1.1.10"
4646
},
4747
"homepage": "https://github.com/Sertion/vscode-gitblame/blob/master/README.md",

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export const TITLE_SHOW_LOG = 'Show Log';
88
export const FS_EVENT_TYPE_REMOVE = 'rename';
99
export const FS_EVENT_TYPE_CHANGE = 'change';
1010

11-
export const TIME_CACHE_LIFETIME = 4 * 60 * 1000;
11+
export const TIME_CACHE_LIFETIME = 240_000;

src/git/blame.ts

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isWebUri } from 'valid-url';
22

3-
import { Disposable, commands, window, workspace, Uri } from 'vscode';
3+
import { Disposable, commands, window, workspace, Uri, MessageItem } from 'vscode';
44

55
import { ErrorHandler } from '../util/errorhandler';
66
import { TextDecorator } from '../util/textdecorator';
@@ -97,7 +97,6 @@ export class GitBlame {
9797

9898
async showMessage(): Promise<void> {
9999
const commitInfo = await this.getCommitInfo();
100-
const commitToolUrl = this.getToolUrl(commitInfo);
101100
const messageFormat = Property.get(Properties.InfoMessageFormat);
102101
const normalizedTokens = TextDecorator.normalizeCommitInfoTokens(
103102
commitInfo
@@ -106,17 +105,34 @@ export class GitBlame {
106105
messageFormat,
107106
normalizedTokens
108107
);
109-
const extraAction = commitToolUrl ? TITLE_VIEW_ONLINE : '';
108+
const extraActions = this.generateMessageActions(commitInfo);
110109

111110
this.updateView(commitInfo);
112111

113-
const item = await window.showInformationMessage(message, extraAction);
112+
const actionedItem = await window.showInformationMessage(message, ...extraActions);
114113

115-
if (item === TITLE_VIEW_ONLINE) {
116-
commands.executeCommand('vscode.open', commitToolUrl);
114+
if (actionedItem) {
115+
actionedItem.takeAction();
117116
}
118117
}
119118

119+
private generateMessageActions(commitInfo: GitCommitInfo): ActionableMessageItem[] {
120+
const commitToolUrl = this.getToolUrl(commitInfo);
121+
const extraActions:ActionableMessageItem[] = [];
122+
123+
if (commitToolUrl) {
124+
let viewOnlineAction = new ActionableMessageItem(TITLE_VIEW_ONLINE);
125+
126+
viewOnlineAction.setAction(() => {
127+
commands.executeCommand('vscode.open', commitToolUrl);
128+
});
129+
130+
extraActions.push(viewOnlineAction);
131+
}
132+
133+
return extraActions;
134+
}
135+
120136
async blameLink(): Promise<void> {
121137
const commitInfo = await this.getCommitInfo();
122138
const commitToolUrl = this.getToolUrl(commitInfo);
@@ -256,3 +272,25 @@ export class GitBlame {
256272
return hash.substr(0, Property.get(Properties.InternalHashLength));
257273
}
258274
}
275+
276+
/**
277+
* Helper class for window.showInformationMessage
278+
*/
279+
class ActionableMessageItem implements MessageItem {
280+
public title: string;
281+
private action: () => void;
282+
283+
constructor(title) {
284+
this.title = title;
285+
}
286+
287+
setAction(action) {
288+
this.action = action;
289+
}
290+
291+
takeAction() {
292+
if (this.action) {
293+
this.action();
294+
}
295+
}
296+
}

0 commit comments

Comments
 (0)