From 13b11919c63224e817fd70937b068430ef750d03 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 27 Apr 2017 14:16:59 +0200 Subject: [PATCH] use correct uri manipulation, #25539 --- extensions/vscode-api-tests/src/workspace.test.ts | 7 +++++++ src/vs/workbench/api/node/mainThreadDocuments.ts | 2 +- .../untitled/common/untitledEditorService.ts | 12 ++---------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/extensions/vscode-api-tests/src/workspace.test.ts b/extensions/vscode-api-tests/src/workspace.test.ts index f54c5b525b6..07754e24fce 100644 --- a/extensions/vscode-api-tests/src/workspace.test.ts +++ b/extensions/vscode-api-tests/src/workspace.test.ts @@ -85,6 +85,13 @@ suite('workspace-namespace', () => { }); }); + test('openTextDocument, untitled with host', function () { + const uri = Uri.parse('untitled://localhost/c%24/Users/jrieken/code/samples/foobar.txt'); + return workspace.openTextDocument(uri).then(doc => { + assert.equal(doc.uri.scheme, 'untitled'); + }); + }); + test('openTextDocument, untitled without path', function () { return workspace.openTextDocument().then(doc => { assert.equal(doc.uri.scheme, 'untitled'); diff --git a/src/vs/workbench/api/node/mainThreadDocuments.ts b/src/vs/workbench/api/node/mainThreadDocuments.ts index 68e8ae99d00..153ddc8232f 100644 --- a/src/vs/workbench/api/node/mainThreadDocuments.ts +++ b/src/vs/workbench/api/node/mainThreadDocuments.ts @@ -227,7 +227,7 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { } private _handleUnititledScheme(uri: URI): TPromise { - let asFileUri = URI.file(uri.fsPath); + let asFileUri = uri.with({ scheme: 'file' }); return this._fileService.resolveFile(asFileUri).then(stats => { // don't create a new file ontop of an existing file return TPromise.wrapError('file already exists on disk'); diff --git a/src/vs/workbench/services/untitled/common/untitledEditorService.ts b/src/vs/workbench/services/untitled/common/untitledEditorService.ts index ca9b0a35175..e1d7d25bbe6 100644 --- a/src/vs/workbench/services/untitled/common/untitledEditorService.ts +++ b/src/vs/workbench/services/untitled/common/untitledEditorService.ts @@ -161,7 +161,7 @@ export class UntitledEditorService implements IUntitledEditorService { let hasAssociatedFilePath = false; if (resource) { hasAssociatedFilePath = (resource.scheme === 'file'); - resource = this.resourceToUntitled(resource); // ensure we have the right scheme + resource = resource.with({ scheme: UntitledEditorInput.SCHEMA }); // ensure we have the right scheme if (hasAssociatedFilePath) { UntitledEditorService.KNOWN_ASSOCIATED_FILE_PATHS.set(resource, true); // remember for future lookups @@ -231,14 +231,6 @@ export class UntitledEditorService implements IUntitledEditorService { return input; } - private resourceToUntitled(resource: URI): URI { - if (resource.scheme === UntitledEditorInput.SCHEMA) { - return resource; - } - - return URI.from({ scheme: UntitledEditorInput.SCHEMA, path: resource.fsPath }); - } - public hasAssociatedFilePath(resource: URI): boolean { return UntitledEditorService.KNOWN_ASSOCIATED_FILE_PATHS.has(resource); } @@ -249,4 +241,4 @@ export class UntitledEditorService implements IUntitledEditorService { this._onDidChangeEncoding.dispose(); this._onDidDisposeModel.dispose(); } -} \ No newline at end of file +} -- GitLab