Merge from vscode 3c6f6af7347d38e87bc6406024e8dcf9e9bce229 (#8962)

* Merge from vscode 3c6f6af7347d38e87bc6406024e8dcf9e9bce229

* skip failing tests

* update mac build image
This commit is contained in:
Anthony Dresser
2020-01-27 15:28:17 -08:00
committed by Karl Burtram
parent 0eaee18dc4
commit fefe1454de
481 changed files with 12764 additions and 7836 deletions

View File

@@ -3,6 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { Event, Emitter } from 'vs/base/common/event';
import { assign } from 'vs/base/common/objects';
import { withNullAsUndefined, assertIsDefined } from 'vs/base/common/types';
@@ -298,15 +299,6 @@ export const enum SaveReason {
WINDOW_CHANGE = 4
}
export const enum SaveContext {
/**
* Indicates that the editor is saved because it
* is being closed by the user.
*/
EDITOR_CLOSE = 1,
}
export interface ISaveOptions {
/**
@@ -314,11 +306,6 @@ export interface ISaveOptions {
*/
reason?: SaveReason;
/**
* Additional information about the context of the save.
*/
context?: SaveContext;
/**
* Forces to save the contents of the working copy
* again even if the working copy is not dirty.
@@ -361,6 +348,16 @@ export interface IEditorInput extends IDisposable {
*/
readonly onDispose: Event<void>;
/**
* Triggered when this input changes its dirty state.
*/
readonly onDidChangeDirty: Event<void>;
/**
* Triggered when this input changes its label
*/
readonly onDidChangeLabel: Event<void>;
/**
* Returns the associated resource of this input.
*/
@@ -415,23 +412,29 @@ export interface IEditorInput extends IDisposable {
isSaving(): boolean;
/**
* Saves the editor. The provided groupId helps
* implementors to e.g. preserve view state of the editor
* and re-open it in the correct group after saving.
* Saves the editor. The provided groupId helps implementors
* to e.g. preserve view state of the editor and re-open it
* in the correct group after saving.
*
* @returns the resulting editor input of this operation. Can
* be the same editor input.
*/
save(groupId: GroupIdentifier, options?: ISaveOptions): Promise<boolean>;
save(group: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined>;
/**
* Saves the editor to a different location. The provided groupId
* helps implementors to e.g. preserve view state of the editor
* and re-open it in the correct group after saving.
*
* @returns the resulting editor input of this operation. Typically
* a different editor input.
*/
saveAs(groupId: GroupIdentifier, options?: ISaveOptions): Promise<boolean>;
saveAs(group: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined>;
/**
* Reverts this input.
* Reverts this input from the provided group.
*/
revert(options?: IRevertOptions): Promise<boolean>;
revert(group: GroupIdentifier, options?: IRevertOptions): Promise<boolean>;
/**
* Returns if the other object matches this input.
@@ -523,15 +526,15 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
return false;
}
async save(groupId: GroupIdentifier, options?: ISaveOptions): Promise<boolean> {
return true;
async save(group: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
return this;
}
async saveAs(groupId: GroupIdentifier, options?: ISaveOptions): Promise<boolean> {
return true;
async saveAs(group: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
return this;
}
async revert(options?: IRevertOptions): Promise<boolean> {
async revert(group: GroupIdentifier, options?: IRevertOptions): Promise<boolean> {
return true;
}
@@ -551,8 +554,10 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
}
dispose(): void {
this.disposed = true;
this._onDispose.fire();
if (!this.disposed) {
this.disposed = true;
this._onDispose.fire();
}
super.dispose();
}
@@ -573,43 +578,37 @@ export abstract class TextEditorInput extends EditorInput {
return this.resource;
}
async save(groupId: GroupIdentifier, options?: ITextFileSaveOptions): Promise<boolean> {
return this.textFileService.save(this.resource, options);
async save(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise<IEditorInput | undefined> {
return this.doSave(group, options, false);
}
saveAs(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise<boolean> {
return this.doSaveAs(group, options, () => this.textFileService.saveAs(this.resource, undefined, options));
saveAs(group: GroupIdentifier, options?: ITextFileSaveOptions): Promise<IEditorInput | undefined> {
return this.doSave(group, options, true);
}
protected async doSaveAs(group: GroupIdentifier, options: ISaveOptions | undefined, saveRunnable: () => Promise<URI | undefined>, replaceAllEditors?: boolean): Promise<boolean> {
private async doSave(group: GroupIdentifier, options: ISaveOptions | undefined, saveAs: boolean): Promise<IEditorInput | undefined> {
// Preserve view state by opening the editor first. In addition
// this allows the user to review the contents of the editor.
let viewState: IEditorViewState | undefined = undefined;
const editor = await this.editorService.openEditor(this, undefined, group);
if (isTextEditor(editor)) {
viewState = editor.getViewState();
// Save / Save As
let target: URI | undefined;
if (saveAs) {
target = await this.textFileService.saveAs(this.resource, undefined, options);
} else {
target = await this.textFileService.save(this.resource, options);
}
// Save as
const target = await saveRunnable();
if (!target) {
return false; // save cancelled
return undefined; // save cancelled
}
// Replace editor preserving viewstate (either across all groups or
// only selected group) if the target is different from the current resource
// and if the editor is not being saved because it is being closed
// (because in that case we do not want to open a different editor anyway)
if (options?.context !== SaveContext.EDITOR_CLOSE && !isEqual(target, this.resource)) {
const replacement = this.editorService.createInput({ resource: target });
const targetGroups = replaceAllEditors ? this.editorGroupService.groups.map(group => group.id) : [group];
for (const group of targetGroups) {
await this.editorService.replaceEditors([{ editor: this, replacement, options: { pinned: true, viewState } }], group);
}
if (!isEqual(target, this.resource)) {
return this.editorService.createInput({ resource: target });
}
return true;
return this;
}
revert(group: GroupIdentifier, options?: IRevertOptions): Promise<boolean> {
return this.textFileService.revert(this.resource, options);
}
}
@@ -682,7 +681,7 @@ export class SideBySideEditorInput extends EditorInput {
static readonly ID: string = 'workbench.editorinputs.sidebysideEditorInput';
constructor(
private readonly name: string,
protected readonly name: string | undefined,
private readonly description: string | undefined,
private readonly _details: EditorInput,
private readonly _master: EditorInput
@@ -700,6 +699,22 @@ export class SideBySideEditorInput extends EditorInput {
return this._details;
}
getTypeId(): string {
return SideBySideEditorInput.ID;
}
getName(): string {
if (!this.name) {
return localize('sideBySideLabels', "{0} - {1}", this._details.getName(), this._master.getName());
}
return this.name;
}
getDescription(): string | undefined {
return this.description;
}
isReadonly(): boolean {
return this.master.isReadonly();
}
@@ -716,16 +731,16 @@ export class SideBySideEditorInput extends EditorInput {
return this.master.isSaving();
}
save(groupId: GroupIdentifier, options?: ISaveOptions): Promise<boolean> {
return this.master.save(groupId, options);
save(group: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
return this.master.save(group, options);
}
saveAs(groupId: GroupIdentifier, options?: ISaveOptions): Promise<boolean> {
return this.master.saveAs(groupId, options);
saveAs(group: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
return this.master.saveAs(group, options);
}
revert(options?: IRevertOptions): Promise<boolean> {
return this.master.revert(options);
revert(group: GroupIdentifier, options?: IRevertOptions): Promise<boolean> {
return this.master.revert(group, options);
}
getTelemetryDescriptor(): { [key: string]: unknown } {
@@ -760,18 +775,6 @@ export class SideBySideEditorInput extends EditorInput {
return null;
}
getTypeId(): string {
return SideBySideEditorInput.ID;
}
getName(): string {
return this.name;
}
getDescription(): string | undefined {
return this.description;
}
matches(otherInput: unknown): boolean {
if (super.matches(otherInput) === true) {
return true;