streamline scm extension api

This commit is contained in:
Joao Moreno
2016-11-24 16:24:32 +01:00
parent 0edd066b17
commit ceda84ef28
5 changed files with 102 additions and 72 deletions

View File

@@ -5,7 +5,7 @@
'use strict';
import { scm, ExtensionContext, workspace } from 'vscode';
import { scm, ExtensionContext, workspace, Uri } from 'vscode';
import * as path from 'path';
import { findGit, Git } from './git';
@@ -13,6 +13,19 @@ export function log(...args: any[]): void {
console.log.apply(console, ['git:', ...args]);
}
class GitSCMProvider {
resourceGroups = [];
onDidChangeResourceGroup = null;
getOriginalResource(uri: Uri): Uri {
if (uri.scheme !== 'file') {
return null;
}
return uri.with({ scheme: 'git-index' });
}
}
export function activate(context: ExtensionContext): any {
if (!workspace) {
return;
@@ -24,16 +37,8 @@ export function activate(context: ExtensionContext): any {
log(`Using git ${info.version} from ${info.path}`);
const git = new Git({ gitPath: info.path, version: info.version });
const scmProvider = scm.createSCMProvider('git', {
getOriginalResource: uri => {
if (uri.scheme !== 'file') {
return null;
}
return uri.with({ scheme: 'git-index' });
}
});
const provider = new GitSCMProvider();
const providerDisposable = scm.registerSCMProvider('git', provider);
const contentProvider = workspace.registerTextDocumentContentProvider('git-index', {
provideTextDocumentContent: uri => {
@@ -49,6 +54,6 @@ export function activate(context: ExtensionContext): any {
}
});
context.subscriptions.push(scmProvider, contentProvider);
context.subscriptions.push(providerDisposable, contentProvider);
});
}