diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/mappedEdits.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/mappedEdits.test.ts index f4fc349f115..72413a2773f 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/mappedEdits.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/mappedEdits.test.ts @@ -18,13 +18,12 @@ suite('mapped edits provider', () => { const r1 = vscode.chat.registerMappedEditsProvider(tsDocFilter, { provideMappedEdits: (_doc: vscode.TextDocument, codeBlocks: string[], context: vscode.MappedEditsContext, _token: vscode.CancellationToken) => { - assert(context.selections.length === 1); - assert(context.related.length === 1); - assert('uri' in context.related[0] && 'range' in context.related[0]); + assert((context as any).selections.length === 1); // context.selections is for backward compat + assert(context.documents.length === 1); const edit = new vscode.WorkspaceEdit(); const text = codeBlocks.join('\n//----\n'); - edit.replace(uri, context.selections[0], text); + edit.replace(uri, context.documents[0][0].ranges[0], text); return edit; } }); @@ -37,12 +36,16 @@ suite('mapped edits provider', () => { `function foo() {\n\treturn 1;\n}`, ], { - selections: [new vscode.Selection(0, 0, 1, 0)], - related: [ - { - uri, - range: new vscode.Range(new vscode.Position(0, 0), new vscode.Position(1, 0)) - } + documents: [ + [ + { + uri, + version: 1, + ranges: [ + new vscode.Range(new vscode.Position(0, 0), new vscode.Position(1, 0)) + ] + } + ] ] } ); @@ -60,13 +63,9 @@ suite('mapped edits provider', () => { const r1 = vscode.chat.registerMappedEditsProvider(tsDocFilter, { provideMappedEdits: (_doc: vscode.TextDocument, codeBlocks: string[], context: vscode.MappedEditsContext, _token: vscode.CancellationToken) => { - assert(context.selections.length === 1); - assert(context.related.length === 1); - assert('uri' in context.related[0] && 'range' in context.related[0]); - const edit = new vscode.WorkspaceEdit(); const text = codeBlocks.join('\n//----\n'); - edit.replace(uri, context.selections[0], text); + edit.replace(uri, context.documents[0][0].ranges[0], text); return edit; } }); @@ -80,12 +79,16 @@ suite('mapped edits provider', () => { `function foo() {\n\treturn 1;\n}`, ], { - selections: [new vscode.Selection(0, 0, 1, 0)], - related: [ - { - uri, - range: new vscode.Range(new vscode.Position(0, 0), new vscode.Position(1, 0)) - } + documents: [ + [ + { + uri, + version: 1, + ranges: [ + new vscode.Range(new vscode.Position(0, 0), new vscode.Position(1, 0)) + ] + } + ] ] } ); diff --git a/src/vs/workbench/api/common/extHostCommands.ts b/src/vs/workbench/api/common/extHostCommands.ts index fd3ba6c52b9..beb10dcddac 100644 --- a/src/vs/workbench/api/common/extHostCommands.ts +++ b/src/vs/workbench/api/common/extHostCommands.ts @@ -123,7 +123,7 @@ export class ExtHostCommands implements ExtHostCommandsShape { const internalArgs = apiCommand.args.map((arg, i) => { if (!arg.validate(apiArgs[i])) { - throw new Error(`Invalid argument '${arg.name}' when running '${apiCommand.id}', received: ${apiArgs[i]}`); + throw new Error(`Invalid argument '${arg.name}' when running '${apiCommand.id}', received: ${typeof apiArgs[i] === 'object' ? JSON.stringify(apiArgs[i], null, '\t') : apiArgs[i]} `); } return arg.convert(apiArgs[i]); }); @@ -238,7 +238,7 @@ export class ExtHostCommands implements ExtHostCommandsShape { try { validateConstraint(args[i], description.args[i].constraint); } catch (err) { - throw new Error(`Running the contributed command: '${id}' failed. Illegal argument '${description.args[i].name}' - ${description.args[i].description}`); + throw new Error(`Running the contributed command: '${id}' failed.Illegal argument '${description.args[i].name}' - ${description.args[i].description} `); } } } @@ -342,7 +342,7 @@ export const IExtHostCommands = createDecorator('IExtHostComma export class CommandsConverter implements extHostTypeConverter.Command.ICommandsConverter { - readonly delegatingCommandId: string = `__vsc${Date.now().toString(36)}`; + readonly delegatingCommandId: string = `__vsc${Date.now().toString(36)} `; private readonly _cache = new Map(); private _cachIdPool = 0; @@ -387,7 +387,7 @@ export class CommandsConverter implements extHostTypeConverter.Command.ICommands // we have a contributed command with arguments. that // means we don't want to send the arguments around - const id = `${command.command}/${++this._cachIdPool}`; + const id = `${command.command} /${++this._cachIdPool}`; this._cache.set(id, command); disposables.add(toDisposable(() => { this._cache.delete(id); diff --git a/src/vs/workbench/api/common/extHostTypeConverters.ts b/src/vs/workbench/api/common/extHostTypeConverters.ts index b22d52ebead..9055980c1e4 100644 --- a/src/vs/workbench/api/common/extHostTypeConverters.ts +++ b/src/vs/workbench/api/common/extHostTypeConverters.ts @@ -1567,14 +1567,20 @@ export namespace LanguageSelector { export namespace MappedEditsContext { export function is(v: unknown): v is vscode.MappedEditsContext { - return (!!v && - typeof v === 'object' && - 'selections' in v && - Array.isArray(v.selections) && - v.selections.every(s => s instanceof types.Selection) && - 'related' in v && - Array.isArray(v.related) && - v.related.every(e => e && typeof e === 'object' && URI.isUri(e.uri) && e.range instanceof types.Range)); + return ( + !!v && typeof v === 'object' && + 'documents' in v && + Array.isArray(v.documents) && + v.documents.every(subArr => + Array.isArray(subArr) && + subArr.every(docRef => + docRef && typeof docRef === 'object' && + 'uri' in docRef && URI.isUri(docRef.uri) && + 'version' in docRef && typeof docRef.version === 'number' && + 'ranges' in docRef && Array.isArray(docRef.ranges) && docRef.ranges.every((r: unknown) => r instanceof types.Range) + ) + ) + ); } export function from(extContext: vscode.MappedEditsContext): languages.MappedEditsContext {