Skip to content

Commit a313980

Browse files
fix(Sky): Fix text search result mapping and fileSearch params
Update MatchFromHit to read Mountain's actual response format: use `Hit.resource` instead of `Hit.uri`, and `Hit.matches[]` array (each with `preview` and `line_number`) instead of flat per-hit shape. Add backwards-compat support for the old flat `{uri, lineNumber, preview}` format for any future Mountain path that returns it. Fix search:findFiles IPC call to include required null exclude parameter. Without it, MaxResults shifted into the exclude slot, causing the glob extractor to ignore max and default to 10000. This resolves empty search results where previous code produced resource=MakeFileUri("") with empty results array because Mountain's response never contained the expected flat hit fields.
1 parent 18f9fb7 commit a313980

1 file changed

Lines changed: 65 additions & 19 deletions

File tree

Source/Function/SkyBridge.ts

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -874,28 +874,67 @@ export async function InstallSkyBridge(): Promise<void> {
874874
return { scheme: "file", path: FsPath, fsPath: FsPath };
875875
};
876876

877-
// Translate a raw Mountain hit into the `IFileMatch` shape the
878-
// workbench renderer expects.
877+
// Translate a raw Mountain hit into the workbench's `IFileMatch`
878+
// shape.
879+
//
880+
// **Wire shape**: Mountain's `SearchProvider::TextSearch` (in
881+
// `Mountain/Source/Environment/SearchProvider.rs::TextSearch`)
882+
// returns one entry per FILE that contained matches:
883+
//
884+
// ```json
885+
// [
886+
// {
887+
// "resource": "file:///abs/path.ts",
888+
// "matches": [
889+
// { "preview": "line text", "line_number": 42 },
890+
// { "preview": "another", "line_number": 51 }
891+
// ]
892+
// },
893+
// ...
894+
// ]
895+
// ```
896+
//
897+
// **Workbench shape**: `IFileMatch` is one entry per file with
898+
// `results[]` carrying every per-line match (`preview` + range).
899+
// The previous adapter read `Hit.uri` / `Hit.lineNumber` /
900+
// `Hit.preview` (flat per-hit shape) - none of those fields
901+
// exist in Mountain's response, so every search produced
902+
// `resource = MakeFileUri("")` and an empty results array. The
903+
// workbench's dedup map saw N "matches in <empty path>" rows
904+
// and merged them away to nothing visible.
879905
const MatchFromHit = (Hit: any) => {
880-
const Raw = String(Hit?.uri ?? "");
906+
const Raw = String(Hit?.resource ?? Hit?.uri ?? "");
881907
const OsPath = Raw.replace(/^file:\/\//, "");
882-
const Line = Number(Hit?.lineNumber ?? 1);
883-
const Preview = String(Hit?.preview ?? "");
884-
return {
885-
resource: MakeFileUri(OsPath),
886-
results: [
887-
{
888-
preview: { text: Preview, matches: [] },
889-
ranges: [
908+
const PerLineMatches: Array<{ preview: string; lineNumber: number }> =
909+
Array.isArray(Hit?.matches)
910+
? Hit.matches.map((Inner: any) => ({
911+
preview: String(Inner?.preview ?? ""),
912+
lineNumber: Number(
913+
Inner?.line_number ?? Inner?.lineNumber ?? 1,
914+
),
915+
}))
916+
: // Backwards-compat: also accept a flat per-hit shape
917+
// `{ uri, lineNumber, preview }` so any future Mountain
918+
// path that returns flat hits continues to work.
919+
[
890920
{
891-
startLineNumber: Line,
892-
startColumn: 1,
893-
endLineNumber: Line,
894-
endColumn: Math.max(1, Preview.length + 1),
921+
preview: String(Hit?.preview ?? ""),
922+
lineNumber: Number(Hit?.lineNumber ?? Hit?.line_number ?? 1),
895923
},
896-
],
897-
},
898-
],
924+
];
925+
return {
926+
resource: MakeFileUri(OsPath),
927+
results: PerLineMatches.map((M) => ({
928+
preview: { text: M.preview, matches: [] },
929+
ranges: [
930+
{
931+
startLineNumber: M.lineNumber,
932+
startColumn: 1,
933+
endLineNumber: M.lineNumber,
934+
endColumn: Math.max(1, M.preview.length + 1),
935+
},
936+
],
937+
})),
899938
};
900939
};
901940

@@ -973,9 +1012,16 @@ export async function InstallSkyBridge(): Promise<void> {
9731012
message: `[SkyBridge] fileSearch invoked pattern="${Raw}" glob="${Glob}" max=${MaxResults}`,
9741013
}).catch(() => {});
9751014
try {
1015+
// Positional contract for `search:findFiles` (see
1016+
// `Mountain/Source/IPC/WindServiceHandlers/Search.rs::handle_search_find_files`):
1017+
// [include, exclude?, max?, useIgnore?, followSymlinks?]
1018+
// `null` for exclude is required - dropping it shifts
1019+
// `MaxResults` into the exclude slot which the
1020+
// glob-extractor then ignores, leaving max defaulted
1021+
// to 10000 instead of the requested cap.
9761022
const Files = (await invoke("MountainIPCInvoke", {
9771023
method: "search:findFiles",
978-
params: [Glob, MaxResults],
1024+
params: [Glob, null, MaxResults],
9791025
})) as string[];
9801026
const Results = (Files ?? []).map((Uri) => ({
9811027
resource: MakeFileUri(

0 commit comments

Comments
 (0)