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

@@ -9,11 +9,8 @@ import { basename } from 'vs/base/common/resources';
import { IFileService } from 'vs/platform/files/common/files';
import { IWindowOpenable } from 'vs/platform/windows/common/windows';
import { URI } from 'vs/base/common/uri';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { ITextFileService, stringToSnapshot } from 'vs/workbench/services/textfile/common/textfiles';
import { Schemas } from 'vs/base/common/network';
import { DefaultEndOfLine } from 'vs/editor/common/model';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEditorViewState } from 'vs/editor/common/editorCommon';
import { DataTransfers } from 'vs/base/browser/dnd';
import { DragMouseEvent } from 'vs/base/browser/mouseEvent';
@@ -31,6 +28,8 @@ import { IWorkspaceEditingService } from 'vs/workbench/services/workspaces/commo
import { withNullAsUndefined } from 'vs/base/common/types';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { isStandalone } from 'vs/base/browser/browser';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
export interface IDraggedResource {
resource: URI;
@@ -56,7 +55,7 @@ export class DraggedEditorGroupIdentifier {
}
export interface IDraggedEditor extends IDraggedResource {
backupResource?: URI;
content?: string;
encoding?: string;
mode?: string;
viewState?: IEditorViewState;
@@ -64,7 +63,7 @@ export interface IDraggedEditor extends IDraggedResource {
export interface ISerializedDraggedEditor {
resource: string;
backupResource?: string;
content?: string;
encoding?: string;
mode?: string;
viewState?: IEditorViewState;
@@ -90,7 +89,7 @@ export function extractResources(e: DragEvent, externalOnly?: boolean): Array<ID
draggedEditors.forEach(draggedEditor => {
resources.push({
resource: URI.parse(draggedEditor.resource),
backupResource: draggedEditor.backupResource ? URI.parse(draggedEditor.backupResource) : undefined,
content: draggedEditor.content,
viewState: draggedEditor.viewState,
encoding: draggedEditor.encoding,
mode: draggedEditor.mode,
@@ -171,7 +170,6 @@ export class ResourcesDropHandler {
@ITextFileService private readonly textFileService: ITextFileService,
@IBackupFileService private readonly backupFileService: IBackupFileService,
@IEditorService private readonly editorService: IEditorService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IWorkspaceEditingService private readonly workspaceEditingService: IWorkspaceEditingService,
@IHostService private readonly hostService: IHostService
) {
@@ -221,9 +219,9 @@ export class ResourcesDropHandler {
private async doHandleDrop(untitledOrFileResources: Array<IDraggedResource | IDraggedEditor>): Promise<boolean> {
// Check for dirty editors being dropped
const resourcesWithBackups: IDraggedEditor[] = untitledOrFileResources.filter(resource => !resource.isExternal && !!(resource as IDraggedEditor).backupResource);
if (resourcesWithBackups.length > 0) {
await Promise.all(resourcesWithBackups.map(resourceWithBackup => this.handleDirtyEditorDrop(resourceWithBackup)));
const resourcesWithContent: IDraggedEditor[] = untitledOrFileResources.filter(resource => !resource.isExternal && !!(resource as IDraggedEditor).content);
if (resourcesWithContent.length > 0) {
await Promise.all(resourcesWithContent.map(resourceWithContent => this.handleDirtyEditorDrop(resourceWithContent)));
return false;
}
@@ -245,16 +243,16 @@ export class ResourcesDropHandler {
droppedDirtyEditor.resource = this.textFileService.untitled.create({ mode: droppedDirtyEditor.mode, encoding: droppedDirtyEditor.encoding }).getResource();
}
// Return early if the resource is already dirty in target or opened already
if (this.textFileService.isDirty(droppedDirtyEditor.resource) || this.editorService.isOpen({ resource: droppedDirtyEditor.resource })) {
// File: ensure the file is not dirty or opened already
else if (this.textFileService.isDirty(droppedDirtyEditor.resource) || this.editorService.isOpen(this.editorService.createInput({ resource: droppedDirtyEditor.resource, forceFile: true }))) {
return false;
}
// Resolve the contents of the dropped dirty resource from source
if (droppedDirtyEditor.backupResource) {
// If the dropped editor is dirty with content we simply take that
// content and turn it into a backup so that it loads the contents
if (droppedDirtyEditor.content) {
try {
const content = await this.backupFileService.resolveBackupContent((droppedDirtyEditor.backupResource));
await this.backupFileService.backupResource(droppedDirtyEditor.resource, content.value.create(this.getDefaultEOL()).createSnapshot(true));
await this.backupFileService.backup(droppedDirtyEditor.resource, stringToSnapshot(droppedDirtyEditor.content));
} catch (e) {
// Ignore error
}
@@ -263,15 +261,6 @@ export class ResourcesDropHandler {
return false;
}
private getDefaultEOL(): DefaultEndOfLine {
const eol = this.configurationService.getValue('files.eol');
if (eol === '\r\n') {
return DefaultEndOfLine.CRLF;
}
return DefaultEndOfLine.LF;
}
private async handleWorkspaceFileDrop(fileOnDiskResources: URI[]): Promise<boolean> {
const toOpen: IWindowOpenable[] = [];
const folderURIs: IWorkspaceFolderCreationData[] = [];
@@ -350,8 +339,8 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:
// Editors: enables cross window DND of tabs into the editor area
const textFileService = accessor.get(ITextFileService);
const backupFileService = accessor.get(IBackupFileService);
const editorService = accessor.get(IEditorService);
const modelService = accessor.get(IModelService);
const draggedEditors: ISerializedDraggedEditor[] = [];
files.forEach(file => {
@@ -379,15 +368,18 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:
mode = model.getMode();
}
// If the resource is dirty, send over its backup
// resource to restore dirty state
let backupResource: string | undefined = undefined;
// If the resource is dirty or untitled, send over its content
// to restore dirty state. Get that from the text model directly
let content: string | undefined = undefined;
if (textFileService.isDirty(file.resource)) {
backupResource = backupFileService.toBackupResource(file.resource).toString();
const textModel = modelService.getModel(file.resource);
if (textModel) {
content = textModel.getValue();
}
}
// Add as dragged editor
draggedEditors.push({ resource: file.resource.toString(), backupResource, viewState, encoding, mode });
draggedEditors.push({ resource: file.resource.toString(), content, viewState, encoding, mode });
});
if (draggedEditors.length) {