Path: blob/main/src/vs/workbench/api/common/extHostApiCommands.ts
5240 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { isFalsyOrEmpty } from '../../../base/common/arrays.js';6import { VSBuffer } from '../../../base/common/buffer.js';7import { Schemas, matchesSomeScheme } from '../../../base/common/network.js';8import { URI } from '../../../base/common/uri.js';9import { IPosition } from '../../../editor/common/core/position.js';10import { IRange } from '../../../editor/common/core/range.js';11import { ISelection } from '../../../editor/common/core/selection.js';12import * as languages from '../../../editor/common/languages.js';13import { decodeSemanticTokensDto } from '../../../editor/common/services/semanticTokensDto.js';14import { validateWhenClauses } from '../../../platform/contextkey/common/contextkey.js';15import { ITextEditorOptions } from '../../../platform/editor/common/editor.js';16import { ICallHierarchyItemDto, IIncomingCallDto, IInlineValueContextDto, IOutgoingCallDto, IRawColorInfo, ITypeHierarchyItemDto, IWorkspaceEditDto } from './extHost.protocol.js';17import { ApiCommand, ApiCommandArgument, ApiCommandResult, ExtHostCommands } from './extHostCommands.js';18import { CustomCodeAction } from './extHostLanguageFeatures.js';19import * as typeConverters from './extHostTypeConverters.js';20import * as types from './extHostTypes.js';21import { TransientCellMetadata, TransientDocumentMetadata } from '../../contrib/notebook/common/notebookCommon.js';22import * as search from '../../contrib/search/common/search.js';23import type * as vscode from 'vscode';24import { PromptsType } from '../../contrib/chat/common/promptSyntax/promptTypes.js';25import type { IExtensionPromptFileResult } from '../../contrib/chat/common/promptSyntax/chatPromptFilesContribution.js';2627//#region --- NEW world2829const newCommands: ApiCommand[] = [30// -- document highlights31new ApiCommand(32'vscode.executeDocumentHighlights', '_executeDocumentHighlights', 'Execute document highlight provider.',33[ApiCommandArgument.Uri, ApiCommandArgument.Position],34new ApiCommandResult<languages.DocumentHighlight[], types.DocumentHighlight[] | undefined>('A promise that resolves to an array of DocumentHighlight-instances.', tryMapWith(typeConverters.DocumentHighlight.to))35),36// -- document symbols37new ApiCommand(38'vscode.executeDocumentSymbolProvider', '_executeDocumentSymbolProvider', 'Execute document symbol provider.',39[ApiCommandArgument.Uri],40new ApiCommandResult<languages.DocumentSymbol[], vscode.SymbolInformation[] | undefined>('A promise that resolves to an array of SymbolInformation and DocumentSymbol instances.', (value, apiArgs) => {4142if (isFalsyOrEmpty(value)) {43return undefined;44}45class MergedInfo extends types.SymbolInformation implements vscode.DocumentSymbol {46static to(symbol: languages.DocumentSymbol): MergedInfo {47const res = new MergedInfo(48symbol.name,49typeConverters.SymbolKind.to(symbol.kind),50symbol.containerName || '',51new types.Location(apiArgs[0], typeConverters.Range.to(symbol.range))52);53res.detail = symbol.detail;54res.range = res.location.range;55res.selectionRange = typeConverters.Range.to(symbol.selectionRange);56res.children = symbol.children ? symbol.children.map(MergedInfo.to) : [];57return res;58}5960detail!: string;61range!: vscode.Range;62selectionRange!: vscode.Range;63children!: vscode.DocumentSymbol[];64override containerName: string = '';65}66return value.map(MergedInfo.to);6768})69),70// -- formatting71new ApiCommand(72'vscode.executeFormatDocumentProvider', '_executeFormatDocumentProvider', 'Execute document format provider.',73[ApiCommandArgument.Uri, new ApiCommandArgument('options', 'Formatting options', _ => true, v => v)],74new ApiCommandResult<languages.TextEdit[], types.TextEdit[] | undefined>('A promise that resolves to an array of TextEdits.', tryMapWith(typeConverters.TextEdit.to))75),76new ApiCommand(77'vscode.executeFormatRangeProvider', '_executeFormatRangeProvider', 'Execute range format provider.',78[ApiCommandArgument.Uri, ApiCommandArgument.Range, new ApiCommandArgument('options', 'Formatting options', _ => true, v => v)],79new ApiCommandResult<languages.TextEdit[], types.TextEdit[] | undefined>('A promise that resolves to an array of TextEdits.', tryMapWith(typeConverters.TextEdit.to))80),81new ApiCommand(82'vscode.executeFormatOnTypeProvider', '_executeFormatOnTypeProvider', 'Execute format on type provider.',83[ApiCommandArgument.Uri, ApiCommandArgument.Position, new ApiCommandArgument('ch', 'Trigger character', v => typeof v === 'string', v => v), new ApiCommandArgument('options', 'Formatting options', _ => true, v => v)],84new ApiCommandResult<languages.TextEdit[], types.TextEdit[] | undefined>('A promise that resolves to an array of TextEdits.', tryMapWith(typeConverters.TextEdit.to))85),86// -- go to symbol (definition, type definition, declaration, impl, references)87new ApiCommand(88'vscode.executeDefinitionProvider', '_executeDefinitionProvider', 'Execute all definition providers.',89[ApiCommandArgument.Uri, ApiCommandArgument.Position],90new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)91),92new ApiCommand(93'vscode.experimental.executeDefinitionProvider_recursive', '_executeDefinitionProvider_recursive', 'Execute all definition providers.',94[ApiCommandArgument.Uri, ApiCommandArgument.Position],95new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)96),97new ApiCommand(98'vscode.executeTypeDefinitionProvider', '_executeTypeDefinitionProvider', 'Execute all type definition providers.',99[ApiCommandArgument.Uri, ApiCommandArgument.Position],100new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)101),102new ApiCommand(103'vscode.experimental.executeTypeDefinitionProvider_recursive', '_executeTypeDefinitionProvider_recursive', 'Execute all type definition providers.',104[ApiCommandArgument.Uri, ApiCommandArgument.Position],105new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)106),107new ApiCommand(108'vscode.executeDeclarationProvider', '_executeDeclarationProvider', 'Execute all declaration providers.',109[ApiCommandArgument.Uri, ApiCommandArgument.Position],110new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)111),112new ApiCommand(113'vscode.experimental.executeDeclarationProvider_recursive', '_executeDeclarationProvider_recursive', 'Execute all declaration providers.',114[ApiCommandArgument.Uri, ApiCommandArgument.Position],115new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)116),117new ApiCommand(118'vscode.executeImplementationProvider', '_executeImplementationProvider', 'Execute all implementation providers.',119[ApiCommandArgument.Uri, ApiCommandArgument.Position],120new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)121),122new ApiCommand(123'vscode.experimental.executeImplementationProvider_recursive', '_executeImplementationProvider_recursive', 'Execute all implementation providers.',124[ApiCommandArgument.Uri, ApiCommandArgument.Position],125new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)126),127new ApiCommand(128'vscode.executeReferenceProvider', '_executeReferenceProvider', 'Execute all reference providers.',129[ApiCommandArgument.Uri, ApiCommandArgument.Position],130new ApiCommandResult<languages.Location[], types.Location[] | undefined>('A promise that resolves to an array of Location-instances.', tryMapWith(typeConverters.location.to))131),132new ApiCommand(133'vscode.experimental.executeReferenceProvider', '_executeReferenceProvider_recursive', 'Execute all reference providers.',134[ApiCommandArgument.Uri, ApiCommandArgument.Position],135new ApiCommandResult<languages.Location[], types.Location[] | undefined>('A promise that resolves to an array of Location-instances.', tryMapWith(typeConverters.location.to))136),137// -- hover138new ApiCommand(139'vscode.executeHoverProvider', '_executeHoverProvider', 'Execute all hover providers.',140[ApiCommandArgument.Uri, ApiCommandArgument.Position],141new ApiCommandResult<languages.Hover[], types.Hover[] | undefined>('A promise that resolves to an array of Hover-instances.', tryMapWith(typeConverters.Hover.to))142),143new ApiCommand(144'vscode.experimental.executeHoverProvider_recursive', '_executeHoverProvider_recursive', 'Execute all hover providers.',145[ApiCommandArgument.Uri, ApiCommandArgument.Position],146new ApiCommandResult<languages.Hover[], types.Hover[] | undefined>('A promise that resolves to an array of Hover-instances.', tryMapWith(typeConverters.Hover.to))147),148// -- selection range149new ApiCommand(150'vscode.executeSelectionRangeProvider', '_executeSelectionRangeProvider', 'Execute selection range provider.',151[ApiCommandArgument.Uri, new ApiCommandArgument<types.Position[], IPosition[]>('position', 'A position in a text document', v => Array.isArray(v) && v.every(v => types.Position.isPosition(v)), v => v.map(typeConverters.Position.from))],152new ApiCommandResult<IRange[][], types.SelectionRange[]>('A promise that resolves to an array of ranges.', result => {153return result.map(ranges => {154let node: types.SelectionRange | undefined;155for (const range of ranges.reverse()) {156node = new types.SelectionRange(typeConverters.Range.to(range), node);157}158return node!;159});160})161),162// -- symbol search163new ApiCommand(164'vscode.executeWorkspaceSymbolProvider', '_executeWorkspaceSymbolProvider', 'Execute all workspace symbol providers.',165[ApiCommandArgument.String.with('query', 'Search string')],166new ApiCommandResult<search.IWorkspaceSymbol[], types.SymbolInformation[]>('A promise that resolves to an array of SymbolInformation-instances.', value => {167return value.map(typeConverters.WorkspaceSymbol.to);168})169),170// --- call hierarchy171new ApiCommand(172'vscode.prepareCallHierarchy', '_executePrepareCallHierarchy', 'Prepare call hierarchy at a position inside a document',173[ApiCommandArgument.Uri, ApiCommandArgument.Position],174new ApiCommandResult<ICallHierarchyItemDto[], types.CallHierarchyItem[]>('A promise that resolves to an array of CallHierarchyItem-instances', v => v.map(typeConverters.CallHierarchyItem.to))175),176new ApiCommand(177'vscode.provideIncomingCalls', '_executeProvideIncomingCalls', 'Compute incoming calls for an item',178[ApiCommandArgument.CallHierarchyItem],179new ApiCommandResult<IIncomingCallDto[], types.CallHierarchyIncomingCall[]>('A promise that resolves to an array of CallHierarchyIncomingCall-instances', v => v.map(typeConverters.CallHierarchyIncomingCall.to))180),181new ApiCommand(182'vscode.provideOutgoingCalls', '_executeProvideOutgoingCalls', 'Compute outgoing calls for an item',183[ApiCommandArgument.CallHierarchyItem],184new ApiCommandResult<IOutgoingCallDto[], types.CallHierarchyOutgoingCall[]>('A promise that resolves to an array of CallHierarchyOutgoingCall-instances', v => v.map(typeConverters.CallHierarchyOutgoingCall.to))185),186// --- rename187new ApiCommand(188'vscode.prepareRename', '_executePrepareRename', 'Execute the prepareRename of rename provider.',189[ApiCommandArgument.Uri, ApiCommandArgument.Position],190new ApiCommandResult<languages.RenameLocation, { range: types.Range; placeholder: string } | undefined>('A promise that resolves to a range and placeholder text.', value => {191if (!value) {192return undefined;193}194return {195range: typeConverters.Range.to(value.range),196placeholder: value.text197};198})199),200new ApiCommand(201'vscode.executeDocumentRenameProvider', '_executeDocumentRenameProvider', 'Execute rename provider.',202[ApiCommandArgument.Uri, ApiCommandArgument.Position, ApiCommandArgument.String.with('newName', 'The new symbol name')],203new ApiCommandResult<IWorkspaceEditDto & { rejectReason?: string }, types.WorkspaceEdit | undefined>('A promise that resolves to a WorkspaceEdit.', value => {204if (!value) {205return undefined;206}207if (value.rejectReason) {208throw new Error(value.rejectReason);209}210return typeConverters.WorkspaceEdit.to(value);211})212),213// --- links214new ApiCommand(215'vscode.executeLinkProvider', '_executeLinkProvider', 'Execute document link provider.',216[ApiCommandArgument.Uri, ApiCommandArgument.Number.with('linkResolveCount', 'Number of links that should be resolved, only when links are unresolved.').optional()],217new ApiCommandResult<languages.ILink[], vscode.DocumentLink[]>('A promise that resolves to an array of DocumentLink-instances.', value => value.map(typeConverters.DocumentLink.to))218),219// --- semantic tokens220new ApiCommand(221'vscode.provideDocumentSemanticTokensLegend', '_provideDocumentSemanticTokensLegend', 'Provide semantic tokens legend for a document',222[ApiCommandArgument.Uri],223new ApiCommandResult<languages.SemanticTokensLegend, types.SemanticTokensLegend | undefined>('A promise that resolves to SemanticTokensLegend.', value => {224if (!value) {225return undefined;226}227return new types.SemanticTokensLegend(value.tokenTypes, value.tokenModifiers);228})229),230new ApiCommand(231'vscode.provideDocumentSemanticTokens', '_provideDocumentSemanticTokens', 'Provide semantic tokens for a document',232[ApiCommandArgument.Uri],233new ApiCommandResult<VSBuffer, types.SemanticTokens | undefined>('A promise that resolves to SemanticTokens.', value => {234if (!value) {235return undefined;236}237const semanticTokensDto = decodeSemanticTokensDto(value);238if (semanticTokensDto.type !== 'full') {239// only accepting full semantic tokens from provideDocumentSemanticTokens240return undefined;241}242return new types.SemanticTokens(semanticTokensDto.data, undefined);243})244),245new ApiCommand(246'vscode.provideDocumentRangeSemanticTokensLegend', '_provideDocumentRangeSemanticTokensLegend', 'Provide semantic tokens legend for a document range',247[ApiCommandArgument.Uri, ApiCommandArgument.Range.optional()],248new ApiCommandResult<languages.SemanticTokensLegend, types.SemanticTokensLegend | undefined>('A promise that resolves to SemanticTokensLegend.', value => {249if (!value) {250return undefined;251}252return new types.SemanticTokensLegend(value.tokenTypes, value.tokenModifiers);253})254),255new ApiCommand(256'vscode.provideDocumentRangeSemanticTokens', '_provideDocumentRangeSemanticTokens', 'Provide semantic tokens for a document range',257[ApiCommandArgument.Uri, ApiCommandArgument.Range],258new ApiCommandResult<VSBuffer, types.SemanticTokens | undefined>('A promise that resolves to SemanticTokens.', value => {259if (!value) {260return undefined;261}262const semanticTokensDto = decodeSemanticTokensDto(value);263if (semanticTokensDto.type !== 'full') {264// only accepting full semantic tokens from provideDocumentRangeSemanticTokens265return undefined;266}267return new types.SemanticTokens(semanticTokensDto.data, undefined);268})269),270// --- completions271new ApiCommand(272'vscode.executeCompletionItemProvider', '_executeCompletionItemProvider', 'Execute completion item provider.',273[274ApiCommandArgument.Uri,275ApiCommandArgument.Position,276ApiCommandArgument.String.with('triggerCharacter', 'Trigger completion when the user types the character, like `,` or `(`').optional(),277ApiCommandArgument.Number.with('itemResolveCount', 'Number of completions to resolve (too large numbers slow down completions)').optional()278],279new ApiCommandResult<languages.CompletionList, vscode.CompletionList>('A promise that resolves to a CompletionList-instance.', (value, _args, converter) => {280if (!value) {281return new types.CompletionList([]);282}283const items = value.suggestions.map(suggestion => typeConverters.CompletionItem.to(suggestion, converter));284return new types.CompletionList(items, value.incomplete);285})286),287// --- signature help288new ApiCommand(289'vscode.executeSignatureHelpProvider', '_executeSignatureHelpProvider', 'Execute signature help provider.',290[ApiCommandArgument.Uri, ApiCommandArgument.Position, ApiCommandArgument.String.with('triggerCharacter', 'Trigger signature help when the user types the character, like `,` or `(`').optional()],291new ApiCommandResult<languages.SignatureHelp, vscode.SignatureHelp | undefined>('A promise that resolves to SignatureHelp.', value => {292if (value) {293return typeConverters.SignatureHelp.to(value);294}295return undefined;296})297),298// --- code lens299new ApiCommand(300'vscode.executeCodeLensProvider', '_executeCodeLensProvider', 'Execute code lens provider.',301[ApiCommandArgument.Uri, ApiCommandArgument.Number.with('itemResolveCount', 'Number of lenses that should be resolved and returned. Will only return resolved lenses, will impact performance)').optional()],302new ApiCommandResult<languages.CodeLens[], vscode.CodeLens[] | undefined>('A promise that resolves to an array of CodeLens-instances.', (value, _args, converter) => {303return tryMapWith<languages.CodeLens, vscode.CodeLens>(item => {304return new types.CodeLens(typeConverters.Range.to(item.range), item.command && converter.fromInternal(item.command));305})(value);306})307),308// --- code actions309new ApiCommand(310'vscode.executeCodeActionProvider', '_executeCodeActionProvider', 'Execute code action provider.',311[312ApiCommandArgument.Uri,313new ApiCommandArgument('rangeOrSelection', 'Range in a text document. Some refactoring provider requires Selection object.', v => types.Range.isRange(v), v => types.Selection.isSelection(v) ? typeConverters.Selection.from(v) : typeConverters.Range.from(v)),314ApiCommandArgument.String.with('kind', 'Code action kind to return code actions for').optional(),315ApiCommandArgument.Number.with('itemResolveCount', 'Number of code actions to resolve (too large numbers slow down code actions)').optional()316],317new ApiCommandResult<CustomCodeAction[], (vscode.CodeAction | vscode.Command | undefined)[] | undefined>('A promise that resolves to an array of Command-instances.', (value, _args, converter) => {318return tryMapWith<CustomCodeAction, vscode.CodeAction | vscode.Command | undefined>((codeAction) => {319if (codeAction._isSynthetic) {320if (!codeAction.command) {321throw new Error('Synthetic code actions must have a command');322}323return converter.fromInternal(codeAction.command);324} else {325const ret = new types.CodeAction(326codeAction.title,327codeAction.kind ? new types.CodeActionKind(codeAction.kind) : undefined328);329if (codeAction.edit) {330ret.edit = typeConverters.WorkspaceEdit.to(codeAction.edit);331}332if (codeAction.command) {333ret.command = converter.fromInternal(codeAction.command);334}335ret.isPreferred = codeAction.isPreferred;336return ret;337}338})(value);339})340),341// --- colors342new ApiCommand(343'vscode.executeDocumentColorProvider', '_executeDocumentColorProvider', 'Execute document color provider.',344[ApiCommandArgument.Uri],345new ApiCommandResult<IRawColorInfo[], vscode.ColorInformation[]>('A promise that resolves to an array of ColorInformation objects.', result => {346if (result) {347return result.map(ci => new types.ColorInformation(typeConverters.Range.to(ci.range), typeConverters.Color.to(ci.color)));348}349return [];350})351),352new ApiCommand(353'vscode.executeColorPresentationProvider', '_executeColorPresentationProvider', 'Execute color presentation provider.',354[355new ApiCommandArgument<types.Color, [number, number, number, number]>('color', 'The color to show and insert', v => v instanceof types.Color, typeConverters.Color.from),356new ApiCommandArgument<{ uri: URI; range: types.Range }, { uri: URI; range: IRange }>('context', 'Context object with uri and range', _v => true, v => ({ uri: v.uri, range: typeConverters.Range.from(v.range) })),357],358new ApiCommandResult<languages.IColorPresentation[], types.ColorPresentation[]>('A promise that resolves to an array of ColorPresentation objects.', result => {359if (result) {360return result.map(typeConverters.ColorPresentation.to);361}362return [];363})364),365// --- inline hints366new ApiCommand(367'vscode.executeInlayHintProvider', '_executeInlayHintProvider', 'Execute inlay hints provider',368[ApiCommandArgument.Uri, ApiCommandArgument.Range],369new ApiCommandResult<languages.InlayHint[], vscode.InlayHint[]>('A promise that resolves to an array of Inlay objects', (result, args, converter) => {370return result.map(typeConverters.InlayHint.to.bind(undefined, converter));371})372),373// --- folding374new ApiCommand(375'vscode.executeFoldingRangeProvider', '_executeFoldingRangeProvider', 'Execute folding range provider',376[ApiCommandArgument.Uri],377new ApiCommandResult<languages.FoldingRange[] | undefined, vscode.FoldingRange[] | undefined>('A promise that resolves to an array of FoldingRange objects', (result, args) => {378if (result) {379return result.map(typeConverters.FoldingRange.to);380}381return undefined;382})383),384385// --- notebooks386new ApiCommand(387'vscode.resolveNotebookContentProviders', '_resolveNotebookContentProvider', 'Resolve Notebook Content Providers',388[389// new ApiCommandArgument<string, string>('viewType', '', v => typeof v === 'string', v => v),390// new ApiCommandArgument<string, string>('displayName', '', v => typeof v === 'string', v => v),391// new ApiCommandArgument<object, object>('options', '', v => typeof v === 'object', v => v),392],393new ApiCommandResult<{394viewType: string;395displayName: string;396options: { transientOutputs: boolean; transientCellMetadata: TransientCellMetadata; transientDocumentMetadata: TransientDocumentMetadata };397filenamePattern: (vscode.GlobPattern | { include: vscode.GlobPattern; exclude: vscode.GlobPattern })[];398}[], {399viewType: string;400displayName: string;401filenamePattern: (vscode.GlobPattern | { include: vscode.GlobPattern; exclude: vscode.GlobPattern })[];402options: vscode.NotebookDocumentContentOptions;403}[] | undefined>('A promise that resolves to an array of NotebookContentProvider static info objects.', tryMapWith(item => {404return {405viewType: item.viewType,406displayName: item.displayName,407options: {408transientOutputs: item.options.transientOutputs,409transientCellMetadata: item.options.transientCellMetadata,410transientDocumentMetadata: item.options.transientDocumentMetadata411},412filenamePattern: item.filenamePattern.map(pattern => typeConverters.NotebookExclusiveDocumentPattern.to(pattern))413};414}))415),416// --- debug support417new ApiCommand(418'vscode.executeInlineValueProvider', '_executeInlineValueProvider', 'Execute inline value provider',419[420ApiCommandArgument.Uri,421ApiCommandArgument.Range,422new ApiCommandArgument<types.InlineValueContext, IInlineValueContextDto>('context', 'An InlineValueContext', v => v && typeof v.frameId === 'number' && v.stoppedLocation instanceof types.Range, v => typeConverters.InlineValueContext.from(v))423],424new ApiCommandResult<languages.InlineValue[], vscode.InlineValue[]>('A promise that resolves to an array of InlineValue objects', result => {425return result.map(typeConverters.InlineValue.to);426})427),428// --- open'ish commands429new ApiCommand(430'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.',431[432new ApiCommandArgument<URI | string>('uriOrString', 'Uri-instance or string (only http/https)', v => URI.isUri(v) || (typeof v === 'string' && matchesSomeScheme(v, Schemas.http, Schemas.https)), v => v),433new ApiCommandArgument<vscode.ViewColumn | typeConverters.TextEditorOpenOptions | undefined, [vscode.ViewColumn?, ITextEditorOptions?] | undefined>('columnOrOptions', 'Either the column in which to open or editor options, see vscode.TextDocumentShowOptions',434v => v === undefined || typeof v === 'number' || typeof v === 'object',435v => !v ? v : typeof v === 'number' ? [typeConverters.ViewColumn.from(v), undefined] : [typeConverters.ViewColumn.from(v.viewColumn), typeConverters.TextEditorOpenOptions.from(v)]436).optional(),437ApiCommandArgument.String.with('label', '').optional()438],439ApiCommandResult.Void440),441new ApiCommand(442'vscode.openWith', '_workbench.openWith', 'Opens the provided resource with a specific editor.',443[444ApiCommandArgument.Uri.with('resource', 'Resource to open'),445ApiCommandArgument.String.with('viewId', 'Custom editor view id. This should be the viewType string for custom editors or the notebookType string for notebooks. Use \'default\' to use VS Code\'s default text editor'),446new ApiCommandArgument<vscode.ViewColumn | typeConverters.TextEditorOpenOptions | undefined, [vscode.ViewColumn?, ITextEditorOptions?] | undefined>('columnOrOptions', 'Either the column in which to open or editor options, see vscode.TextDocumentShowOptions',447v => v === undefined || typeof v === 'number' || typeof v === 'object',448v => !v ? v : typeof v === 'number' ? [typeConverters.ViewColumn.from(v), undefined] : [typeConverters.ViewColumn.from(v.viewColumn), typeConverters.TextEditorOpenOptions.from(v)],449).optional()450],451ApiCommandResult.Void452),453new ApiCommand(454'vscode.diff', '_workbench.diff', 'Opens the provided resources in the diff editor to compare their contents.',455[456ApiCommandArgument.Uri.with('left', 'Left-hand side resource of the diff editor'),457ApiCommandArgument.Uri.with('right', 'Right-hand side resource of the diff editor'),458ApiCommandArgument.String.with('title', 'Human readable title for the diff editor').optional(),459new ApiCommandArgument<typeConverters.TextEditorOpenOptions | undefined, [number?, ITextEditorOptions?] | undefined>('columnOrOptions', 'Either the column in which to open or editor options, see vscode.TextDocumentShowOptions',460v => v === undefined || typeof v === 'object',461v => v && [typeConverters.ViewColumn.from(v.viewColumn), typeConverters.TextEditorOpenOptions.from(v)]462).optional(),463],464ApiCommandResult.Void465),466new ApiCommand(467'vscode.changes', '_workbench.changes', 'Opens a list of resources in the changes editor to compare their contents.',468[469ApiCommandArgument.String.with('title', 'Human readable title for the changes editor'),470new ApiCommandArgument<[URI, URI?, URI?][]>('resourceList', 'List of resources to compare',471resources => {472for (const resource of resources) {473if (resource.length !== 3) {474return false;475}476477const [label, left, right] = resource;478if (!URI.isUri(label) ||479(!URI.isUri(left) && left !== undefined && left !== null) ||480(!URI.isUri(right) && right !== undefined && right !== null)) {481return false;482}483}484485return true;486},487v => v)488],489ApiCommandResult.Void490),491// --- type hierarchy492new ApiCommand(493'vscode.prepareTypeHierarchy', '_executePrepareTypeHierarchy', 'Prepare type hierarchy at a position inside a document',494[ApiCommandArgument.Uri, ApiCommandArgument.Position],495new ApiCommandResult<ITypeHierarchyItemDto[], types.TypeHierarchyItem[]>('A promise that resolves to an array of TypeHierarchyItem-instances', v => v.map(typeConverters.TypeHierarchyItem.to))496),497new ApiCommand(498'vscode.provideSupertypes', '_executeProvideSupertypes', 'Compute supertypes for an item',499[ApiCommandArgument.TypeHierarchyItem],500new ApiCommandResult<ITypeHierarchyItemDto[], types.TypeHierarchyItem[]>('A promise that resolves to an array of TypeHierarchyItem-instances', v => v.map(typeConverters.TypeHierarchyItem.to))501),502new ApiCommand(503'vscode.provideSubtypes', '_executeProvideSubtypes', 'Compute subtypes for an item',504[ApiCommandArgument.TypeHierarchyItem],505new ApiCommandResult<ITypeHierarchyItemDto[], types.TypeHierarchyItem[]>('A promise that resolves to an array of TypeHierarchyItem-instances', v => v.map(typeConverters.TypeHierarchyItem.to))506),507// --- testing508new ApiCommand(509'vscode.revealTestInExplorer', '_revealTestInExplorer', 'Reveals a test instance in the explorer',510[ApiCommandArgument.TestItem],511ApiCommandResult.Void512),513new ApiCommand(514'vscode.startContinuousTestRun', 'testing.startContinuousRunFromExtension', 'Starts running the given tests with continuous run mode.',515[ApiCommandArgument.TestProfile, ApiCommandArgument.Arr(ApiCommandArgument.TestItem)],516ApiCommandResult.Void517),518new ApiCommand(519'vscode.stopContinuousTestRun', 'testing.stopContinuousRunFromExtension', 'Stops running the given tests with continuous run mode.',520[ApiCommandArgument.Arr(ApiCommandArgument.TestItem)],521ApiCommandResult.Void522),523// --- continue edit session524new ApiCommand(525'vscode.experimental.editSession.continue', '_workbench.editSessions.actions.continueEditSession', 'Continue the current edit session in a different workspace',526[ApiCommandArgument.Uri.with('workspaceUri', 'The target workspace to continue the current edit session in')],527ApiCommandResult.Void528),529// --- context keys530new ApiCommand(531'setContext', '_setContext', 'Set a custom context key value that can be used in when clauses.',532[533ApiCommandArgument.String.with('name', 'The context key name'),534new ApiCommandArgument('value', 'The context key value', () => true, v => v),535],536ApiCommandResult.Void537),538// --- inline chat539new ApiCommand(540'vscode.editorChat.start', 'inlineChat.start', 'Invoke a new editor chat session',541[new ApiCommandArgument<InlineChatEditorApiArg | undefined, InlineChatRunOptions | undefined>('Run arguments', '', _v => true, v => {542543if (!v) {544return undefined;545}546547return {548initialRange: v.initialRange ? typeConverters.Range.from(v.initialRange) : undefined,549initialSelection: types.Selection.isSelection(v.initialSelection) ? typeConverters.Selection.from(v.initialSelection) : undefined,550message: v.message,551attachments: v.attachments,552autoSend: v.autoSend,553position: v.position ? typeConverters.Position.from(v.position) : undefined,554resolveOnResponse: v.resolveOnResponse555};556})],557ApiCommandResult.Void558),559// --- extension prompt files560new ApiCommand(561'vscode.extensionPromptFileProvider', '_listExtensionPromptFiles', 'Get all extension-contributed prompt files (custom agents, instructions, and prompt files).',562[],563new ApiCommandResult<IExtensionPromptFileResult[], { uri: vscode.Uri; type: PromptsType }[]>(564'A promise that resolves to an array of objects containing uri and type.',565(value) => {566if (!value) {567return [];568}569return value.map(item => ({570uri: URI.revive(item.uri),571type: item.type572}));573}574)575)576];577578type InlineChatEditorApiArg = {579initialRange?: vscode.Range;580initialSelection?: vscode.Selection;581message?: string;582attachments?: vscode.Uri[];583autoSend?: boolean;584position?: vscode.Position;585resolveOnResponse?: boolean;586};587588type InlineChatRunOptions = {589initialRange?: IRange;590initialSelection?: ISelection;591message?: string;592attachments?: URI[];593autoSend?: boolean;594position?: IPosition;595resolveOnResponse?: boolean;596};597598//#endregion599600601//#region OLD world602603export class ExtHostApiCommands {604605static register(commands: ExtHostCommands) {606607newCommands.forEach(commands.registerApiCommand, commands);608609this._registerValidateWhenClausesCommand(commands);610}611612private static _registerValidateWhenClausesCommand(commands: ExtHostCommands) {613commands.registerCommand(false, '_validateWhenClauses', validateWhenClauses);614}615}616617function tryMapWith<T, R>(f: (x: T) => R) {618return (value: T[]) => {619if (Array.isArray(value)) {620return value.map(f);621}622return undefined;623};624}625626function mapLocationOrLocationLink(values: (languages.Location | languages.LocationLink)[]): (types.Location | vscode.LocationLink)[] | undefined {627if (!Array.isArray(values)) {628return undefined;629}630const result: (types.Location | vscode.LocationLink)[] = [];631for (const item of values) {632if (languages.isLocationLink(item)) {633result.push(typeConverters.DefinitionLink.to(item));634} else {635result.push(typeConverters.location.to(item));636}637}638return result;639}640641642