diff --git a/src/vs/editor/browser/services/codeEditorService.ts b/src/vs/editor/browser/services/codeEditorService.ts index a04318b748f1a852c92050d0632721f7ba4a67b9..69972231ce7be687198a18eb9f9e363c40e84f08 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 3fe4d646ddc50676becdcae143c3ef2d41e05731..006fcc3c3a5906a0c16b12b137c7db6afa2dc203 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 7f039a12bc53df4191c1da09303dc327e2c62d84..1946ac227c41a672c417218f0cff4e4912cec7d6 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 8adc96a167e74c532c55c3d0c37bc6467ce904c1..c7b8599ee197a042d670308500334b55ba1f8e72 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 a5e81ad27325e29962970cbf3c9cd1ee16d41a60..8afe20a82c51a221e3074aae39ba8b9c24914984 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 f730d35c1daeb0178a93d2c0299fe05fd8cfcb62..347f72014563b0ef27943563afb396f53968acda 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 3699692cd51af73248284bc9f57645baaf3acd9c..42edc13f213e911c2eeda3b95ddfde193273860c 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 f4d1a37cd265ccd2ad4593c81ccb52dcece44e81..6d66fcc876fdbcc0543418f47c9660b1c92ccbd6 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; } }