Skip to content

Commit 6184960

Browse files
feat(Sky): Add column-based match highlighting for text search results
Parse Mountain's `columns` array (0-based UTF-8 char offsets) and transform into VS Code's 1-based `ISearchRange` format for result ranges. Also populate `preview.matches` with preview-local coordinates so the renderer shows the actual matched-substring highlight inside each line. Previously all matches displayed as full-line highlights with no sub-line underline. With columns, users now see precise character-level highlighting in the search results widget.
1 parent a313980 commit 6184960

1 file changed

Lines changed: 71 additions & 28 deletions

File tree

Source/Function/SkyBridge.ts

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -905,36 +905,79 @@ export async function InstallSkyBridge(): Promise<void> {
905905
const MatchFromHit = (Hit: any) => {
906906
const Raw = String(Hit?.resource ?? Hit?.uri ?? "");
907907
const OsPath = Raw.replace(/^file:\/\//, "");
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-
[
920-
{
921-
preview: String(Hit?.preview ?? ""),
922-
lineNumber: Number(Hit?.lineNumber ?? Hit?.line_number ?? 1),
923-
},
924-
];
925-
return {
926-
resource: MakeFileUri(OsPath),
927-
results: PerLineMatches.map((M) => ({
928-
preview: { text: M.preview, matches: [] },
929-
ranges: [
908+
type LineHit = {
909+
preview: string;
910+
lineNumber: number;
911+
columns: Array<{ start: number; end: number }>;
912+
};
913+
const PerLineMatches: LineHit[] = Array.isArray(Hit?.matches)
914+
? Hit.matches.map((Inner: any) => ({
915+
preview: String(Inner?.preview ?? ""),
916+
lineNumber: Number(
917+
Inner?.line_number ?? Inner?.lineNumber ?? 1,
918+
),
919+
columns: Array.isArray(Inner?.columns)
920+
? Inner.columns.map((C: any) => ({
921+
start: Number(C?.start ?? 0),
922+
end: Number(C?.end ?? 0),
923+
}))
924+
: [],
925+
}))
926+
: // Backwards-compat: also accept a flat per-hit shape
927+
// `{ uri, lineNumber, preview }` for any future Mountain
928+
// path that returns flat hits.
929+
[
930930
{
931-
startLineNumber: M.lineNumber,
932-
startColumn: 1,
933-
endLineNumber: M.lineNumber,
934-
endColumn: Math.max(1, M.preview.length + 1),
931+
preview: String(Hit?.preview ?? ""),
932+
lineNumber: Number(Hit?.lineNumber ?? Hit?.line_number ?? 1),
933+
columns: [],
935934
},
936-
],
937-
})),
935+
];
936+
return {
937+
resource: MakeFileUri(OsPath),
938+
results: PerLineMatches.map((M) => {
939+
// VS Code's `ISearchRange`: 1-based for line, 0-based
940+
// for column. Mountain's columns array is already
941+
// 0-based UTF-8 char offsets within the preview line.
942+
// When Mountain didn't supply columns (older ripgrep
943+
// path or zero-width match), highlight the whole
944+
// line so the user still sees the row but without
945+
// a sub-line underline.
946+
const Ranges =
947+
M.columns.length > 0
948+
? M.columns.map((C) => ({
949+
startLineNumber: M.lineNumber,
950+
startColumn: C.start + 1,
951+
endLineNumber: M.lineNumber,
952+
endColumn: C.end + 1,
953+
}))
954+
: [
955+
{
956+
startLineNumber: M.lineNumber,
957+
startColumn: 1,
958+
endLineNumber: M.lineNumber,
959+
endColumn: Math.max(1, M.preview.length + 1),
960+
},
961+
];
962+
// `preview.matches` is the SAME range list but
963+
// translated into preview-local coordinates (line 1,
964+
// column relative to preview start). Without this the
965+
// renderer shows the row but no matched-substring
966+
// highlight inside the line.
967+
const PreviewMatches =
968+
M.columns.length > 0
969+
? M.columns.map((C) => ({
970+
startLineNumber: 1,
971+
startColumn: C.start + 1,
972+
endLineNumber: 1,
973+
endColumn: C.end + 1,
974+
}))
975+
: [];
976+
return {
977+
preview: { text: M.preview, matches: PreviewMatches },
978+
ranges: Ranges,
979+
};
980+
}),
938981
};
939982
};
940983

0 commit comments

Comments
 (0)