Ver código fonte

Removes hard dependency on donjayamanne.githistory

Provides optional additional code lens
main
Eric Amodio 8 anos atrás
pai
commit
ea33560f14
4 arquivos alterados com 15 adições e 8 exclusões
  1. +0
    -3
      package.json
  2. +2
    -1
      src/constants.ts
  3. +2
    -1
      src/extension.ts
  4. +11
    -3
      src/gitCodeLensProvider.ts

+ 0
- 3
package.json Ver arquivo

@ -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 ./",

+ 2
- 1
src/constants.ts Ver arquivo

@ -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
}

+ 2
- 1
src/extension.ts Ver arquivo

@ -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)));

+ 11
- 3
src/gitCodeLensProvider.ts Ver arquivo

@ -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<CodeLens[]> {
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<CodeLens> {

Carregando…
Cancelar
Salvar