Path: blob/main/src/vs/workbench/api/common/extHostApiCommands.ts
3296 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';2425//#region --- NEW world2627const newCommands: ApiCommand[] = [28// -- document highlights29new ApiCommand(30'vscode.executeDocumentHighlights', '_executeDocumentHighlights', 'Execute document highlight provider.',31[ApiCommandArgument.Uri, ApiCommandArgument.Position],32new ApiCommandResult<languages.DocumentHighlight[], types.DocumentHighlight[] | undefined>('A promise that resolves to an array of DocumentHighlight-instances.', tryMapWith(typeConverters.DocumentHighlight.to))33),34// -- document symbols35new ApiCommand(36'vscode.executeDocumentSymbolProvider', '_executeDocumentSymbolProvider', 'Execute document symbol provider.',37[ApiCommandArgument.Uri],38new ApiCommandResult<languages.DocumentSymbol[], vscode.SymbolInformation[] | undefined>('A promise that resolves to an array of SymbolInformation and DocumentSymbol instances.', (value, apiArgs) => {3940if (isFalsyOrEmpty(value)) {41return undefined;42}43class MergedInfo extends types.SymbolInformation implements vscode.DocumentSymbol {44static to(symbol: languages.DocumentSymbol): MergedInfo {45const res = new MergedInfo(46symbol.name,47typeConverters.SymbolKind.to(symbol.kind),48symbol.containerName || '',49new types.Location(apiArgs[0], typeConverters.Range.to(symbol.range))50);51res.detail = symbol.detail;52res.range = res.location.range;53res.selectionRange = typeConverters.Range.to(symbol.selectionRange);54res.children = symbol.children ? symbol.children.map(MergedInfo.to) : [];55return res;56}5758detail!: string;59range!: vscode.Range;60selectionRange!: vscode.Range;61children!: vscode.DocumentSymbol[];62override containerName: string = '';63}64return value.map(MergedInfo.to);6566})67),68// -- formatting69new ApiCommand(70'vscode.executeFormatDocumentProvider', '_executeFormatDocumentProvider', 'Execute document format provider.',71[ApiCommandArgument.Uri, new ApiCommandArgument('options', 'Formatting options', _ => true, v => v)],72new ApiCommandResult<languages.TextEdit[], types.TextEdit[] | undefined>('A promise that resolves to an array of TextEdits.', tryMapWith(typeConverters.TextEdit.to))73),74new ApiCommand(75'vscode.executeFormatRangeProvider', '_executeFormatRangeProvider', 'Execute range format provider.',76[ApiCommandArgument.Uri, ApiCommandArgument.Range, new ApiCommandArgument('options', 'Formatting options', _ => true, v => v)],77new ApiCommandResult<languages.TextEdit[], types.TextEdit[] | undefined>('A promise that resolves to an array of TextEdits.', tryMapWith(typeConverters.TextEdit.to))78),79new ApiCommand(80'vscode.executeFormatOnTypeProvider', '_executeFormatOnTypeProvider', 'Execute format on type provider.',81[ApiCommandArgument.Uri, ApiCommandArgument.Position, new ApiCommandArgument('ch', 'Trigger character', v => typeof v === 'string', v => v), new ApiCommandArgument('options', 'Formatting options', _ => true, v => v)],82new ApiCommandResult<languages.TextEdit[], types.TextEdit[] | undefined>('A promise that resolves to an array of TextEdits.', tryMapWith(typeConverters.TextEdit.to))83),84// -- go to symbol (definition, type definition, declaration, impl, references)85new ApiCommand(86'vscode.executeDefinitionProvider', '_executeDefinitionProvider', 'Execute all definition providers.',87[ApiCommandArgument.Uri, ApiCommandArgument.Position],88new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)89),90new ApiCommand(91'vscode.experimental.executeDefinitionProvider_recursive', '_executeDefinitionProvider_recursive', 'Execute all definition providers.',92[ApiCommandArgument.Uri, ApiCommandArgument.Position],93new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)94),95new ApiCommand(96'vscode.executeTypeDefinitionProvider', '_executeTypeDefinitionProvider', 'Execute all type definition providers.',97[ApiCommandArgument.Uri, ApiCommandArgument.Position],98new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)99),100new ApiCommand(101'vscode.experimental.executeTypeDefinitionProvider_recursive', '_executeTypeDefinitionProvider_recursive', 'Execute all type definition providers.',102[ApiCommandArgument.Uri, ApiCommandArgument.Position],103new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)104),105new ApiCommand(106'vscode.executeDeclarationProvider', '_executeDeclarationProvider', 'Execute all declaration providers.',107[ApiCommandArgument.Uri, ApiCommandArgument.Position],108new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)109),110new ApiCommand(111'vscode.experimental.executeDeclarationProvider_recursive', '_executeDeclarationProvider_recursive', 'Execute all declaration providers.',112[ApiCommandArgument.Uri, ApiCommandArgument.Position],113new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)114),115new ApiCommand(116'vscode.executeImplementationProvider', '_executeImplementationProvider', 'Execute all implementation providers.',117[ApiCommandArgument.Uri, ApiCommandArgument.Position],118new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)119),120new ApiCommand(121'vscode.experimental.executeImplementationProvider_recursive', '_executeImplementationProvider_recursive', 'Execute all implementation providers.',122[ApiCommandArgument.Uri, ApiCommandArgument.Position],123new ApiCommandResult<(languages.Location | languages.LocationLink)[], (types.Location | vscode.LocationLink)[] | undefined>('A promise that resolves to an array of Location or LocationLink instances.', mapLocationOrLocationLink)124),125new ApiCommand(126'vscode.executeReferenceProvider', '_executeReferenceProvider', 'Execute all reference providers.',127[ApiCommandArgument.Uri, ApiCommandArgument.Position],128new ApiCommandResult<languages.Location[], types.Location[] | undefined>('A promise that resolves to an array of Location-instances.', tryMapWith(typeConverters.location.to))129),130new ApiCommand(131'vscode.experimental.executeReferenceProvider', '_executeReferenceProvider_recursive', 'Execute all reference providers.',132[ApiCommandArgument.Uri, ApiCommandArgument.Position],133new ApiCommandResult<languages.Location[], types.Location[] | undefined>('A promise that resolves to an array of Location-instances.', tryMapWith(typeConverters.location.to))134),135// -- hover136new ApiCommand(137'vscode.executeHoverProvider', '_executeHoverProvider', 'Execute all hover providers.',138[ApiCommandArgument.Uri, ApiCommandArgument.Position],139new ApiCommandResult<languages.Hover[], types.Hover[] | undefined>('A promise that resolves to an array of Hover-instances.', tryMapWith(typeConverters.Hover.to))140),141new ApiCommand(142'vscode.experimental.executeHoverProvider_recursive', '_executeHoverProvider_recursive', 'Execute all hover providers.',143[ApiCommandArgument.Uri, ApiCommandArgument.Position],144new ApiCommandResult<languages.Hover[], types.Hover[] | undefined>('A promise that resolves to an array of Hover-instances.', tryMapWith(typeConverters.Hover.to))145),146// -- selection range147new ApiCommand(148'vscode.executeSelectionRangeProvider', '_executeSelectionRangeProvider', 'Execute selection range provider.',149[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))],150new ApiCommandResult<IRange[][], types.SelectionRange[]>('A promise that resolves to an array of ranges.', result => {151return result.map(ranges => {152let node: types.SelectionRange | undefined;153for (const range of ranges.reverse()) {154node = new types.SelectionRange(typeConverters.Range.to(range), node);155}156return node!;157});158})159),160// -- symbol search161new ApiCommand(162'vscode.executeWorkspaceSymbolProvider', '_executeWorkspaceSymbolProvider', 'Execute all workspace symbol providers.',163[ApiCommandArgument.String.with('query', 'Search string')],164new ApiCommandResult<search.IWorkspaceSymbol[], types.SymbolInformation[]>('A promise that resolves to an array of SymbolInformation-instances.', value => {165return value.map(typeConverters.WorkspaceSymbol.to);166})167),168// --- call hierarchy169new ApiCommand(170'vscode.prepareCallHierarchy', '_executePrepareCallHierarchy', 'Prepare call hierarchy at a position inside a document',171[ApiCommandArgument.Uri, ApiCommandArgument.Position],172new ApiCommandResult<ICallHierarchyItemDto[], types.CallHierarchyItem[]>('A promise that resolves to an array of CallHierarchyItem-instances', v => v.map(typeConverters.CallHierarchyItem.to))173),174new ApiCommand(175'vscode.provideIncomingCalls', '_executeProvideIncomingCalls', 'Compute incoming calls for an item',176[ApiCommandArgument.CallHierarchyItem],177new ApiCommandResult<IIncomingCallDto[], types.CallHierarchyIncomingCall[]>('A promise that resolves to an array of CallHierarchyIncomingCall-instances', v => v.map(typeConverters.CallHierarchyIncomingCall.to))178),179new ApiCommand(180'vscode.provideOutgoingCalls', '_executeProvideOutgoingCalls', 'Compute outgoing calls for an item',181[ApiCommandArgument.CallHierarchyItem],182new ApiCommandResult<IOutgoingCallDto[], types.CallHierarchyOutgoingCall[]>('A promise that resolves to an array of CallHierarchyOutgoingCall-instances', v => v.map(typeConverters.CallHierarchyOutgoingCall.to))183),184// --- rename185new ApiCommand(186'vscode.prepareRename', '_executePrepareRename', 'Execute the prepareRename of rename provider.',187[ApiCommandArgument.Uri, ApiCommandArgument.Position],188new ApiCommandResult<languages.RenameLocation, { range: types.Range; placeholder: string } | undefined>('A promise that resolves to a range and placeholder text.', value => {189if (!value) {190return undefined;191}192return {193range: typeConverters.Range.to(value.range),194placeholder: value.text195};196})197),198new ApiCommand(199'vscode.executeDocumentRenameProvider', '_executeDocumentRenameProvider', 'Execute rename provider.',200[ApiCommandArgument.Uri, ApiCommandArgument.Position, ApiCommandArgument.String.with('newName', 'The new symbol name')],201new ApiCommandResult<IWorkspaceEditDto & { rejectReason?: string }, types.WorkspaceEdit | undefined>('A promise that resolves to a WorkspaceEdit.', value => {202if (!value) {203return undefined;204}205if (value.rejectReason) {206throw new Error(value.rejectReason);207}208return typeConverters.WorkspaceEdit.to(value);209})210),211// --- links212new ApiCommand(213'vscode.executeLinkProvider', '_executeLinkProvider', 'Execute document link provider.',214[ApiCommandArgument.Uri, ApiCommandArgument.Number.with('linkResolveCount', 'Number of links that should be resolved, only when links are unresolved.').optional()],215new ApiCommandResult<languages.ILink[], vscode.DocumentLink[]>('A promise that resolves to an array of DocumentLink-instances.', value => value.map(typeConverters.DocumentLink.to))216),217// --- semantic tokens218new ApiCommand(219'vscode.provideDocumentSemanticTokensLegend', '_provideDocumentSemanticTokensLegend', 'Provide semantic tokens legend for a document',220[ApiCommandArgument.Uri],221new ApiCommandResult<languages.SemanticTokensLegend, types.SemanticTokensLegend | undefined>('A promise that resolves to SemanticTokensLegend.', value => {222if (!value) {223return undefined;224}225return new types.SemanticTokensLegend(value.tokenTypes, value.tokenModifiers);226})227),228new ApiCommand(229'vscode.provideDocumentSemanticTokens', '_provideDocumentSemanticTokens', 'Provide semantic tokens for a document',230[ApiCommandArgument.Uri],231new ApiCommandResult<VSBuffer, types.SemanticTokens | undefined>('A promise that resolves to SemanticTokens.', value => {232if (!value) {233return undefined;234}235const semanticTokensDto = decodeSemanticTokensDto(value);236if (semanticTokensDto.type !== 'full') {237// only accepting full semantic tokens from provideDocumentSemanticTokens238return undefined;239}240return new types.SemanticTokens(semanticTokensDto.data, undefined);241})242),243new ApiCommand(244'vscode.provideDocumentRangeSemanticTokensLegend', '_provideDocumentRangeSemanticTokensLegend', 'Provide semantic tokens legend for a document range',245[ApiCommandArgument.Uri, ApiCommandArgument.Range.optional()],246new ApiCommandResult<languages.SemanticTokensLegend, types.SemanticTokensLegend | undefined>('A promise that resolves to SemanticTokensLegend.', value => {247if (!value) {248return undefined;249}250return new types.SemanticTokensLegend(value.tokenTypes, value.tokenModifiers);251})252),253new ApiCommand(254'vscode.provideDocumentRangeSemanticTokens', '_provideDocumentRangeSemanticTokens', 'Provide semantic tokens for a document range',255[ApiCommandArgument.Uri, ApiCommandArgument.Range],256new ApiCommandResult<VSBuffer, types.SemanticTokens | undefined>('A promise that resolves to SemanticTokens.', value => {257if (!value) {258return undefined;259}260const semanticTokensDto = decodeSemanticTokensDto(value);261if (semanticTokensDto.type !== 'full') {262// only accepting full semantic tokens from provideDocumentRangeSemanticTokens263return undefined;264}265return new types.SemanticTokens(semanticTokensDto.data, undefined);266})267),268// --- completions269new ApiCommand(270'vscode.executeCompletionItemProvider', '_executeCompletionItemProvider', 'Execute completion item provider.',271[272ApiCommandArgument.Uri,273ApiCommandArgument.Position,274ApiCommandArgument.String.with('triggerCharacter', 'Trigger completion when the user types the character, like `,` or `(`').optional(),275ApiCommandArgument.Number.with('itemResolveCount', 'Number of completions to resolve (too large numbers slow down completions)').optional()276],277new ApiCommandResult<languages.CompletionList, vscode.CompletionList>('A promise that resolves to a CompletionList-instance.', (value, _args, converter) => {278if (!value) {279return new types.CompletionList([]);280}281const items = value.suggestions.map(suggestion => typeConverters.CompletionItem.to(suggestion, converter));282return new types.CompletionList(items, value.incomplete);283})284),285// --- signature help286new ApiCommand(287'vscode.executeSignatureHelpProvider', '_executeSignatureHelpProvider', 'Execute signature help provider.',288[ApiCommandArgument.Uri, ApiCommandArgument.Position, ApiCommandArgument.String.with('triggerCharacter', 'Trigger signature help when the user types the character, like `,` or `(`').optional()],289new ApiCommandResult<languages.SignatureHelp, vscode.SignatureHelp | undefined>('A promise that resolves to SignatureHelp.', value => {290if (value) {291return typeConverters.SignatureHelp.to(value);292}293return undefined;294})295),296// --- code lens297new ApiCommand(298'vscode.executeCodeLensProvider', '_executeCodeLensProvider', 'Execute code lens provider.',299[ApiCommandArgument.Uri, ApiCommandArgument.Number.with('itemResolveCount', 'Number of lenses that should be resolved and returned. Will only return resolved lenses, will impact performance)').optional()],300new ApiCommandResult<languages.CodeLens[], vscode.CodeLens[] | undefined>('A promise that resolves to an array of CodeLens-instances.', (value, _args, converter) => {301return tryMapWith<languages.CodeLens, vscode.CodeLens>(item => {302return new types.CodeLens(typeConverters.Range.to(item.range), item.command && converter.fromInternal(item.command));303})(value);304})305),306// --- code actions307new ApiCommand(308'vscode.executeCodeActionProvider', '_executeCodeActionProvider', 'Execute code action provider.',309[310ApiCommandArgument.Uri,311new 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)),312ApiCommandArgument.String.with('kind', 'Code action kind to return code actions for').optional(),313ApiCommandArgument.Number.with('itemResolveCount', 'Number of code actions to resolve (too large numbers slow down code actions)').optional()314],315new ApiCommandResult<CustomCodeAction[], (vscode.CodeAction | vscode.Command | undefined)[] | undefined>('A promise that resolves to an array of Command-instances.', (value, _args, converter) => {316return tryMapWith<CustomCodeAction, vscode.CodeAction | vscode.Command | undefined>((codeAction) => {317if (codeAction._isSynthetic) {318if (!codeAction.command) {319throw new Error('Synthetic code actions must have a command');320}321return converter.fromInternal(codeAction.command);322} else {323const ret = new types.CodeAction(324codeAction.title,325codeAction.kind ? new types.CodeActionKind(codeAction.kind) : undefined326);327if (codeAction.edit) {328ret.edit = typeConverters.WorkspaceEdit.to(codeAction.edit);329}330if (codeAction.command) {331ret.command = converter.fromInternal(codeAction.command);332}333ret.isPreferred = codeAction.isPreferred;334return ret;335}336})(value);337})338),339// --- colors340new ApiCommand(341'vscode.executeDocumentColorProvider', '_executeDocumentColorProvider', 'Execute document color provider.',342[ApiCommandArgument.Uri],343new ApiCommandResult<IRawColorInfo[], vscode.ColorInformation[]>('A promise that resolves to an array of ColorInformation objects.', result => {344if (result) {345return result.map(ci => new types.ColorInformation(typeConverters.Range.to(ci.range), typeConverters.Color.to(ci.color)));346}347return [];348})349),350new ApiCommand(351'vscode.executeColorPresentationProvider', '_executeColorPresentationProvider', 'Execute color presentation provider.',352[353new ApiCommandArgument<types.Color, [number, number, number, number]>('color', 'The color to show and insert', v => v instanceof types.Color, typeConverters.Color.from),354new 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) })),355],356new ApiCommandResult<languages.IColorPresentation[], types.ColorPresentation[]>('A promise that resolves to an array of ColorPresentation objects.', result => {357if (result) {358return result.map(typeConverters.ColorPresentation.to);359}360return [];361})362),363// --- inline hints364new ApiCommand(365'vscode.executeInlayHintProvider', '_executeInlayHintProvider', 'Execute inlay hints provider',366[ApiCommandArgument.Uri, ApiCommandArgument.Range],367new ApiCommandResult<languages.InlayHint[], vscode.InlayHint[]>('A promise that resolves to an array of Inlay objects', (result, args, converter) => {368return result.map(typeConverters.InlayHint.to.bind(undefined, converter));369})370),371// --- folding372new ApiCommand(373'vscode.executeFoldingRangeProvider', '_executeFoldingRangeProvider', 'Execute folding range provider',374[ApiCommandArgument.Uri],375new ApiCommandResult<languages.FoldingRange[] | undefined, vscode.FoldingRange[] | undefined>('A promise that resolves to an array of FoldingRange objects', (result, args) => {376if (result) {377return result.map(typeConverters.FoldingRange.to);378}379return undefined;380})381),382383// --- notebooks384new ApiCommand(385'vscode.resolveNotebookContentProviders', '_resolveNotebookContentProvider', 'Resolve Notebook Content Providers',386[387// new ApiCommandArgument<string, string>('viewType', '', v => typeof v === 'string', v => v),388// new ApiCommandArgument<string, string>('displayName', '', v => typeof v === 'string', v => v),389// new ApiCommandArgument<object, object>('options', '', v => typeof v === 'object', v => v),390],391new ApiCommandResult<{392viewType: string;393displayName: string;394options: { transientOutputs: boolean; transientCellMetadata: TransientCellMetadata; transientDocumentMetadata: TransientDocumentMetadata };395filenamePattern: (vscode.GlobPattern | { include: vscode.GlobPattern; exclude: vscode.GlobPattern })[];396}[], {397viewType: string;398displayName: string;399filenamePattern: (vscode.GlobPattern | { include: vscode.GlobPattern; exclude: vscode.GlobPattern })[];400options: vscode.NotebookDocumentContentOptions;401}[] | undefined>('A promise that resolves to an array of NotebookContentProvider static info objects.', tryMapWith(item => {402return {403viewType: item.viewType,404displayName: item.displayName,405options: {406transientOutputs: item.options.transientOutputs,407transientCellMetadata: item.options.transientCellMetadata,408transientDocumentMetadata: item.options.transientDocumentMetadata409},410filenamePattern: item.filenamePattern.map(pattern => typeConverters.NotebookExclusiveDocumentPattern.to(pattern))411};412}))413),414// --- debug support415new ApiCommand(416'vscode.executeInlineValueProvider', '_executeInlineValueProvider', 'Execute inline value provider',417[418ApiCommandArgument.Uri,419ApiCommandArgument.Range,420new ApiCommandArgument<types.InlineValueContext, IInlineValueContextDto>('context', 'An InlineValueContext', v => v && typeof v.frameId === 'number' && v.stoppedLocation instanceof types.Range, v => typeConverters.InlineValueContext.from(v))421],422new ApiCommandResult<languages.InlineValue[], vscode.InlineValue[]>('A promise that resolves to an array of InlineValue objects', result => {423return result.map(typeConverters.InlineValue.to);424})425),426// --- open'ish commands427new ApiCommand(428'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.',429[430new 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),431new ApiCommandArgument<vscode.ViewColumn | typeConverters.TextEditorOpenOptions | undefined, [vscode.ViewColumn?, ITextEditorOptions?] | undefined>('columnOrOptions', 'Either the column in which to open or editor options, see vscode.TextDocumentShowOptions',432v => v === undefined || typeof v === 'number' || typeof v === 'object',433v => !v ? v : typeof v === 'number' ? [typeConverters.ViewColumn.from(v), undefined] : [typeConverters.ViewColumn.from(v.viewColumn), typeConverters.TextEditorOpenOptions.from(v)]434).optional(),435ApiCommandArgument.String.with('label', '').optional()436],437ApiCommandResult.Void438),439new ApiCommand(440'vscode.openWith', '_workbench.openWith', 'Opens the provided resource with a specific editor.',441[442ApiCommandArgument.Uri.with('resource', 'Resource to open'),443ApiCommandArgument.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'),444new ApiCommandArgument<vscode.ViewColumn | typeConverters.TextEditorOpenOptions | undefined, [vscode.ViewColumn?, ITextEditorOptions?] | undefined>('columnOrOptions', 'Either the column in which to open or editor options, see vscode.TextDocumentShowOptions',445v => v === undefined || typeof v === 'number' || typeof v === 'object',446v => !v ? v : typeof v === 'number' ? [typeConverters.ViewColumn.from(v), undefined] : [typeConverters.ViewColumn.from(v.viewColumn), typeConverters.TextEditorOpenOptions.from(v)],447).optional()448],449ApiCommandResult.Void450),451new ApiCommand(452'vscode.diff', '_workbench.diff', 'Opens the provided resources in the diff editor to compare their contents.',453[454ApiCommandArgument.Uri.with('left', 'Left-hand side resource of the diff editor'),455ApiCommandArgument.Uri.with('right', 'Right-hand side resource of the diff editor'),456ApiCommandArgument.String.with('title', 'Human readable title for the diff editor').optional(),457new ApiCommandArgument<typeConverters.TextEditorOpenOptions | undefined, [number?, ITextEditorOptions?] | undefined>('columnOrOptions', 'Either the column in which to open or editor options, see vscode.TextDocumentShowOptions',458v => v === undefined || typeof v === 'object',459v => v && [typeConverters.ViewColumn.from(v.viewColumn), typeConverters.TextEditorOpenOptions.from(v)]460).optional(),461],462ApiCommandResult.Void463),464new ApiCommand(465'vscode.changes', '_workbench.changes', 'Opens a list of resources in the changes editor to compare their contents.',466[467ApiCommandArgument.String.with('title', 'Human readable title for the changes editor'),468new ApiCommandArgument<[URI, URI?, URI?][]>('resourceList', 'List of resources to compare',469resources => {470for (const resource of resources) {471if (resource.length !== 3) {472return false;473}474475const [label, left, right] = resource;476if (!URI.isUri(label) ||477(!URI.isUri(left) && left !== undefined && left !== null) ||478(!URI.isUri(right) && right !== undefined && right !== null)) {479return false;480}481}482483return true;484},485v => v)486],487ApiCommandResult.Void488),489// --- type hierarchy490new ApiCommand(491'vscode.prepareTypeHierarchy', '_executePrepareTypeHierarchy', 'Prepare type hierarchy at a position inside a document',492[ApiCommandArgument.Uri, ApiCommandArgument.Position],493new ApiCommandResult<ITypeHierarchyItemDto[], types.TypeHierarchyItem[]>('A promise that resolves to an array of TypeHierarchyItem-instances', v => v.map(typeConverters.TypeHierarchyItem.to))494),495new ApiCommand(496'vscode.provideSupertypes', '_executeProvideSupertypes', 'Compute supertypes for an item',497[ApiCommandArgument.TypeHierarchyItem],498new ApiCommandResult<ITypeHierarchyItemDto[], types.TypeHierarchyItem[]>('A promise that resolves to an array of TypeHierarchyItem-instances', v => v.map(typeConverters.TypeHierarchyItem.to))499),500new ApiCommand(501'vscode.provideSubtypes', '_executeProvideSubtypes', 'Compute subtypes for an item',502[ApiCommandArgument.TypeHierarchyItem],503new ApiCommandResult<ITypeHierarchyItemDto[], types.TypeHierarchyItem[]>('A promise that resolves to an array of TypeHierarchyItem-instances', v => v.map(typeConverters.TypeHierarchyItem.to))504),505// --- testing506new ApiCommand(507'vscode.revealTestInExplorer', '_revealTestInExplorer', 'Reveals a test instance in the explorer',508[ApiCommandArgument.TestItem],509ApiCommandResult.Void510),511new ApiCommand(512'vscode.startContinuousTestRun', 'testing.startContinuousRunFromExtension', 'Starts running the given tests with continuous run mode.',513[ApiCommandArgument.TestProfile, ApiCommandArgument.Arr(ApiCommandArgument.TestItem)],514ApiCommandResult.Void515),516new ApiCommand(517'vscode.stopContinuousTestRun', 'testing.stopContinuousRunFromExtension', 'Stops running the given tests with continuous run mode.',518[ApiCommandArgument.Arr(ApiCommandArgument.TestItem)],519ApiCommandResult.Void520),521// --- continue edit session522new ApiCommand(523'vscode.experimental.editSession.continue', '_workbench.editSessions.actions.continueEditSession', 'Continue the current edit session in a different workspace',524[ApiCommandArgument.Uri.with('workspaceUri', 'The target workspace to continue the current edit session in')],525ApiCommandResult.Void526),527// --- context keys528new ApiCommand(529'setContext', '_setContext', 'Set a custom context key value that can be used in when clauses.',530[531ApiCommandArgument.String.with('name', 'The context key name'),532new ApiCommandArgument('value', 'The context key value', () => true, v => v),533],534ApiCommandResult.Void535),536// --- inline chat537new ApiCommand(538'vscode.editorChat.start', 'inlineChat.start', 'Invoke a new editor chat session',539[new ApiCommandArgument<InlineChatEditorApiArg | undefined, InlineChatRunOptions | undefined>('Run arguments', '', _v => true, v => {540541if (!v) {542return undefined;543}544545return {546initialRange: v.initialRange ? typeConverters.Range.from(v.initialRange) : undefined,547initialSelection: types.Selection.isSelection(v.initialSelection) ? typeConverters.Selection.from(v.initialSelection) : undefined,548message: v.message,549attachments: v.attachments,550autoSend: v.autoSend,551position: v.position ? typeConverters.Position.from(v.position) : undefined,552};553})],554ApiCommandResult.Void555)556];557558type InlineChatEditorApiArg = {559initialRange?: vscode.Range;560initialSelection?: vscode.Selection;561message?: string;562attachments?: vscode.Uri[];563autoSend?: boolean;564position?: vscode.Position;565};566567type InlineChatRunOptions = {568initialRange?: IRange;569initialSelection?: ISelection;570message?: string;571attachments?: URI[];572autoSend?: boolean;573position?: IPosition;574};575576//#endregion577578579//#region OLD world580581export class ExtHostApiCommands {582583static register(commands: ExtHostCommands) {584585newCommands.forEach(commands.registerApiCommand, commands);586587this._registerValidateWhenClausesCommand(commands);588}589590private static _registerValidateWhenClausesCommand(commands: ExtHostCommands) {591commands.registerCommand(false, '_validateWhenClauses', validateWhenClauses);592}593}594595function tryMapWith<T, R>(f: (x: T) => R) {596return (value: T[]) => {597if (Array.isArray(value)) {598return value.map(f);599}600return undefined;601};602}603604function mapLocationOrLocationLink(values: (languages.Location | languages.LocationLink)[]): (types.Location | vscode.LocationLink)[] | undefined {605if (!Array.isArray(values)) {606return undefined;607}608const result: (types.Location | vscode.LocationLink)[] = [];609for (const item of values) {610if (languages.isLocationLink(item)) {611result.push(typeConverters.DefinitionLink.to(item));612} else {613result.push(typeConverters.location.to(item));614}615}616return result;617}618619620