Skip to content

Commit bfee5ac

Browse files
author
Benjamin Pasero
committed
debt - cleanup outputpanel instantiation override
1 parent 6861571 commit bfee5ac

5 files changed

Lines changed: 33 additions & 36 deletions

File tree

src/vs/workbench/browser/parts/editor/textEditor.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,12 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor {
4444
private editorMemento: IEditorMemento<IEditorViewState>;
4545
private inputDisposable: IDisposable | undefined;
4646

47-
// Allow subclasses to provide a different (e.g. scoped)
48-
// instantiation service for this abstract text editor
49-
protected get instantiationService(): IInstantiationService {
50-
return this._instantiationService;
51-
}
52-
5347
constructor(
5448
id: string,
5549
@ITelemetryService telemetryService: ITelemetryService,
56-
@IInstantiationService private readonly _instantiationService: IInstantiationService,
50+
@IInstantiationService protected readonly instantiationService: IInstantiationService,
5751
@IStorageService storageService: IStorageService,
58-
@ITextResourceConfigurationService protected readonly configurationService: ITextResourceConfigurationService,
52+
@ITextResourceConfigurationService protected readonly textResourceConfigurationService: ITextResourceConfigurationService,
5953
@IThemeService protected themeService: IThemeService,
6054
@IEditorService protected editorService: IEditorService,
6155
@IEditorGroupsService protected editorGroupService: IEditorGroupsService
@@ -64,9 +58,9 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor {
6458

6559
this.editorMemento = this.getEditorMemento<IEditorViewState>(editorGroupService, BaseTextEditor.TEXT_EDITOR_VIEW_STATE_PREFERENCE_KEY, 100);
6660

67-
this._register(this.configurationService.onDidChangeConfiguration(e => {
61+
this._register(this.textResourceConfigurationService.onDidChangeConfiguration(e => {
6862
const resource = this.getResource();
69-
const value = resource ? this.configurationService.getValue<IEditorConfiguration>(resource) : undefined;
63+
const value = resource ? this.textResourceConfigurationService.getValue<IEditorConfiguration>(resource) : undefined;
7064

7165
return this.handleConfigurationChangeEvent(value);
7266
}));
@@ -123,7 +117,7 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor {
123117

124118
// Editor for Text
125119
this.editorContainer = parent;
126-
this.editorControl = this._register(this.createEditorControl(parent, this.computeConfiguration(this.configurationService.getValue<IEditorConfiguration>(this.getResource()))));
120+
this.editorControl = this._register(this.createEditorControl(parent, this.computeConfiguration(this.textResourceConfigurationService.getValue<IEditorConfiguration>(this.getResource()))));
127121

128122
// Model & Language changes
129123
const codeEditor = getCodeEditor(this.editorControl);
@@ -265,7 +259,7 @@ export abstract class BaseTextEditor extends BaseEditor implements ITextEditor {
265259
if (!configuration) {
266260
const resource = this.getResource();
267261
if (resource) {
268-
configuration = this.configurationService.getValue<IEditorConfiguration>(resource);
262+
configuration = this.textResourceConfigurationService.getValue<IEditorConfiguration>(resource);
269263
}
270264
}
271265

src/vs/workbench/browser/parts/editor/textResourceEditor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ export class AbstractTextResourceEditor extends BaseTextEditor {
3333
@ITelemetryService telemetryService: ITelemetryService,
3434
@IInstantiationService instantiationService: IInstantiationService,
3535
@IStorageService storageService: IStorageService,
36-
@ITextResourceConfigurationService configurationService: ITextResourceConfigurationService,
36+
@ITextResourceConfigurationService textResourceConfigurationService: ITextResourceConfigurationService,
3737
@IThemeService themeService: IThemeService,
3838
@IEditorGroupsService editorGroupService: IEditorGroupsService,
3939
@IEditorService editorService: IEditorService
4040
) {
41-
super(id, telemetryService, instantiationService, storageService, configurationService, themeService, editorService, editorGroupService);
41+
super(id, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorService, editorGroupService);
4242
}
4343

4444
getTitle(): string | undefined {
@@ -184,11 +184,11 @@ export class TextResourceEditor extends AbstractTextResourceEditor {
184184
@ITelemetryService telemetryService: ITelemetryService,
185185
@IInstantiationService instantiationService: IInstantiationService,
186186
@IStorageService storageService: IStorageService,
187-
@ITextResourceConfigurationService configurationService: ITextResourceConfigurationService,
187+
@ITextResourceConfigurationService textResourceConfigurationService: ITextResourceConfigurationService,
188188
@IThemeService themeService: IThemeService,
189189
@IEditorService editorService: IEditorService,
190190
@IEditorGroupsService editorGroupService: IEditorGroupsService
191191
) {
192-
super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, editorGroupService, editorService);
192+
super(TextResourceEditor.ID, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorGroupService, editorService);
193193
}
194194
}

src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class TextFileEditor extends BaseTextEditor {
7878
}
7979

8080
private updateRestoreViewStateConfiguration(): void {
81-
this.restoreViewState = this.configurationService.getValue(undefined, 'workbench.editor.restoreViewState');
81+
this.restoreViewState = this.textResourceConfigurationService.getValue(undefined, 'workbench.editor.restoreViewState');
8282
}
8383

8484
getTitle(): string {

src/vs/workbench/contrib/files/electron-browser/textFileEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class NativeTextFileEditor extends TextFileEditor {
5353

5454
// Allow to restart with higher memory limit if the file is too large
5555
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_EXCEEDS_MEMORY_LIMIT) {
56-
const memoryLimit = Math.max(MIN_MAX_MEMORY_SIZE_MB, +this.configurationService.getValue<number>(undefined, 'files.maxMemoryForLargeFilesMB') || FALLBACK_MAX_MEMORY_SIZE_MB);
56+
const memoryLimit = Math.max(MIN_MAX_MEMORY_SIZE_MB, +this.textResourceConfigurationService.getValue<number>(undefined, 'files.maxMemoryForLargeFilesMB') || FALLBACK_MAX_MEMORY_SIZE_MB);
5757

5858
throw createErrorWithActions(nls.localize('fileTooLargeForHeapError', "To open a file of this size, you need to restart and allow it to use more memory"), {
5959
actions: [

src/vs/workbench/contrib/output/browser/outputPanel.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
2626
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
2727

2828
export class OutputPanel extends AbstractTextResourceEditor {
29+
2930
private actions: IAction[] | undefined;
31+
32+
// Override the instantiation service to use to be the scoped one
3033
private scopedInstantiationService: IInstantiationService;
31-
private _focus = false;
34+
protected get instantiationService(): IInstantiationService { return this.scopedInstantiationService; }
35+
protected set instantiationService(instantiationService: IInstantiationService) { }
3236

3337
constructor(
3438
@ITelemetryService telemetryService: ITelemetryService,
3539
@IInstantiationService instantiationService: IInstantiationService,
3640
@IStorageService storageService: IStorageService,
37-
@IConfigurationService private readonly baseConfigurationService: IConfigurationService,
41+
@IConfigurationService private readonly configurationService: IConfigurationService,
3842
@ITextResourceConfigurationService textResourceConfigurationService: ITextResourceConfigurationService,
3943
@IThemeService themeService: IThemeService,
4044
@IOutputService private readonly outputService: IOutputService,
@@ -44,14 +48,11 @@ export class OutputPanel extends AbstractTextResourceEditor {
4448
) {
4549
super(OUTPUT_PANEL_ID, telemetryService, instantiationService, storageService, textResourceConfigurationService, themeService, editorGroupService, editorService);
4650

51+
// Initially, the scoped instantiation service is the global
52+
// one until the editor is created later on
4753
this.scopedInstantiationService = instantiationService;
4854
}
4955

50-
protected get instantiationService(): IInstantiationService {
51-
// Override instantiation service with our scoped service
52-
return this.scopedInstantiationService;
53-
}
54-
5556
getId(): string {
5657
return OUTPUT_PANEL_ID;
5758
}
@@ -63,10 +64,10 @@ export class OutputPanel extends AbstractTextResourceEditor {
6364
getActions(): IAction[] {
6465
if (!this.actions) {
6566
this.actions = [
66-
this.instantiationService.createInstance(SwitchOutputAction),
67-
this.instantiationService.createInstance(ClearOutputAction, ClearOutputAction.ID, ClearOutputAction.LABEL),
68-
this.instantiationService.createInstance(ToggleOrSetOutputScrollLockAction, ToggleOrSetOutputScrollLockAction.ID, ToggleOrSetOutputScrollLockAction.LABEL),
69-
this.instantiationService.createInstance(OpenLogOutputFile)
67+
this.scopedInstantiationService.createInstance(SwitchOutputAction),
68+
this.scopedInstantiationService.createInstance(ClearOutputAction, ClearOutputAction.ID, ClearOutputAction.LABEL),
69+
this.scopedInstantiationService.createInstance(ToggleOrSetOutputScrollLockAction, ToggleOrSetOutputScrollLockAction.ID, ToggleOrSetOutputScrollLockAction.LABEL),
70+
this.scopedInstantiationService.createInstance(OpenLogOutputFile)
7071
];
7172

7273
this.actions.forEach(a => this._register(a));
@@ -77,7 +78,7 @@ export class OutputPanel extends AbstractTextResourceEditor {
7778

7879
getActionViewItem(action: Action): IActionViewItem | undefined {
7980
if (action.id === SwitchOutputAction.ID) {
80-
return this.instantiationService.createInstance(SwitchOutputActionViewItem, action);
81+
return this.scopedInstantiationService.createInstance(SwitchOutputActionViewItem, action);
8182
}
8283

8384
return super.getActionViewItem(action);
@@ -95,7 +96,7 @@ export class OutputPanel extends AbstractTextResourceEditor {
9596
options.renderLineHighlight = 'none';
9697
options.minimap = { enabled: false };
9798

98-
const outputConfig = this.baseConfigurationService.getValue<any>('[Log]');
99+
const outputConfig = this.configurationService.getValue<any>('[Log]');
99100
if (outputConfig) {
100101
if (outputConfig['editor.minimap.enabled']) {
101102
options.minimap = { enabled: true };
@@ -115,17 +116,17 @@ export class OutputPanel extends AbstractTextResourceEditor {
115116
}
116117

117118
async setInput(input: EditorInput, options: EditorOptions | undefined, token: CancellationToken): Promise<void> {
118-
this._focus = !(options && options.preserveFocus);
119+
const focus = !(options && options.preserveFocus);
119120
if (input.matches(this.input)) {
120-
return Promise.resolve(undefined);
121+
return;
121122
}
122123

123124
if (this.input) {
124125
// Dispose previous input (Output panel is not a workbench editor)
125126
this.input.dispose();
126127
}
127128
await super.setInput(input, options, token);
128-
if (this._focus) {
129+
if (focus) {
129130
this.focus();
130131
}
131132
this.revealLastLine();
@@ -140,15 +141,17 @@ export class OutputPanel extends AbstractTextResourceEditor {
140141
}
141142

142143
protected createEditor(parent: HTMLElement): void {
144+
143145
// First create the scoped instantiation service and only then construct the editor using the scoped service
144146
const scopedContextKeyService = this._register(this.contextKeyService.createScoped(parent));
145147
this.scopedInstantiationService = this.instantiationService.createChild(new ServiceCollection([IContextKeyService, scopedContextKeyService]));
148+
146149
super.createEditor(parent);
147150

148151
CONTEXT_IN_OUTPUT.bindTo(scopedContextKeyService).set(true);
149152

150153
const codeEditor = <ICodeEditor>this.getControl();
151-
codeEditor.onDidChangeCursorPosition((e) => {
154+
this._register(codeEditor.onDidChangeCursorPosition((e) => {
152155
if (e.reason !== CursorChangeReason.Explicit) {
153156
return;
154157
}
@@ -161,6 +164,6 @@ export class OutputPanel extends AbstractTextResourceEditor {
161164
const lockAction = this.actions.filter((action) => action.id === ToggleOrSetOutputScrollLockAction.ID)[0];
162165
lockAction.run(newLockState);
163166
}
164-
});
167+
}));
165168
}
166169
}

0 commit comments

Comments
 (0)