Skip to content

Commit fe2efa1

Browse files
author
Benjamin Pasero
committed
resources - tweaks
1 parent 22d8581 commit fe2efa1

2 files changed

Lines changed: 12 additions & 22 deletions

File tree

src/vs/base/common/resources.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,15 @@ export class ResourceGlobMatcher {
311311
}
312312
}
313313

314-
export function toLocalResource(resource: URI, remoteAuthority: string | undefined): URI {
315-
let scheme: string;
316-
if (remoteAuthority) {
317-
scheme = Schemas.vscodeRemote;
318-
} else {
319-
scheme = Schemas.file;
314+
export function toLocalResource(resource: URI, authority: string | undefined): URI {
315+
if (authority) {
316+
let path = resource.path;
317+
if (path && path[0] !== paths.posix.sep) {
318+
path = paths.posix.sep + path;
319+
}
320+
321+
return resource.with({ scheme: Schemas.vscodeRemote, authority, path });
320322
}
321323

322-
return resource.with({ scheme });
324+
return resource.with({ scheme: Schemas.file });
323325
}

src/vs/workbench/services/textfile/common/textFileService.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
3030
import { createTextBufferFactoryFromSnapshot, createTextBufferFactoryFromStream } from 'vs/editor/common/model/textModel';
3131
import { IModelService } from 'vs/editor/common/services/modelService';
3232
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
33-
import { isEqualOrParent, isEqual, joinPath, dirname, extname, basename } from 'vs/base/common/resources';
33+
import { isEqualOrParent, isEqual, joinPath, dirname, extname, basename, toLocalResource } from 'vs/base/common/resources';
3434
import { posix } from 'vs/base/common/path';
3535
import { getConfirmMessage, IDialogService, IFileDialogService, ISaveDialogOptions, IConfirmation } from 'vs/platform/dialogs/common/dialogs';
3636
import { IModeService } from 'vs/editor/common/services/modeService';
@@ -570,7 +570,7 @@ export class TextFileService extends Disposable implements ITextFileService {
570570

571571
// Untitled with associated file path don't need to prompt
572572
if (this.untitledEditorService.hasAssociatedFilePath(untitled)) {
573-
targetUri = this.untitledToAssociatedFileResource(untitled);
573+
targetUri = toLocalResource(untitled, this.environmentService.configuration.remoteAuthority);
574574
}
575575

576576
// Otherwise ask user
@@ -607,18 +607,6 @@ export class TextFileService extends Disposable implements ITextFileService {
607607
});
608608
}
609609

610-
private untitledToAssociatedFileResource(untitled: URI): URI {
611-
const authority = this.environmentService.configuration.remoteAuthority;
612-
if (authority) {
613-
let path = untitled.path;
614-
if (path && path[0] !== posix.sep) {
615-
path = posix.sep + path;
616-
}
617-
return untitled.with({ scheme: Schemas.vscodeRemote, authority, path });
618-
}
619-
return untitled.with({ scheme: Schemas.file });
620-
}
621-
622610
private doSaveAllFiles(resources?: URI[], options: ISaveOptions = Object.create(null)): Promise<ITextFileOperationResult> {
623611
const dirtyFileModels = this.getDirtyFileModels(Array.isArray(resources) ? resources : undefined /* Save All */)
624612
.filter(model => {
@@ -762,7 +750,7 @@ export class TextFileService extends Disposable implements ITextFileService {
762750
// path. This can happen if the file was created after the untitled file was opened.
763751
// See https://github.com/Microsoft/vscode/issues/67946
764752
let confirmWrite: Promise<boolean>;
765-
if (sourceModel instanceof UntitledEditorModel && sourceModel.hasAssociatedFilePath && targetExists && isEqual(target, this.untitledToAssociatedFileResource(sourceModel.getResource()))) {
753+
if (sourceModel instanceof UntitledEditorModel && sourceModel.hasAssociatedFilePath && targetExists && isEqual(target, toLocalResource(sourceModel.getResource(), this.environmentService.configuration.remoteAuthority))) {
766754
confirmWrite = this.confirmOverwrite(target);
767755
} else {
768756
confirmWrite = Promise.resolve(true);

0 commit comments

Comments
 (0)