aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/ssr.ts
blob: 9b814612aaabd6fbadb7fc959c392663af68147c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Ctx, Cmd } from '../ctx';
import { applySourceChange, SourceChange } from '../source_change';
import * as vscode from 'vscode';

export function ssr(ctx: Ctx): Cmd {
    return async () => {
        const client = ctx.client;
        if (!client) return;

        const options: vscode.InputBoxOptions = {
            placeHolder: "foo($a:expr, $b:expr) ==>> bar($a, foo($b))",
            prompt: "Enter request",
            validateInput: (x: string) => {
                if (x.includes('==>>')) {
                    return null;
                }
                return "Enter request: pattern ==>> template";
            }
        };
        const request = await vscode.window.showInputBox(options);

        if (!request) return;

        const ssrRequest: SsrRequest = { arg: request };
        const change = await client.sendRequest<SourceChange>(
            'rust-analyzer/ssr',
            ssrRequest,
        );

        await applySourceChange(ctx, change);
    };
}

interface SsrRequest {
    arg: string;
}