未验证 提交 4aee31ef 编写于 作者: A Alex Dima

Switch to use a notification when the max computation time is reached

上级 86ea9e1d
...@@ -864,6 +864,11 @@ export interface IDiffEditor extends editorCommon.IEditor { ...@@ -864,6 +864,11 @@ export interface IDiffEditor extends editorCommon.IEditor {
* @internal * @internal
*/ */
readonly renderIndicators: boolean; readonly renderIndicators: boolean;
/**
* Timeout in milliseconds after which diff computation is cancelled.
* @internal
*/
readonly maxComputationTime: number;
/** /**
* @see ICodeEditor.getDomNode * @see ICodeEditor.getDomNode
......
...@@ -400,6 +400,10 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE ...@@ -400,6 +400,10 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
return this._renderSideBySide; return this._renderSideBySide;
} }
public get maxComputationTime(): number {
return this._maxComputationTime;
}
public get renderIndicators(): boolean { public get renderIndicators(): boolean {
return this._renderIndicators; return this._renderIndicators;
} }
......
...@@ -12,11 +12,11 @@ import { FloatingClickWidget } from 'vs/workbench/browser/parts/editor/editorWid ...@@ -12,11 +12,11 @@ import { FloatingClickWidget } from 'vs/workbench/browser/parts/editor/editorWid
import { IDiffComputationResult } from 'vs/editor/common/services/editorWorkerService'; import { IDiffComputationResult } from 'vs/editor/common/services/editorWorkerService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
const enum WidgetState { const enum WidgetState {
Hidden, Hidden,
HintWhitespace, HintWhitespace
HintTimeout
} }
class DiffEditorHelperContribution extends Disposable implements IEditorContribution { class DiffEditorHelperContribution extends Disposable implements IEditorContribution {
...@@ -29,6 +29,7 @@ class DiffEditorHelperContribution extends Disposable implements IEditorContribu ...@@ -29,6 +29,7 @@ class DiffEditorHelperContribution extends Disposable implements IEditorContribu
private readonly _diffEditor: IDiffEditor, private readonly _diffEditor: IDiffEditor,
@IInstantiationService private readonly _instantiationService: IInstantiationService, @IInstantiationService private readonly _instantiationService: IInstantiationService,
@IConfigurationService private readonly _configurationService: IConfigurationService, @IConfigurationService private readonly _configurationService: IConfigurationService,
@INotificationService private readonly _notificationService: INotificationService,
) { ) {
super(); super();
this._helperWidget = null; this._helperWidget = null;
...@@ -37,7 +38,22 @@ class DiffEditorHelperContribution extends Disposable implements IEditorContribu ...@@ -37,7 +38,22 @@ class DiffEditorHelperContribution extends Disposable implements IEditorContribu
this._register(this._diffEditor.onDidUpdateDiff(() => { this._register(this._diffEditor.onDidUpdateDiff(() => {
this._setState(this._deduceState(this._diffEditor.getDiffComputationResult())); const diffComputationResult = this._diffEditor.getDiffComputationResult();
this._setState(this._deduceState(diffComputationResult));
if (diffComputationResult && diffComputationResult.quitEarly) {
this._notificationService.prompt(
Severity.Warning,
nls.localize('hintTimeout', "The diff algorithm was stopped early (after {0} ms.)", this._diffEditor.maxComputationTime),
[{
label: nls.localize('removeTimeout', "Remove limit"),
run: () => {
this._configurationService.updateValue('diffEditor.maxComputationTime', 0, ConfigurationTarget.USER);
}
}],
{}
);
}
})); }));
} }
...@@ -48,9 +64,6 @@ class DiffEditorHelperContribution extends Disposable implements IEditorContribu ...@@ -48,9 +64,6 @@ class DiffEditorHelperContribution extends Disposable implements IEditorContribu
if (this._diffEditor.ignoreTrimWhitespace && diffComputationResult.changes.length === 0 && !diffComputationResult.identical) { if (this._diffEditor.ignoreTrimWhitespace && diffComputationResult.changes.length === 0 && !diffComputationResult.identical) {
return WidgetState.HintWhitespace; return WidgetState.HintWhitespace;
} }
if (diffComputationResult.quitEarly) {
return WidgetState.HintTimeout;
}
return WidgetState.Hidden; return WidgetState.Hidden;
} }
...@@ -75,21 +88,12 @@ class DiffEditorHelperContribution extends Disposable implements IEditorContribu ...@@ -75,21 +88,12 @@ class DiffEditorHelperContribution extends Disposable implements IEditorContribu
this._helperWidgetListener = this._helperWidget.onClick(() => this._onDidClickHelperWidget()); this._helperWidgetListener = this._helperWidget.onClick(() => this._onDidClickHelperWidget());
this._helperWidget.render(); this._helperWidget.render();
} }
if (this._state === WidgetState.HintTimeout) {
this._helperWidget = this._instantiationService.createInstance(FloatingClickWidget, this._diffEditor.getModifiedEditor(), nls.localize('hintTimeout', "Remove diff computation timeout"), null);
this._helperWidgetListener = this._helperWidget.onClick(() => this._onDidClickHelperWidget());
this._helperWidget.render();
}
} }
private _onDidClickHelperWidget(): void { private _onDidClickHelperWidget(): void {
if (this._state === WidgetState.HintWhitespace) { if (this._state === WidgetState.HintWhitespace) {
this._configurationService.updateValue('diffEditor.ignoreTrimWhitespace', false, ConfigurationTarget.USER); this._configurationService.updateValue('diffEditor.ignoreTrimWhitespace', false, ConfigurationTarget.USER);
} }
if (this._state === WidgetState.HintTimeout) {
this._configurationService.updateValue('diffEditor.maxComputationTime', 0, ConfigurationTarget.USER);
}
} }
dispose(): void { dispose(): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册