-
-
Notifications
You must be signed in to change notification settings - Fork 920
Expand file tree
/
Copy pathpreviewsuggestions.ts
More file actions
46 lines (42 loc) · 1.39 KB
/
previewsuggestions.ts
File metadata and controls
46 lines (42 loc) · 1.39 KB
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
37
38
39
40
41
42
43
44
45
46
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import { TabRpcClient } from "@/app/store/wshrpcutil";
import { WaveEnv, WaveEnvSubset } from "@/app/waveenv/waveenv";
import { isBlank, makeConnRoute } from "@/util/util";
export type PreviewSuggestionsEnv = WaveEnvSubset<{
rpc: {
FetchSuggestionsCommand: WaveEnv["rpc"]["FetchSuggestionsCommand"];
DisposeSuggestionsCommand: WaveEnv["rpc"]["DisposeSuggestionsCommand"];
};
}>;
type FetchPreviewFileSuggestionsOpts = {
cwd?: string;
connection?: string;
};
export async function fetchPreviewFileSuggestions(
env: PreviewSuggestionsEnv,
query: string,
reqContext: SuggestionRequestContext,
opts?: FetchPreviewFileSuggestionsOpts
): Promise<FetchSuggestionsResponse> {
let route = makeConnRoute(opts?.connection);
if (isBlank(opts?.connection)) {
route = null;
}
if (reqContext?.dispose) {
env.rpc.DisposeSuggestionsCommand(TabRpcClient, reqContext.widgetid, { noresponse: true, route });
return null;
}
return await env.rpc.FetchSuggestionsCommand(
TabRpcClient,
{
suggestiontype: "file",
"file:cwd": opts?.cwd ?? "~",
query,
widgetid: reqContext.widgetid,
reqnum: reqContext.reqnum,
"file:connection": opts?.connection,
},
{ route }
);
}