Reworks git abstraction and acccess

Adds commands module
Adds git commit message to blame hover decorator
This commit is contained in:
Eric Amodio
2016-08-31 17:20:53 -04:00
parent 9964ea691b
commit 0e064f15c7
7 changed files with 181 additions and 130 deletions

View File

@@ -1,10 +1,10 @@
'use strict';
import {CodeLens, commands, DocumentSelector, ExtensionContext, languages, Position, Range, Uri, window, workspace} from 'vscode';
import {CodeLens, DocumentSelector, ExtensionContext, languages, workspace} from 'vscode';
import GitCodeLensProvider, {GitBlameCodeLens} from './codeLensProvider';
import GitContentProvider from './contentProvider';
import {gitRepoPath} from './git';
import GitBlameProvider from './gitBlameProvider';
import {Commands, VsCodeCommands, WorkspaceState} from './constants';
import GitProvider from './gitProvider';
import {BlameCommand} from './commands';
import {WorkspaceState} from './constants';
// this method is called when your extension is activated
export function activate(context: ExtensionContext) {
@@ -16,35 +16,19 @@ export function activate(context: ExtensionContext) {
}
console.log(`GitLens active: ${workspace.rootPath}`);
gitRepoPath(workspace.rootPath).then(repoPath => {
const git = new GitProvider(context);
context.subscriptions.push(git);
git.getRepoPath(workspace.rootPath).then(repoPath => {
context.workspaceState.update(WorkspaceState.RepoPath, repoPath);
const blameProvider = new GitBlameProvider(context);
context.subscriptions.push(blameProvider);
context.subscriptions.push(workspace.registerTextDocumentContentProvider(GitContentProvider.scheme, new GitContentProvider(context, git)));
context.subscriptions.push(workspace.registerTextDocumentContentProvider(GitContentProvider.scheme, new GitContentProvider(context, blameProvider)));
context.subscriptions.push(commands.registerCommand(Commands.ShowBlameHistory, (uri?: Uri, range?: Range, position?: Position) => {
// If the command is executed manually -- treat it as a click on the root lens (i.e. show blame for the whole file)
if (!uri) {
const doc = window.activeTextEditor && window.activeTextEditor.document;
if (doc) {
uri = doc.uri;
range = doc.validateRange(new Range(0, 0, 1000000, 1000000));
position = doc.validateRange(new Range(0, 0, 0, 1000000)).start;
}
if (!uri) return;
}
console.log(uri.path, blameProvider.repoPath, range, position);
return blameProvider.getBlameLocations(uri.path, blameProvider.repoPath, range).then(locations => {
return commands.executeCommand(VsCodeCommands.ShowReferences, uri, position, locations);
});
}));
context.subscriptions.push(new BlameCommand(git));
const selector: DocumentSelector = { scheme: 'file' };
context.subscriptions.push(languages.registerCodeLensProvider(selector, new GitCodeLensProvider(context, blameProvider)));
context.subscriptions.push(languages.registerCodeLensProvider(selector, new GitCodeLensProvider(context, git)));
}).catch(reason => console.warn(reason));
}