MCPcopy Create free account
hub / github.com/angular/angular / registerCommands

Function registerCommands

ngp-vscode-ng-language-service/client/src/commands.ts:12–67  ·  view source on GitHub ↗
(
  context: vscode.ExtensionContext,
  client: LanguageClient,
  outputChannel: vscode.OutputChannel,
)

Source from the content-addressed store, hash-verified

10import {LanguageClient} from 'vscode-languageclient/node';
11
12export function registerCommands(
13 context: vscode.ExtensionContext,
14 client: LanguageClient,
15 outputChannel: vscode.OutputChannel,
16) {
17 const TCB_HIGHLIGHT_DECORATION = vscode.window.createTextEditorDecorationType({
18 backgroundColor: new vscode.ThemeColor('editor.selectionHighlightBackground'),
19 });
20
21 const tcbProvider = new TcbContentProvider();
22 context.subscriptions.push(
23 vscode.workspace.registerTextDocumentContentProvider('ng', tcbProvider),
24 );
25
26 context.subscriptions.push(
27 vscode.commands.registerTextEditorCommand('angular.getTemplateTcb', async (textEditor) => {
28 tcbProvider.clear();
29 try {
30 outputChannel.appendLine('Requesting TCB from server...');
31 const response = (await client.sendRequest('angular/getTcb', {
32 textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(textEditor.document),
33 position: client.code2ProtocolConverter.asPosition(textEditor.selection.active),
34 })) as {uri: string; content: string; selections: any[]} | null;
35
36 if (!response) {
37 vscode.window.showInformationMessage('No TCB available for this position.');
38 return;
39 }
40
41 outputChannel.appendLine(
42 `Received TCB response. Content length: ${response.content.length}`,
43 );
44
45 const tcbUri = vscode.Uri.parse(response.uri).with({
46 scheme: 'ng',
47 });
48 tcbProvider.update(tcbUri, response.content);
49 const editor = await vscode.window.showTextDocument(tcbUri, {
50 viewColumn: vscode.ViewColumn.Beside,
51 preserveFocus: true,
52 });
53
54 const selections = response.selections.map((s: any) => {
55 return new vscode.Range(
56 new vscode.Position(s.start.line, s.start.character),
57 new vscode.Position(s.end.line, s.end.character),
58 );
59 });
60
61 editor.setDecorations(TCB_HIGHLIGHT_DECORATION, selections);
62 } catch (err) {
63 vscode.window.showErrorMessage(`Failed to get TCB: ${err}`);
64 }
65 }),
66 );
67}
68
69class TcbContentProvider implements vscode.TextDocumentContentProvider {

Callers 1

activateFunction · 0.90

Calls 5

clearMethod · 0.95
updateMethod · 0.95
mapMethod · 0.80
parseMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected