Skip to content

Commit ea33560

Browse files
author
Eric Amodio
committed
Removes hard dependency on donjayamanne.githistory
Provides optional additional code lens
1 parent 70cc92d commit ea33560

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
"typescript": "^1.8.10",
4242
"vscode": "^0.11.17"
4343
},
44-
"extensionDependencies": [
45-
"donjayamanne.githistory"
46-
],
4744
"scripts": {
4845
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
4946
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict'
22

3-
export type WorkspaceState = 'repoPath';
3+
export type WorkspaceState = 'hasGitHistoryExtension' | 'repoPath';
44
export const WorkspaceState = {
5+
HasGitHistoryExtension: 'hasGitHistoryExtension' as WorkspaceState,
56
RepoPath: 'repoPath' as WorkspaceState
67
}
78

src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import {CodeLens, DocumentSelector, ExtensionContext, languages, workspace} from 'vscode';
2+
import {CodeLens, DocumentSelector, ExtensionContext, extensions, languages, workspace} from 'vscode';
33
import GitCodeLensProvider from './gitCodeLensProvider';
44
import GitBlameCodeLensProvider from './gitBlameCodeLensProvider';
55
import GitBlameContentProvider from './gitBlameContentProvider';
@@ -23,6 +23,7 @@ export function activate(context: ExtensionContext) {
2323

2424
git.getRepoPath(workspace.rootPath).then(repoPath => {
2525
context.workspaceState.update(WorkspaceState.RepoPath, repoPath);
26+
context.workspaceState.update(WorkspaceState.HasGitHistoryExtension, extensions.getExtension('donjayamanne.githistory') !== undefined);
2627

2728
context.subscriptions.push(workspace.registerTextDocumentContentProvider(GitBlameContentProvider.scheme, new GitBlameContentProvider(context, git)));
2829
context.subscriptions.push(languages.registerCodeLensProvider(GitCodeLensProvider.selector, new GitCodeLensProvider(context, git)));

src/gitCodeLensProvider.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export class GitHistoryCodeLens extends CodeLens {
2323
export default class GitCodeLensProvider implements CodeLensProvider {
2424
static selector: DocumentSelector = { scheme: DocumentSchemes.File };
2525

26-
constructor(context: ExtensionContext, private git: GitProvider) { }
26+
private hasGitHistoryExtension: boolean;
27+
28+
constructor(context: ExtensionContext, private git: GitProvider) {
29+
this.hasGitHistoryExtension = context.workspaceState.get(WorkspaceState.HasGitHistoryExtension, false);
30+
}
2731

2832
provideCodeLenses(document: TextDocument, token: CancellationToken): CodeLens[] | Thenable<CodeLens[]> {
2933
const fileName = document.fileName;
@@ -38,7 +42,9 @@ export default class GitCodeLensProvider implements CodeLensProvider {
3842
if (!lenses.find(l => l.range.start.line === 0 && l.range.end.line === 0)) {
3943
const blameRange = document.validateRange(new Range(0, 1000000, 1000000, 1000000));
4044
lenses.push(new GitCodeLens(this.git, fileName, blameRange, new Range(0, 0, 0, blameRange.start.character)));
41-
lenses.push(new GitHistoryCodeLens(this.git.repoPath, fileName, new Range(0, 1, 0, blameRange.start.character)));
45+
if (this.hasGitHistoryExtension) {
46+
lenses.push(new GitHistoryCodeLens(this.git.repoPath, fileName, new Range(0, 1, 0, blameRange.start.character)));
47+
}
4248
}
4349
return lenses;
4450
});
@@ -71,7 +77,9 @@ export default class GitCodeLensProvider implements CodeLensProvider {
7177
}
7278

7379
lenses.push(new GitCodeLens(this.git, fileName, symbol.location.range, line.range.with(new Position(line.range.start.line, startChar))));
74-
lenses.push(new GitHistoryCodeLens(this.git.repoPath, fileName, line.range.with(new Position(line.range.start.line, startChar + 1))));
80+
if (this.hasGitHistoryExtension) {
81+
lenses.push(new GitHistoryCodeLens(this.git.repoPath, fileName, line.range.with(new Position(line.range.start.line, startChar + 1))));
82+
}
7583
}
7684

7785
resolveCodeLens(lens: CodeLens, token: CancellationToken): Thenable<CodeLens> {

0 commit comments

Comments
 (0)