From 8bb9ce0caf63f998107f858d12f5bb21368999e1 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 18 May 2018 09:12:48 +0200 Subject: [PATCH] grid - some cleanup --- .../browser/services/codeEditorService.ts | 17 ++++++-------- src/vs/workbench/browser/composite.ts | 5 ++-- .../browser/parts/editor/textDiffEditor.ts | 15 ++++-------- .../browser/parts/editor/textEditor.ts | 14 ++++------- src/vs/workbench/common/composite.ts | 8 +++++-- src/vs/workbench/common/editor.ts | 3 ++- .../parts/debug/browser/debugCommands.ts | 13 ++++------- .../debugConfigurationManager.ts | 23 ++++++++----------- 8 files changed, 42 insertions(+), 56 deletions(-) diff --git a/src/vs/editor/browser/services/codeEditorService.ts b/src/vs/editor/browser/services/codeEditorService.ts index a04318b748f..69972231ce7 100644 --- a/src/vs/editor/browser/services/codeEditorService.ts +++ b/src/vs/editor/browser/services/codeEditorService.ts @@ -48,9 +48,14 @@ export interface ICodeEditorService { } /** - * Uses `editor.getControl()` and returns either a `codeEditor` or a `diffEditor` or nothing. + * Uses `editor.getControl()` and returns either the code editor, or the modified editor of a diff editor or nothing. */ -export function getCodeOrDiffEditor(editor: { getControl: () => any }): { codeEditor: ICodeEditor; diffEditor: IDiffEditor } { +export function getCodeEditor(editor: { getControl: () => any }): ICodeEditor { + let r = getCodeOrDiffEditor(editor); + return r.codeEditor || (r.diffEditor && r.diffEditor.getModifiedEditor()) || null; +} + +function getCodeOrDiffEditor(editor: { getControl: () => any }): { codeEditor: ICodeEditor; diffEditor: IDiffEditor } { if (editor) { let control = editor.getControl(); if (control) { @@ -74,11 +79,3 @@ export function getCodeOrDiffEditor(editor: { getControl: () => any }): { codeEd diffEditor: null }; } - -/** - * Uses `editor.getControl()` and returns either the code editor, or the modified editor of a diff editor or nothing. - */ -export function getCodeEditor(editor: { getControl: () => any }): ICodeEditor { - let r = getCodeOrDiffEditor(editor); - return r.codeEditor || (r.diffEditor && r.diffEditor.getModifiedEditor()) || null; -} diff --git a/src/vs/workbench/browser/composite.ts b/src/vs/workbench/browser/composite.ts index 3fe4d646ddc..006fcc3c3a5 100644 --- a/src/vs/workbench/browser/composite.ts +++ b/src/vs/workbench/browser/composite.ts @@ -8,8 +8,7 @@ import { IAction, IActionRunner, ActionRunner } from 'vs/base/common/actions'; import { IActionItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { Component } from 'vs/workbench/common/component'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; -import { IComposite } from 'vs/workbench/common/composite'; -import { IEditorControl } from 'vs/workbench/common/editor'; +import { IComposite, ICompositeControl } from 'vs/workbench/common/composite'; import { Event, Emitter } from 'vs/base/common/event'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { IConstructorSignature0, IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -193,7 +192,7 @@ export abstract class Composite extends Component implements IComposite { /** * Returns the underlying composite control or null if it is not accessible. */ - public getControl(): IEditorControl { + public getControl(): ICompositeControl { return null; } diff --git a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts index 7f039a12bc5..1946ac227c4 100644 --- a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts @@ -35,7 +35,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { Registry } from 'vs/platform/registry/common/platform'; import URI from 'vs/base/common/uri'; -import { getCodeOrDiffEditor } from 'vs/editor/browser/services/codeEditorService'; import { once } from 'vs/base/common/event'; import { DelegatingWorkbenchEditorService } from 'vs/workbench/services/editor/browser/nextEditorService'; import { INextEditorGroup, INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService'; @@ -150,7 +149,7 @@ export class TextDiffEditor extends BaseTextEditor { } // Set Editor Model - const diffEditor = this.getControl(); + const diffEditor = this.getControl(); diffEditor.setModel((resolvedModel).textDiffEditorModel); // Apply Options from TextOptions @@ -192,7 +191,7 @@ export class TextDiffEditor extends BaseTextEditor { public setOptions(options: EditorOptions): void { const textOptions = options; if (textOptions && types.isFunction(textOptions.apply)) { - textOptions.apply(this.getControl(), ScrollType.Smooth); + textOptions.apply(this.getControl(), ScrollType.Smooth); } } @@ -367,12 +366,8 @@ export class TextDiffEditor extends BaseTextEditor { } private retrieveTextDiffEditorViewState(resource: URI): IDiffEditorViewState { - const editor = getCodeOrDiffEditor(this).diffEditor; - if (!editor) { - return null; // not supported for non-diff editors - } - - const model = editor.getModel(); + const control = this.getControl(); + const model = control.getModel(); if (!model || !model.modified || !model.original) { return null; // view state always needs a model } @@ -386,7 +381,7 @@ export class TextDiffEditor extends BaseTextEditor { return null; // prevent saving view state for a model that is not the expected one } - return editor.saveViewState(); + return control.saveViewState(); } private toDiffEditorViewStateResource(modelOrInput: IDiffEditorModel | DiffEditorInput): URI { diff --git a/src/vs/workbench/browser/parts/editor/textEditor.ts b/src/vs/workbench/browser/parts/editor/textEditor.ts index 8adc96a167e..c7b8599ee19 100644 --- a/src/vs/workbench/browser/parts/editor/textEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textEditor.ts @@ -20,11 +20,11 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { Scope } from 'vs/workbench/common/memento'; -import { getCodeEditor, getCodeOrDiffEditor } from 'vs/editor/browser/services/codeEditorService'; +import { getCodeEditor } from 'vs/editor/browser/services/codeEditorService'; import { ITextFileService, SaveReason, AutoSaveMode } from 'vs/workbench/services/textfile/common/textfiles'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; -import { isDiffEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser'; +import { isDiffEditor, isCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { INextEditorGroupsService, INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService'; import { CancellationToken } from 'vs/base/common/cancellation'; import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService'; @@ -238,12 +238,8 @@ export abstract class BaseTextEditor extends BaseEditor { } protected retrieveTextEditorViewState(resource: URI): IEditorViewState { - const editor = getCodeOrDiffEditor(this).codeEditor; - if (!editor) { - return null; // not supported for diff editors - } - - const model = editor.getModel(); + const control = this.getControl() as ICodeEditor; + const model = control.getModel(); if (!model) { return null; // view state always needs a model } @@ -257,7 +253,7 @@ export abstract class BaseTextEditor extends BaseEditor { return null; // prevent saving view state for a model that is not the expected one } - return editor.saveViewState(); + return control.saveViewState(); } /** diff --git a/src/vs/workbench/common/composite.ts b/src/vs/workbench/common/composite.ts index a5e81ad2732..8afe20a82c5 100644 --- a/src/vs/workbench/common/composite.ts +++ b/src/vs/workbench/common/composite.ts @@ -4,7 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import { IAction, IActionItem } from 'vs/base/common/actions'; -import { IEditorControl } from 'vs/workbench/common/editor'; export interface IComposite { @@ -41,10 +40,15 @@ export interface IComposite { /** * Returns the underlying control of this composite. */ - getControl(): IEditorControl; + getControl(): ICompositeControl; /** * Asks the underlying control to focus. */ focus(): void; } + +/** + * Marker interface for the composite control + */ +export interface ICompositeControl { } diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index f730d35c1da..347f7201456 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -19,6 +19,7 @@ import { ITextModel } from 'vs/editor/common/model'; import { Schemas } from 'vs/base/common/network'; import { LRUCache } from 'vs/base/common/map'; import { INextEditorGroupsService, INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService'; +import { ICompositeControl } from 'vs/workbench/common/composite'; export const EditorsVisibleContext = new RawContextKey('editorIsOpen', false); export const NoEditorsVisibleContext: ContextKeyExpr = EditorsVisibleContext.toNegated(); @@ -79,7 +80,7 @@ export interface IEditor { /** * Marker interface for the editor control */ -export interface IEditorControl { } +export interface IEditorControl extends ICompositeControl { } export interface IFileInputFactory { diff --git a/src/vs/workbench/parts/debug/browser/debugCommands.ts b/src/vs/workbench/parts/debug/browser/debugCommands.ts index 3699692cd51..42edc13f213 100644 --- a/src/vs/workbench/parts/debug/browser/debugCommands.ts +++ b/src/vs/workbench/parts/debug/browser/debugCommands.ts @@ -15,7 +15,7 @@ import { IDebugService, IEnablement, CONTEXT_BREAKPOINTS_FOCUSED, CONTEXT_WATCH_ import { Expression, Variable, Breakpoint, FunctionBreakpoint } from 'vs/workbench/parts/debug/common/debugModel'; import { IExtensionsViewlet, VIEWLET_ID as EXTENSIONS_VIEWLET_ID } from 'vs/workbench/parts/extensions/common/extensions'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; -import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; +import { ICodeEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser'; import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions'; import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; @@ -54,10 +54,8 @@ export function registerCommands(): void { handler: (accessor) => { const debugService = accessor.get(IDebugService); const editorService = accessor.get(INextEditorService); - const editor = editorService.activeControl; - const control = editor.getControl(); - - if (control) { + const control = editorService.activeTextEditorControl; + if (isCodeEditor(control)) { const model = control.getModel(); if (model) { const position = control.getPosition(); @@ -203,9 +201,8 @@ export function registerCommands(): void { const inlineBreakpointHandler = (accessor: ServicesAccessor) => { const debugService = accessor.get(IDebugService); const editorService = accessor.get(INextEditorService); - const editor = editorService.activeControl; - const control = editor && editor.getControl(); - if (control) { + const control = editorService.activeTextEditorControl; + if (isCodeEditor(control)) { const position = control.getPosition(); const modelUri = control.getModel().uri; const bp = debugService.getModel().getBreakpoints({ lineNumber: position.lineNumber, uri: modelUri }) diff --git a/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts b/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts index f4d1a37cd26..6d66fcc876f 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts @@ -328,20 +328,17 @@ export class ConfigurationManager implements IConfigurationManager { return TPromise.as(adapter); } - const editor = this.editorService.activeControl; + const codeEditor = this.editorService.activeTextEditorControl; let candidates: Debugger[]; - if (editor) { - const codeEditor = editor.getControl(); - if (isCodeEditor(codeEditor)) { - const model = codeEditor.getModel(); - const language = model ? model.getLanguageIdentifier().language : undefined; - const adapters = this.debuggers.filter(a => a.languages && a.languages.indexOf(language) >= 0); - if (adapters.length === 1) { - return TPromise.as(adapters[0]); - } - if (adapters.length > 1) { - candidates = adapters; - } + if (isCodeEditor(codeEditor)) { + const model = codeEditor.getModel(); + const language = model ? model.getLanguageIdentifier().language : undefined; + const adapters = this.debuggers.filter(a => a.languages && a.languages.indexOf(language) >= 0); + if (adapters.length === 1) { + return TPromise.as(adapters[0]); + } + if (adapters.length > 1) { + candidates = adapters; } } -- GitLab