Skip to content

Commit

Permalink
Change openEditor to return undefined instead of null
Browse files Browse the repository at this point in the history
For #70020
  • Loading branch information
mjbvz committed Aug 15, 2019
1 parent 9649fa5 commit d145b27
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/debug/browser/breakpointsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ class FunctionBreakpointInputRenderer implements IListRenderer<IFunctionBreakpoi
}
}

export function openBreakpointSource(breakpoint: IBreakpoint, sideBySide: boolean, preserveFocus: boolean, debugService: IDebugService, editorService: IEditorService): Promise<IEditor | null> {
export function openBreakpointSource(breakpoint: IBreakpoint, sideBySide: boolean, preserveFocus: boolean, debugService: IDebugService, editorService: IEditorService): Promise<IEditor | undefined> {
if (breakpoint.uri.scheme === DEBUG_SCHEME && debugService.state === State.Inactive) {
return Promise.resolve(null);
return Promise.resolve(undefined);
}

const selection = breakpoint.endLineNumber ? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class Launch extends AbstractLaunch implements ILaunch {
pinned: created,
revealIfVisible: true
},
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP).then(editor => ({ editor, created })));
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP).then(editor => ({ editor: withUndefinedAsNull(editor), created })));
}, (error: Error) => {
throw new Error(nls.localize('DebugConfig.failed', "Unable to create 'launch.json' file inside the '.vscode' folder ({0}).", error.message));
});
Expand Down Expand Up @@ -614,7 +614,7 @@ class WorkspaceLaunch extends AbstractLaunch implements ILaunch {
return this.editorService.openEditor({
resource: this.contextService.getWorkspace().configuration!,
options: { preserveFocus }
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP).then(editor => ({ editor, created: false }));
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP).then(editor => ({ editor: withUndefinedAsNull(editor), created: false }));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/debug/common/debugSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/
import { Schemas } from 'vs/base/common/network';
import { isUri } from 'vs/workbench/contrib/debug/common/debugUtils';
import { ITextEditor } from 'vs/workbench/common/editor';
import { withUndefinedAsNull } from 'vs/base/common/types';

export const UNKNOWN_SOURCE_LABEL = nls.localize('unknownSource', "Unknown Source");

Expand Down Expand Up @@ -104,7 +105,7 @@ export class Source {
revealInCenterIfOutsideViewport: true,
pinned: pinned || (!preserveFocus && !this.inMemory)
}
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP);
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP).then(withUndefinedAsNull);
}

static getEncodedDebugData(modelUri: uri): { name: string, path: string, sessionId?: string, sourceReference?: number } {
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/contrib/files/browser/explorerViewlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { ViewletPanel } from 'vs/workbench/browser/parts/views/panelViewlet';
import { KeyChord, KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { Registry } from 'vs/platform/registry/common/platform';
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
import { withUndefinedAsNull } from 'vs/base/common/types';

export class ExplorerViewletViewsContribution extends Disposable implements IWorkbenchContribution {

Expand Down Expand Up @@ -202,7 +203,7 @@ export class ExplorerViewlet extends ViewContainerViewlet {
openEditorsView.setStructuralRefreshDelay(delay);
}

let openedEditor: IEditor | null = null;
let openedEditor: IEditor | undefined;
try {
openedEditor = await this.editorService.openEditor(editor, options, group);
} catch (error) {
Expand All @@ -214,7 +215,7 @@ export class ExplorerViewlet extends ViewContainerViewlet {
}
}

return openedEditor;
return withUndefinedAsNull(openedEditor);
});

const explorerInstantiator = this.instantiationService.createChild(new ServiceCollection([IEditorService, delegatingEditorService]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ export class KeyboardLayoutPickerAction extends Action {

await this.fileService.resolve(file).then(undefined, (error) => {
return this.fileService.createFile(file, VSBuffer.fromString(KeyboardLayoutPickerAction.DEFAULT_CONTENT));
}).then((stat): Promise<IEditor | null> | null => {
}).then((stat): Promise<IEditor | undefined> | undefined => {
if (!stat) {
return null;
return undefined;
}
return this.editorService.openEditor({
resource: stat.resource,
Expand Down
18 changes: 9 additions & 9 deletions src/vs/workbench/services/editor/browser/editorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ export class EditorService extends Disposable implements EditorServiceImpl {

//#region openEditor()

openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditor | null>;
openEditor(editor: IResourceInput | IUntitledResourceInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextEditor | null>;
openEditor(editor: IResourceDiffInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextDiffEditor | null>;
openEditor(editor: IResourceSideBySideInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextSideBySideEditor | null>;
openEditor(editor: IEditorInput | IResourceEditor, optionsOrGroup?: IEditorOptions | ITextEditorOptions | IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE, group?: GroupIdentifier): Promise<IEditor | null> {
openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditor | undefined>;
openEditor(editor: IResourceInput | IUntitledResourceInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextEditor | undefined>;
openEditor(editor: IResourceDiffInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextDiffEditor | undefined>;
openEditor(editor: IResourceSideBySideInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextSideBySideEditor | undefined>;
openEditor(editor: IEditorInput | IResourceEditor, optionsOrGroup?: IEditorOptions | ITextEditorOptions | IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE, group?: GroupIdentifier): Promise<IEditor | undefined> {

// Typed Editor Support
if (editor instanceof EditorInput) {
Expand All @@ -240,11 +240,11 @@ export class EditorService extends Disposable implements EditorServiceImpl {
return this.doOpenEditor(targetGroup, typedInput, editorOptions);
}

return Promise.resolve(null);
return Promise.resolve(undefined);
}

protected doOpenEditor(group: IEditorGroup, editor: IEditorInput, options?: IEditorOptions): Promise<IEditor | null> {
return group.openEditor(editor, options);
protected doOpenEditor(group: IEditorGroup, editor: IEditorInput, options?: IEditorOptions): Promise<IEditor | undefined> {
return group.openEditor(editor, options).then(withNullAsUndefined);
}

private findTargetGroup(input: IEditorInput, options?: IEditorOptions, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): IEditorGroup {
Expand Down Expand Up @@ -651,7 +651,7 @@ export class DelegatingEditorService extends EditorService {
this.editorOpenHandler = handler;
}

protected async doOpenEditor(group: IEditorGroup, editor: IEditorInput, options?: IEditorOptions): Promise<IEditor | null> {
protected async doOpenEditor(group: IEditorGroup, editor: IEditorInput, options?: IEditorOptions): Promise<IEditor | undefined> {
if (!this.editorOpenHandler) {
return super.doOpenEditor(group, editor, options);
}
Expand Down
10 changes: 5 additions & 5 deletions src/vs/workbench/services/editor/common/editorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ export interface IEditorService {
* active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side
* of the currently active group.
*
* @returns the editor that opened or NULL if the operation failed or the editor was not
* @returns the editor that opened or `undefined` if the operation failed or the editor was not
* opened to be active.
*/
openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditor | null>;
openEditor(editor: IResourceInput | IUntitledResourceInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextEditor | null>;
openEditor(editor: IResourceDiffInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextDiffEditor | null>;
openEditor(editor: IResourceSideBySideInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextSideBySideEditor | null>;
openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditor | undefined>;
openEditor(editor: IResourceInput | IUntitledResourceInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextEditor | undefined>;
openEditor(editor: IResourceDiffInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextDiffEditor | undefined>;
openEditor(editor: IResourceSideBySideInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextSideBySideEditor | undefined>;

/**
* Open editors in an editor group.
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/services/history/browser/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export class HistoryService extends Disposable implements IHistoryService {
this.doNavigate(this.stack[this.index], !acrossEditors).finally(() => this.navigatingInStack = false);
}

private doNavigate(location: IStackEntry, withSelection: boolean): Promise<IBaseEditor | null> {
private doNavigate(location: IStackEntry, withSelection: boolean): Promise<IBaseEditor | undefined> {
const options: ITextEditorOptions = {
revealIfOpened: true // support to navigate across editor groups
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ export class PreferencesService extends Disposable implements IPreferencesServic
return null;
}

openRawDefaultSettings(): Promise<IEditor | null> {
openRawDefaultSettings(): Promise<IEditor | undefined> {
return this.editorService.openEditor({ resource: this.defaultSettingsRawResource });
}

openRawUserSettings(): Promise<IEditor | null> {
openRawUserSettings(): Promise<IEditor | undefined> {
return this.editorService.openEditor({ resource: this.userSettingsResource });
}

Expand Down Expand Up @@ -232,7 +232,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
const environment = await this.remoteAgentService.getEnvironment();
if (environment) {
await this.createIfNotExists(environment.settingsPath, emptyEditableSettingsContent);
return this.editorService.openEditor({ resource: environment.settingsPath, options: { pinned: true, revealIfOpened: true } }).then(withNullAsUndefined);
return this.editorService.openEditor({ resource: environment.settingsPath, options: { pinned: true, revealIfOpened: true } });
}
return undefined;
}
Expand Down Expand Up @@ -307,7 +307,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
return this.editorService.openEditor(this.instantiationService.createInstance(KeybindingsEditorInput), { pinned: true, revealIfOpened: true }).then(() => undefined);
}

openDefaultKeybindingsFile(): Promise<IEditor | null> {
openDefaultKeybindingsFile(): Promise<IEditor | undefined> {
return this.editorService.openEditor({ resource: this.defaultKeybindingsResource, label: nls.localize('defaultKeybindings', "Default Keybindings") });
}

Expand Down Expand Up @@ -368,7 +368,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
this.editorService.openEditor(editableSettingsEditorInput, { pinned: true, revealIfOpened: true }, sideEditorGroup.id)
]).then(([defaultEditor, editor]) => withNullAsUndefined(editor));
} else {
return this.editorService.openEditor(editableSettingsEditorInput, SettingsEditorOptions.create(options), group).then(withNullAsUndefined);
return this.editorService.openEditor(editableSettingsEditorInput, SettingsEditorOptions.create(options), group);
}
});
}
Expand All @@ -385,7 +385,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
const defaultPreferencesEditorInput = this.instantiationService.createInstance(DefaultPreferencesEditorInput, this.getDefaultSettingsResource(configurationTarget));
const preferencesEditorInput = new PreferencesEditorInput(this.getPreferencesEditorInputName(configurationTarget, resource), editableSettingsEditorInput.getDescription(), defaultPreferencesEditorInput, <EditorInput>editableSettingsEditorInput);
this.lastOpenedSettingsInput = preferencesEditorInput;
return this.editorService.openEditor(preferencesEditorInput, SettingsEditorOptions.create(options), group).then(withNullAsUndefined);
return this.editorService.openEditor(preferencesEditorInput, SettingsEditorOptions.create(options), group);
});
}

Expand All @@ -401,7 +401,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
folderUri
};

return this.editorService.openEditor(input, SettingsEditorOptions.create(settingsOptions), group).then(withNullAsUndefined);
return this.editorService.openEditor(input, SettingsEditorOptions.create(settingsOptions), group);
}

private async doSwitchSettings(target: ConfigurationTarget, resource: URI, input: PreferencesEditorInput, group: IEditorGroup, options?: ISettingsEditorOptions): Promise<IEditor> {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/services/preferences/common/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ export interface IPreferencesService {
createPreferencesEditorModel<T>(uri: URI): Promise<IPreferencesEditorModel<T> | null>;
createSettings2EditorModel(): Settings2EditorModel; // TODO

openRawDefaultSettings(): Promise<IEditor | null>;
openRawDefaultSettings(): Promise<IEditor | undefined>;
openSettings(jsonEditor: boolean | undefined, query: string | undefined): Promise<IEditor | undefined>;
openGlobalSettings(jsonEditor?: boolean, options?: ISettingsEditorOptions, group?: IEditorGroup): Promise<IEditor | undefined>;
openRemoteSettings(): Promise<IEditor | undefined>;
openWorkspaceSettings(jsonEditor?: boolean, options?: ISettingsEditorOptions, group?: IEditorGroup): Promise<IEditor | undefined>;
openFolderSettings(folder: URI, jsonEditor?: boolean, options?: ISettingsEditorOptions, group?: IEditorGroup): Promise<IEditor | undefined>;
switchSettings(target: ConfigurationTarget, resource: URI, jsonEditor?: boolean): Promise<void>;
openGlobalKeybindingSettings(textual: boolean): Promise<void>;
openDefaultKeybindingsFile(): Promise<IEditor | null>;
openDefaultKeybindingsFile(): Promise<IEditor | undefined>;

configureSettingsForLanguage(language: string | null): void;
}
Expand Down

0 comments on commit d145b27

Please sign in to comment.