diff --git a/package.json b/package.json index 688b75f..0816d58 100644 --- a/package.json +++ b/package.json @@ -41,9 +41,6 @@ "typescript": "^1.8.10", "vscode": "^0.11.17" }, - "extensionDependencies": [ - "donjayamanne.githistory" - ], "scripts": { "vscode:prepublish": "node ./node_modules/vscode/bin/compile", "compile": "node ./node_modules/vscode/bin/compile -watch -p ./", diff --git a/src/constants.ts b/src/constants.ts index 1cbb4b6..203d0d9 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,7 +1,8 @@ 'use strict' -export type WorkspaceState = 'repoPath'; +export type WorkspaceState = 'hasGitHistoryExtension' | 'repoPath'; export const WorkspaceState = { + HasGitHistoryExtension: 'hasGitHistoryExtension' as WorkspaceState, RepoPath: 'repoPath' as WorkspaceState } diff --git a/src/extension.ts b/src/extension.ts index fabcbe1..0c45591 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,5 @@ 'use strict'; -import {CodeLens, DocumentSelector, ExtensionContext, languages, workspace} from 'vscode'; +import {CodeLens, DocumentSelector, ExtensionContext, extensions, languages, workspace} from 'vscode'; import GitCodeLensProvider from './gitCodeLensProvider'; import GitBlameCodeLensProvider from './gitBlameCodeLensProvider'; import GitBlameContentProvider from './gitBlameContentProvider'; @@ -23,6 +23,7 @@ export function activate(context: ExtensionContext) { git.getRepoPath(workspace.rootPath).then(repoPath => { context.workspaceState.update(WorkspaceState.RepoPath, repoPath); + context.workspaceState.update(WorkspaceState.HasGitHistoryExtension, extensions.getExtension('donjayamanne.githistory') !== undefined); context.subscriptions.push(workspace.registerTextDocumentContentProvider(GitBlameContentProvider.scheme, new GitBlameContentProvider(context, git))); context.subscriptions.push(languages.registerCodeLensProvider(GitCodeLensProvider.selector, new GitCodeLensProvider(context, git))); diff --git a/src/gitCodeLensProvider.ts b/src/gitCodeLensProvider.ts index 6e5e15d..e27ce0e 100644 --- a/src/gitCodeLensProvider.ts +++ b/src/gitCodeLensProvider.ts @@ -23,7 +23,11 @@ export class GitHistoryCodeLens extends CodeLens { export default class GitCodeLensProvider implements CodeLensProvider { static selector: DocumentSelector = { scheme: DocumentSchemes.File }; - constructor(context: ExtensionContext, private git: GitProvider) { } + private hasGitHistoryExtension: boolean; + + constructor(context: ExtensionContext, private git: GitProvider) { + this.hasGitHistoryExtension = context.workspaceState.get(WorkspaceState.HasGitHistoryExtension, false); + } provideCodeLenses(document: TextDocument, token: CancellationToken): CodeLens[] | Thenable { const fileName = document.fileName; @@ -38,7 +42,9 @@ export default class GitCodeLensProvider implements CodeLensProvider { if (!lenses.find(l => l.range.start.line === 0 && l.range.end.line === 0)) { const blameRange = document.validateRange(new Range(0, 1000000, 1000000, 1000000)); lenses.push(new GitCodeLens(this.git, fileName, blameRange, new Range(0, 0, 0, blameRange.start.character))); - lenses.push(new GitHistoryCodeLens(this.git.repoPath, fileName, new Range(0, 1, 0, blameRange.start.character))); + if (this.hasGitHistoryExtension) { + lenses.push(new GitHistoryCodeLens(this.git.repoPath, fileName, new Range(0, 1, 0, blameRange.start.character))); + } } return lenses; }); @@ -71,7 +77,9 @@ export default class GitCodeLensProvider implements CodeLensProvider { } lenses.push(new GitCodeLens(this.git, fileName, symbol.location.range, line.range.with(new Position(line.range.start.line, startChar)))); - lenses.push(new GitHistoryCodeLens(this.git.repoPath, fileName, line.range.with(new Position(line.range.start.line, startChar + 1)))); + if (this.hasGitHistoryExtension) { + lenses.push(new GitHistoryCodeLens(this.git.repoPath, fileName, line.range.with(new Position(line.range.start.line, startChar + 1)))); + } } resolveCodeLens(lens: CodeLens, token: CancellationToken): Thenable {