in source-control-sample/src/extension.ts [18:81]
export async function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "source-control-sample" is now active!');
jsFiddleDocumentContentProvider = new JSFiddleDocumentContentProvider();
try {
await initializeFromConfigurationFile(context);
}
catch (err) {
console.log('Failed to initialize a Fiddle workspace.');
vscode.window.showErrorMessage(err);
}
const openCommand = vscode.commands.registerCommand(SOURCE_CONTROL_OPEN_COMMAND,
(fiddleId?: string, workspaceUri?: vscode.Uri) => {
tryOpenFiddle(context, fiddleId, workspaceUri);
});
context.subscriptions.push(openCommand);
context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider(JSFIDDLE_SCHEME, jsFiddleDocumentContentProvider));
context.subscriptions.push(vscode.commands.registerCommand("extension.source-control.refresh",
async (sourceControlPane: vscode.SourceControl) => {
const sourceControl = await pickSourceControl(sourceControlPane);
if (sourceControl) { sourceControl.refresh(); }
}));
context.subscriptions.push(vscode.commands.registerCommand("extension.source-control.discard",
async (sourceControlPane: vscode.SourceControl) => {
const sourceControl = await pickSourceControl(sourceControlPane);
if (sourceControl) { sourceControl.resetFilesToCheckedOutVersion(); }
}));
context.subscriptions.push(vscode.commands.registerCommand("extension.source-control.commit",
async (sourceControlPane: vscode.SourceControl) => {
const sourceControl = await pickSourceControl(sourceControlPane);
if (sourceControl) { sourceControl.commitAll(); }
}));
context.subscriptions.push(vscode.commands.registerCommand("extension.source-control.checkout",
async (sourceControl: FiddleSourceControl, newVersion?: number) => {
sourceControl = sourceControl || await pickSourceControl(null);
if (sourceControl) { sourceControl.tryCheckout(newVersion); }
}));
context.subscriptions.push(vscode.commands.registerCommand("extension.source-control.browse",
async (sourceControlPane: vscode.SourceControl) => {
const sourceControl = await pickSourceControl(sourceControlPane);
if (sourceControl) { sourceControl.openInBrowser(); }
}));
context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders(e => {
try {
// initialize new source control for manually added workspace folders
e.added.forEach(wf => {
initializeFolderFromConfigurationFile(wf, context);
});
} catch (ex) {
vscode.window.showErrorMessage(ex.message);
} finally {
// dispose source control for removed workspace folders
e.removed.forEach(wf => {
unregisterFiddleSourceControl(wf.uri);
});
}
}));
}