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