Refresh master with initial release/0.24 snapshot (#332)

* Initial port of release/0.24 source code

* Fix additional headers

* Fix a typo in launch.json
This commit is contained in:
Karl Burtram
2017-12-15 15:38:57 -08:00
committed by GitHub
parent 271b3a0b82
commit 6ad0df0e3e
7118 changed files with 107999 additions and 56466 deletions

View File

@@ -6,13 +6,21 @@
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import Event, { Emitter } from 'vs/base/common/event';
import Event, { Emitter, once } from 'vs/base/common/event';
import { debounce } from 'vs/base/common/decorators';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { asWinJsPromise } from 'vs/base/common/async';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/node/extHostCommands';
import { MainContext, MainThreadSCMShape, SCMRawResource, IMainContext } from './extHost.protocol';
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
import { MainContext, MainThreadSCMShape, SCMRawResource, SCMRawResourceSplice, SCMRawResourceSplices, IMainContext } from './extHost.protocol';
import { sortedDiff } from 'vs/base/common/arrays';
import { comparePaths } from 'vs/base/common/comparers';
import * as vscode from 'vscode';
type ProviderHandle = number;
type GroupHandle = number;
type ResourceStateHandle = number;
function getIconPath(decorations: vscode.SourceControlResourceThemableDecorations) {
if (!decorations) {
return undefined;
@@ -24,6 +32,82 @@ function getIconPath(decorations: vscode.SourceControlResourceThemableDecoration
return undefined;
}
function compareResourceThemableDecorations(a: vscode.SourceControlResourceThemableDecorations, b: vscode.SourceControlResourceThemableDecorations): number {
if (!a.iconPath && !b.iconPath) {
return 0;
} else if (!a.iconPath) {
return -1;
} else if (!b.iconPath) {
return 1;
}
const aPath = typeof a.iconPath === 'string' ? a.iconPath : a.iconPath.fsPath;
const bPath = typeof b.iconPath === 'string' ? b.iconPath : b.iconPath.fsPath;
return comparePaths(aPath, bPath);
}
function compareResourceStatesDecorations(a: vscode.SourceControlResourceDecorations, b: vscode.SourceControlResourceDecorations): number {
let result = 0;
if (a.strikeThrough !== b.strikeThrough) {
return a.strikeThrough ? 1 : -1;
}
if (a.faded !== b.faded) {
return a.faded ? 1 : -1;
}
if (a.tooltip !== b.tooltip) {
return (a.tooltip || '').localeCompare(b.tooltip);
}
result = compareResourceThemableDecorations(a, b);
if (result !== 0) {
return result;
}
if (a.light && b.light) {
result = compareResourceThemableDecorations(a.light, b.light);
} else if (a.light) {
return 1;
} else if (b.light) {
return -1;
}
if (result !== 0) {
return result;
}
if (a.dark && b.dark) {
result = compareResourceThemableDecorations(a.dark, b.dark);
} else if (a.dark) {
return 1;
} else if (b.dark) {
return -1;
}
return result;
}
function compareResourceStates(a: vscode.SourceControlResourceState, b: vscode.SourceControlResourceState): number {
let result = comparePaths(a.resourceUri.fsPath, b.resourceUri.fsPath);
if (result !== 0) {
return result;
}
if (a.decorations && b.decorations) {
result = compareResourceStatesDecorations(a.decorations, b.decorations);
} else if (a.decorations) {
return 1;
} else if (b.decorations) {
return -1;
}
return result;
}
export class ExtHostSCMInputBox {
private _value: string = '';
@@ -62,99 +146,135 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
private static _handlePool: number = 0;
private _resourceHandlePool: number = 0;
private _resourceStates: vscode.SourceControlResourceState[] = [];
private _resourceStatesRollingDisposables: { (): void }[] = [];
private _resourceStatesMap: Map<ResourceStateHandle, vscode.SourceControlResourceState> = new Map<ResourceStateHandle, vscode.SourceControlResourceState>();
private _resourceStatesCommandsMap: Map<ResourceStateHandle, vscode.Command> = new Map<ResourceStateHandle, vscode.Command>();
get id(): string {
return this._id;
}
private _onDidUpdateResourceStates = new Emitter<void>();
readonly onDidUpdateResourceStates = this._onDidUpdateResourceStates.event;
private _onDidDispose = new Emitter<void>();
readonly onDidDispose = this._onDidDispose.event;
get label(): string {
return this._label;
}
private _handlesSnapshot: number[] = [];
private _resourceSnapshot: vscode.SourceControlResourceState[] = [];
get id(): string { return this._id; }
get label(): string { return this._label; }
set label(label: string) {
this._label = label;
this._proxy.$updateGroupLabel(this._sourceControlHandle, this._handle, label);
this._proxy.$updateGroupLabel(this._sourceControlHandle, this.handle, label);
}
private _hideWhenEmpty: boolean | undefined = undefined;
get hideWhenEmpty(): boolean | undefined {
return this._hideWhenEmpty;
}
get hideWhenEmpty(): boolean | undefined { return this._hideWhenEmpty; }
set hideWhenEmpty(hideWhenEmpty: boolean | undefined) {
this._hideWhenEmpty = hideWhenEmpty;
this._proxy.$updateGroup(this._sourceControlHandle, this._handle, { hideWhenEmpty });
}
get resourceStates(): vscode.SourceControlResourceState[] {
return [...this._resourceStates];
this._proxy.$updateGroup(this._sourceControlHandle, this.handle, { hideWhenEmpty });
}
get resourceStates(): vscode.SourceControlResourceState[] { return [...this._resourceStates]; }
set resourceStates(resources: vscode.SourceControlResourceState[]) {
this._resourceStates = [...resources];
const handles: number[] = [];
const rawResources = resources.map(r => {
const handle = this._resourceHandlePool++;
this._resourceStatesMap.set(handle, r);
handles.push(handle);
const sourceUri = r.resourceUri.toString();
const command = this._commands.toInternal(r.command);
const iconPath = getIconPath(r.decorations);
const lightIconPath = r.decorations && getIconPath(r.decorations.light) || iconPath;
const darkIconPath = r.decorations && getIconPath(r.decorations.dark) || iconPath;
const icons: string[] = [];
if (lightIconPath || darkIconPath) {
icons.push(lightIconPath);
}
if (darkIconPath !== lightIconPath) {
icons.push(darkIconPath);
}
const tooltip = (r.decorations && r.decorations.tooltip) || '';
const strikeThrough = r.decorations && !!r.decorations.strikeThrough;
const faded = r.decorations && !!r.decorations.faded;
return [handle, sourceUri, command, icons, tooltip, strikeThrough, faded] as SCMRawResource;
});
const disposable = () => handles.forEach(handle => this._resourceStatesMap.delete(handle));
this._resourceStatesRollingDisposables.push(disposable);
while (this._resourceStatesRollingDisposables.length >= 10) {
this._resourceStatesRollingDisposables.shift()();
}
this._proxy.$updateGroupResourceStates(this._sourceControlHandle, this._handle, rawResources);
this._onDidUpdateResourceStates.fire();
}
private _handle: GroupHandle = ExtHostSourceControlResourceGroup._handlePool++;
get handle(): GroupHandle {
return this._handle;
}
readonly handle = ExtHostSourceControlResourceGroup._handlePool++;
private _disposables: IDisposable[] = [];
constructor(
private _proxy: MainThreadSCMShape,
private _commands: CommandsConverter,
private _commands: ExtHostCommands,
private _sourceControlHandle: number,
private _id: string,
private _label: string,
) {
this._proxy.$registerGroup(_sourceControlHandle, this._handle, _id, _label);
this._proxy.$registerGroup(_sourceControlHandle, this.handle, _id, _label);
}
getResourceState(handle: number): vscode.SourceControlResourceState | undefined {
return this._resourceStatesMap.get(handle);
}
async $executeResourceCommand(handle: number): TPromise<void> {
const command = this._resourceStatesCommandsMap.get(handle);
if (!command) {
return;
}
await this._commands.executeCommand(command.command, ...command.arguments);
}
_takeResourceStateSnapshot(): SCMRawResourceSplice[] {
const snapshot = [...this._resourceStates].sort(compareResourceStates);
const diffs = sortedDiff(this._resourceSnapshot, snapshot, compareResourceStates);
const handlesToDelete: number[] = [];
const splices = diffs.map(diff => {
const { start, deleteCount } = diff;
const handles: number[] = [];
const rawResources = diff.inserted
.map(r => {
const handle = this._resourceHandlePool++;
this._resourceStatesMap.set(handle, r);
handles.push(handle);
const sourceUri = r.resourceUri.toString();
const iconPath = getIconPath(r.decorations);
const lightIconPath = r.decorations && getIconPath(r.decorations.light) || iconPath;
const darkIconPath = r.decorations && getIconPath(r.decorations.dark) || iconPath;
const icons: string[] = [];
if (r.command) {
this._resourceStatesCommandsMap.set(handle, r.command);
}
if (lightIconPath || darkIconPath) {
icons.push(lightIconPath);
}
if (darkIconPath !== lightIconPath) {
icons.push(darkIconPath);
}
const tooltip = (r.decorations && r.decorations.tooltip) || '';
const strikeThrough = r.decorations && !!r.decorations.strikeThrough;
const faded = r.decorations && !!r.decorations.faded;
const source = r.decorations && r.decorations.source || undefined;
const letter = r.decorations && r.decorations.letter || undefined;
const color = r.decorations && r.decorations.color || undefined;
return [handle, sourceUri, icons, tooltip, strikeThrough, faded, source, letter, color] as SCMRawResource;
});
handlesToDelete.push(...this._handlesSnapshot.splice(start, deleteCount, ...handles));
return [start, deleteCount, rawResources] as SCMRawResourceSplice;
});
const disposable = () => handlesToDelete.forEach(handle => {
this._resourceStatesMap.delete(handle);
this._resourceStatesCommandsMap.delete(handle);
});
this._resourceStatesRollingDisposables.push(disposable);
while (this._resourceStatesRollingDisposables.length >= 10) {
this._resourceStatesRollingDisposables.shift()();
}
this._resourceSnapshot = snapshot;
return splices;
}
dispose(): void {
this._proxy.$unregisterGroup(this._sourceControlHandle, this._handle);
this._proxy.$unregisterGroup(this._sourceControlHandle, this.handle);
this._disposables = dispose(this._disposables);
this._onDidDispose.fire();
}
}
@@ -171,6 +291,10 @@ class ExtHostSourceControl implements vscode.SourceControl {
return this._label;
}
get rootUri(): vscode.Uri | undefined {
return this._rootUri;
}
private _inputBox: ExtHostSCMInputBox;
get inputBox(): ExtHostSCMInputBox { return this._inputBox; }
@@ -182,7 +306,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
set count(count: number | undefined) {
this._count = count;
this._proxy.$updateSourceControl(this._handle, { count });
this._proxy.$updateSourceControl(this.handle, { count });
}
private _quickDiffProvider: vscode.QuickDiffProvider | undefined = undefined;
@@ -193,7 +317,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
set quickDiffProvider(quickDiffProvider: vscode.QuickDiffProvider | undefined) {
this._quickDiffProvider = quickDiffProvider;
this._proxy.$updateSourceControl(this._handle, { hasQuickDiffProvider: !!quickDiffProvider });
this._proxy.$updateSourceControl(this.handle, { hasQuickDiffProvider: !!quickDiffProvider });
}
private _commitTemplate: string | undefined = undefined;
@@ -204,7 +328,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
set commitTemplate(commitTemplate: string | undefined) {
this._commitTemplate = commitTemplate;
this._proxy.$updateSourceControl(this._handle, { commitTemplate });
this._proxy.$updateSourceControl(this.handle, { commitTemplate });
}
private _acceptInputCommand: vscode.Command | undefined = undefined;
@@ -216,8 +340,8 @@ class ExtHostSourceControl implements vscode.SourceControl {
set acceptInputCommand(acceptInputCommand: vscode.Command | undefined) {
this._acceptInputCommand = acceptInputCommand;
const internal = this._commands.toInternal(acceptInputCommand);
this._proxy.$updateSourceControl(this._handle, { acceptInputCommand: internal });
const internal = this._commands.converter.toInternal(acceptInputCommand);
this._proxy.$updateSourceControl(this.handle, { acceptInputCommand: internal });
}
private _statusBarCommands: vscode.Command[] | undefined = undefined;
@@ -229,41 +353,74 @@ class ExtHostSourceControl implements vscode.SourceControl {
set statusBarCommands(statusBarCommands: vscode.Command[] | undefined) {
this._statusBarCommands = statusBarCommands;
const internal = (statusBarCommands || []).map(c => this._commands.toInternal(c));
this._proxy.$updateSourceControl(this._handle, { statusBarCommands: internal });
const internal = (statusBarCommands || []).map(c => this._commands.converter.toInternal(c));
this._proxy.$updateSourceControl(this.handle, { statusBarCommands: internal });
}
private _handle: number = ExtHostSourceControl._handlePool++;
private handle: number = ExtHostSourceControl._handlePool++;
constructor(
private _proxy: MainThreadSCMShape,
private _commands: CommandsConverter,
private _commands: ExtHostCommands,
private _id: string,
private _label: string,
private _rootUri?: vscode.Uri
) {
this._inputBox = new ExtHostSCMInputBox(this._proxy, this._handle);
this._proxy.$registerSourceControl(this._handle, _id, _label);
this._inputBox = new ExtHostSCMInputBox(this._proxy, this.handle);
this._proxy.$registerSourceControl(this.handle, _id, _label, _rootUri && _rootUri.toString());
}
private updatedResourceGroups = new Set<ExtHostSourceControlResourceGroup>();
createResourceGroup(id: string, label: string): ExtHostSourceControlResourceGroup {
const group = new ExtHostSourceControlResourceGroup(this._proxy, this._commands, this._handle, id, label);
const group = new ExtHostSourceControlResourceGroup(this._proxy, this._commands, this.handle, id, label);
const updateListener = group.onDidUpdateResourceStates(() => {
this.updatedResourceGroups.add(group);
this.eventuallyUpdateResourceStates();
});
once(group.onDidDispose)(() => {
this.updatedResourceGroups.delete(group);
updateListener.dispose();
this._groups.delete(group.handle);
});
this._groups.set(group.handle, group);
return group;
}
@debounce(100)
eventuallyUpdateResourceStates(): void {
const splices: SCMRawResourceSplices[] = [];
this.updatedResourceGroups.forEach(group => {
const snapshot = group._takeResourceStateSnapshot();
if (snapshot.length === 0) {
return;
}
splices.push([group.handle, snapshot]);
});
if (splices.length > 0) {
this._proxy.$spliceResourceStates(this.handle, splices);
}
this.updatedResourceGroups.clear();
}
getResourceGroup(handle: GroupHandle): ExtHostSourceControlResourceGroup | undefined {
return this._groups.get(handle);
}
dispose(): void {
this._proxy.$unregisterSourceControl(this._handle);
this._groups.forEach(group => group.dispose());
this._proxy.$unregisterSourceControl(this.handle);
}
}
type ProviderHandle = number;
type GroupHandle = number;
type ResourceStateHandle = number;
export class ExtHostSCM {
private static _handlePool: number = 0;
@@ -320,9 +477,9 @@ export class ExtHostSCM {
});
}
createSourceControl(extension: IExtensionDescription, id: string, label: string): vscode.SourceControl {
createSourceControl(extension: IExtensionDescription, id: string, label: string, rootUri: vscode.Uri | undefined): vscode.SourceControl {
const handle = ExtHostSCM._handlePool++;
const sourceControl = new ExtHostSourceControl(this._proxy, this._commands.converter, id, label);
const sourceControl = new ExtHostSourceControl(this._proxy, this._commands, id, label, rootUri);
this._sourceControls.set(handle, sourceControl);
const sourceControls = this._sourceControlsByExtension.get(extension.id) || [];
@@ -357,11 +514,27 @@ export class ExtHostSCM {
$onInputBoxValueChange(sourceControlHandle: number, value: string): TPromise<void> {
const sourceControl = this._sourceControls.get(sourceControlHandle);
if (!sourceControl || !sourceControl.quickDiffProvider) {
if (!sourceControl) {
return TPromise.as(null);
}
sourceControl.inputBox.$onInputBoxValueChange(value);
return TPromise.as(null);
}
async $executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): TPromise<void> {
const sourceControl = this._sourceControls.get(sourceControlHandle);
if (!sourceControl) {
return;
}
const group = sourceControl.getResourceGroup(groupHandle);
if (!group) {
return;
}
await group.$executeResourceCommand(handle);
}
}