diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts index 42e2f6a125a..1d08ee961c2 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts @@ -119,9 +119,6 @@ suite('vscode API - commands', () => { await commands.executeCommand('vscode.open', uri, ViewColumn.One); assert.strictEqual(window.activeTextEditor?.viewColumn, ViewColumn.One); - await commands.executeCommand('vscode.open', uri.toString(), ViewColumn.Two); // call with string instead of URI - assert.strictEqual(window.activeTextEditor?.viewColumn, ViewColumn.Two); - let e1: Error | undefined = undefined; try { await commands.executeCommand('vscode.open'); @@ -137,6 +134,17 @@ suite('vscode API - commands', () => { e2 = error; } assert.ok(e2); + + + // we support strings but only http/https. those we cannot test but we can + // enforce that other schemes are treated strict + try { + await commands.executeCommand('vscode.open', 'file:///some/path/not/http'); + assert.fail('expecting exception'); + } catch { + assert.ok(true); + } + }); test('api-command: vscode.open with untitled supports associated resource (#138925)', async function () { diff --git a/src/vs/workbench/api/common/extHostApiCommands.ts b/src/vs/workbench/api/common/extHostApiCommands.ts index 0d8e1b4335b..92ff750977c 100644 --- a/src/vs/workbench/api/common/extHostApiCommands.ts +++ b/src/vs/workbench/api/common/extHostApiCommands.ts @@ -19,6 +19,8 @@ import { TransientCellMetadata, TransientDocumentMetadata } from 'vs/workbench/c import { ITextEditorOptions } from 'vs/platform/editor/common/editor'; import { VSBuffer } from 'vs/base/common/buffer'; import { decodeSemanticTokensDto } from 'vs/editor/common/services/semanticTokensDto'; +import { matchesSomeScheme } from 'vs/platform/opener/common/opener'; +import { Schemas } from 'vs/base/common/network'; //#region --- NEW world @@ -379,7 +381,7 @@ const newCommands: ApiCommand[] = [ new ApiCommand( 'vscode.open', '_workbench.open', 'Opens the provided resource in the editor. Can be a text or binary file, or an http(s) URL. If you need more control over the options for opening a text file, use vscode.window.showTextDocument instead.', [ - ApiCommandArgument.UriOrString, + new ApiCommandArgument('uriOrString', 'Uri-instance or string (only http/https)', v => URI.isUri(v) || (typeof v === 'string' && matchesSomeScheme(v, Schemas.http, Schemas.https)), v => v), new ApiCommandArgument('columnOrOptions', 'Either the column in which to open or editor options, see vscode.TextDocumentShowOptions', v => v === undefined || typeof v === 'number' || typeof v === 'object', v => !v ? v : typeof v === 'number' ? [typeConverters.ViewColumn.from(v), undefined] : [typeConverters.ViewColumn.from(v.viewColumn), typeConverters.TextEditorOpenOptions.from(v)] diff --git a/src/vs/workbench/api/common/extHostCommands.ts b/src/vs/workbench/api/common/extHostCommands.ts index 16004a03b65..6202db02085 100644 --- a/src/vs/workbench/api/common/extHostCommands.ts +++ b/src/vs/workbench/api/common/extHostCommands.ts @@ -390,7 +390,6 @@ export class CommandsConverter implements extHostTypeConverter.Command.ICommands export class ApiCommandArgument { static readonly Uri = new ApiCommandArgument('uri', 'Uri of a text document', v => URI.isUri(v), v => v); - static readonly UriOrString = new ApiCommandArgument('uriOrString', 'Uri-instance or string', v => URI.isUri(v) || typeof v === 'string', v => v); static readonly Position = new ApiCommandArgument('position', 'A position in a text document', v => extHostTypes.Position.isPosition(v), extHostTypeConverter.Position.from); static readonly Range = new ApiCommandArgument('range', 'A range in a text document', v => extHostTypes.Range.isRange(v), extHostTypeConverter.Range.from); static readonly Selection = new ApiCommandArgument('selection', 'A selection in a text document', v => extHostTypes.Selection.isSelection(v), extHostTypeConverter.Selection.from);