Skip to content

Commit 695282d

Browse files
authored
search: fix symbol match URLs (#7)
1 parent d6643e2 commit 695282d

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- **search**: Fix URL opened by `symbol` match results. ([#7](https://github.com/bobheadxi/raycast-sourcegraph/pull/7))
6+
37
## [Feb 7, 2022](https://github.com/raycast/extensions/pull/833)
48

59
- **search**: Fix off-by-one issue when opening `content` match results.

‎src/components/search.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function SearchResultItem({
170170
title = match.symbols.map((s) => s.name).join(", ");
171171
subtitle = match.path;
172172
if (match.symbols.length === 1) {
173-
url = `${searchResult.url}${match.symbols[0].url}`;
173+
url = `${searchResult.url}#${match.symbols[0].url}`;
174174
} else {
175175
multiResult = true;
176176
}
@@ -246,7 +246,7 @@ function MultiResultPeek({ searchResult }: { searchResult: { url: string; match:
246246
title={s.name}
247247
subtitle={s.containerName}
248248
accessoryTitle={s.kind.toLowerCase()}
249-
actions={<ActionPanel>{resultActions(`${searchResult.url}${s.url}`)}</ActionPanel>}
249+
actions={<ActionPanel>{resultActions(`${searchResult.url}#${s.url}`)}</ActionPanel>}
250250
/>
251251
))}
252252
</List.Section>

‎src/sourcegraph/stream-search/index.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export async function performSearch(
8282

8383
handlers.onResults(
8484
event.data.map((match): SearchResult => {
85-
const url = `${src.instance}${getMatchUrl(match)}`;
85+
const matchURL = `${src.instance}${getMatchUrl(match)}`;
86+
// Do some pre-processing of results, since some of the API outputs are a bit
87+
// confusing, to make it easier later on.
8688
switch (match.type) {
8789
case "commit":
8890
// Commit stuff comes already markdown-formatted?? so strip formatting
@@ -95,8 +97,16 @@ export async function performSearch(
9597
match.lineMatches.forEach((l) => {
9698
l.lineNumber += 1;
9799
});
100+
break;
101+
case "symbol":
102+
match.symbols.forEach((s) => {
103+
// Trim out the path that we already have in matchURL so that we can just
104+
// append it, similar to other match types where we append the line number
105+
// of the match.
106+
s.url = s.url.split("#").pop() || "";
107+
});
98108
}
99-
return { url, match };
109+
return { url: matchURL, match };
100110
})
101111
);
102112
});

0 commit comments

Comments
 (0)