提交 db39621b 编写于 作者: B Benjamin Pasero

fix #54295, fix #54369

上级 6babef94
......@@ -11,7 +11,6 @@ import { IExtensionDescription } from 'vs/workbench/services/extensions/common/e
import { 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';
import { IProgressStep } from 'vs/workbench/services/progress/common/progress';
export class ExtHostProgress implements ExtHostProgressShape {
......@@ -69,22 +68,37 @@ export class ExtHostProgress implements ExtHostProgressShape {
}
}
function mergeProgress(result: IProgressStep, currentValue: IProgressStep): IProgressStep {
result.message = currentValue.message;
if (typeof currentValue.increment === 'number') {
result.increment = currentValue.increment;
}
return result;
}
class ProgressCallback extends Progress<IProgressStep> {
private throttledProgressStep: 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);
private throttledReport(p: IProgressStep): void {
// Throttle progress over the duration of 100ms
if (!this.throttledProgressStep) {
this.throttledProgressStep = p;
setTimeout(() => {
this._proxy.$progressReport(this._handle, this.throttledProgressStep);
this.throttledProgressStep = void 0;
}, 100);
}
// If throttled, merge the progress step into the existing one
else {
this.throttledProgressStep.message = p.message;
if (typeof p.increment === 'number') {
if (typeof this.throttledProgressStep.increment === 'number') {
this.throttledProgressStep.increment += p.increment;
} else {
this.throttledProgressStep.increment = p.increment;
}
}
}
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册