mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 17:22:45 -05:00
Merge VS Code 1.23.1 (#1520)
This commit is contained in:
@@ -4,16 +4,20 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { Progress, ProgressOptions, CancellationToken } from 'vscode';
|
||||
import { MainThreadProgressShape } from './extHost.protocol';
|
||||
import { ProgressOptions } from 'vscode';
|
||||
import { MainThreadProgressShape, ExtHostProgressShape } from './extHost.protocol';
|
||||
import { ProgressLocation } from './extHostTypeConverters';
|
||||
import { IExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { IProgressStep } from 'vs/platform/progress/common/progress';
|
||||
import { IProgressStep, Progress } from 'vs/platform/progress/common/progress';
|
||||
import { localize } from 'vs/nls';
|
||||
import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { debounce } from 'vs/base/common/decorators';
|
||||
|
||||
export class ExtHostProgress {
|
||||
export class ExtHostProgress implements ExtHostProgressShape {
|
||||
|
||||
private _proxy: MainThreadProgressShape;
|
||||
private _handles: number = 0;
|
||||
private _mapHandleToCancellationSource: Map<number, CancellationTokenSource> = new Map();
|
||||
|
||||
constructor(proxy: MainThreadProgressShape) {
|
||||
this._proxy = proxy;
|
||||
@@ -21,30 +25,66 @@ export class ExtHostProgress {
|
||||
|
||||
withProgress<R>(extension: IExtensionDescription, options: ProgressOptions, task: (progress: Progress<IProgressStep>, token: CancellationToken) => Thenable<R>): Thenable<R> {
|
||||
const handle = this._handles++;
|
||||
const { title, location } = options;
|
||||
this._proxy.$startProgress(handle, { location: ProgressLocation.from(location), title, tooltip: extension.name });
|
||||
return this._withProgress(handle, task);
|
||||
const { title, location, cancellable } = options;
|
||||
const source = localize('extensionSource', "{0} (Extension)", extension.displayName || extension.name);
|
||||
this._proxy.$startProgress(handle, { location: ProgressLocation.from(location), title, source, cancellable });
|
||||
return this._withProgress(handle, task, cancellable);
|
||||
}
|
||||
|
||||
private _withProgress<R>(handle: number, task: (progress: Progress<IProgressStep>, token: CancellationToken) => Thenable<R>): Thenable<R> {
|
||||
private _withProgress<R>(handle: number, task: (progress: Progress<IProgressStep>, token: CancellationToken) => Thenable<R>, cancellable: boolean): Thenable<R> {
|
||||
let source: CancellationTokenSource;
|
||||
if (cancellable) {
|
||||
source = new CancellationTokenSource();
|
||||
this._mapHandleToCancellationSource.set(handle, source);
|
||||
}
|
||||
|
||||
const progress = {
|
||||
report: (p: IProgressStep) => {
|
||||
this._proxy.$progressReport(handle, p);
|
||||
const progressEnd = (handle: number): void => {
|
||||
this._proxy.$progressEnd(handle);
|
||||
this._mapHandleToCancellationSource.delete(handle);
|
||||
if (source) {
|
||||
source.dispose();
|
||||
}
|
||||
};
|
||||
|
||||
let p: Thenable<R>;
|
||||
|
||||
try {
|
||||
p = task(progress, null);
|
||||
p = task(new ProgressCallback(this._proxy, handle), cancellable ? source.token : CancellationToken.None);
|
||||
} catch (err) {
|
||||
this._proxy.$progressEnd(handle);
|
||||
progressEnd(handle);
|
||||
throw err;
|
||||
}
|
||||
|
||||
p.then(result => this._proxy.$progressEnd(handle), err => this._proxy.$progressEnd(handle));
|
||||
p.then(result => progressEnd(handle), err => progressEnd(handle));
|
||||
return p;
|
||||
}
|
||||
|
||||
public $acceptProgressCanceled(handle: number): void {
|
||||
const source = this._mapHandleToCancellationSource.get(handle);
|
||||
if (source) {
|
||||
source.cancel();
|
||||
this._mapHandleToCancellationSource.delete(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mergeProgress(result: IProgressStep, currentValue: IProgressStep): IProgressStep {
|
||||
result.message = currentValue.message;
|
||||
if (typeof currentValue.increment === 'number' && typeof result.message === 'number') {
|
||||
result.increment += currentValue.increment;
|
||||
} else if (typeof currentValue.increment === 'number') {
|
||||
result.increment = currentValue.increment;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class ProgressCallback extends Progress<IProgressStep> {
|
||||
constructor(private _proxy: MainThreadProgressShape, private _handle: number) {
|
||||
super(p => this.throttledReport(p));
|
||||
}
|
||||
|
||||
@debounce(100, (result: IProgressStep, currentValue: IProgressStep) => mergeProgress(result, currentValue), () => Object.create(null))
|
||||
throttledReport(p: IProgressStep): void {
|
||||
this._proxy.$progressReport(this._handle, p);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user