From 8755e438f566b0e2dbc2b847bc1ba7ea8792f8e5 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 27 Jan 2016 11:36:53 +0100 Subject: [PATCH] scheme and path or authoriy are mandated, fixes #2341 --- .../vscode-api-tests/src/workspace.test.ts | 26 +++++++++++++++++++ src/vs/workbench/api/node/extHostDocuments.ts | 4 +-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/extensions/vscode-api-tests/src/workspace.test.ts b/extensions/vscode-api-tests/src/workspace.test.ts index 2db2c1d80a0..56274efbca5 100644 --- a/extensions/vscode-api-tests/src/workspace.test.ts +++ b/extensions/vscode-api-tests/src/workspace.test.ts @@ -75,6 +75,32 @@ suite('workspace-namespace', () => { }); }); + test('openTextDocument, uri scheme/auth/path', function() { + + let registration = workspace.registerTextDocumentContentProvider('sc', { + provideTextDocumentContent() { + return 'SC'; + } + }); + + return Promise.all([ + workspace.openTextDocument(Uri.parse('sc://auth')).then(doc => { + assert.equal(doc.uri.authority, 'auth'); + assert.equal(doc.uri.path, ''); + }), + workspace.openTextDocument(Uri.parse('sc:///path')).then(doc => { + assert.equal(doc.uri.authority, ''); + assert.equal(doc.uri.path, '/path'); + }), + workspace.openTextDocument(Uri.parse('sc://auth/path')).then(doc => { + assert.equal(doc.uri.authority, 'auth'); + assert.equal(doc.uri.path, '/path'); + }) + ]).then(() => { + registration.dispose(); + }); + }) + test('events: onDidOpenTextDocument, onDidChangeTextDocument, onDidSaveTextDocument', () => { return createRandomFile().then(file => { let disposables = []; diff --git a/src/vs/workbench/api/node/extHostDocuments.ts b/src/vs/workbench/api/node/extHostDocuments.ts index f3fed005cc1..f51124fa9fc 100644 --- a/src/vs/workbench/api/node/extHostDocuments.ts +++ b/src/vs/workbench/api/node/extHostDocuments.ts @@ -581,8 +581,8 @@ export class MainThreadDocuments { _tryOpenDocument(uri: URI): TPromise { - if (!uri.scheme || !uri.fsPath) { - return TPromise.wrapError('Uri must have scheme and path. One or both are missing in: ' + uri.toString()); + if (!uri.scheme || !(uri.fsPath || uri.authority)) { + return TPromise.wrapError(`Invalid uri. Scheme and authority or path must be set.`); } let promise: TPromise;