Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search: fix symbol match URLs #7

Merged
merged 2 commits into from Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- **search**: Fix URL opened by `symbol` match results. ([#7](https://github.com/bobheadxi/raycast-sourcegraph/pull/7))

## [Feb 7, 2022](https://github.com/raycast/extensions/pull/833)

- **search**: Fix off-by-one issue when opening `content` match results.
Expand Down
4 changes: 2 additions & 2 deletions src/components/search.tsx
Expand Up @@ -170,7 +170,7 @@ function SearchResultItem({
title = match.symbols.map((s) => s.name).join(", ");
subtitle = match.path;
if (match.symbols.length === 1) {
url = `${searchResult.url}${match.symbols[0].url}`;
url = `${searchResult.url}#${match.symbols[0].url}`;
} else {
multiResult = true;
}
Expand Down Expand Up @@ -246,7 +246,7 @@ function MultiResultPeek({ searchResult }: { searchResult: { url: string; match:
title={s.name}
subtitle={s.containerName}
accessoryTitle={s.kind.toLowerCase()}
actions={<ActionPanel>{resultActions(`${searchResult.url}${s.url}`)}</ActionPanel>}
actions={<ActionPanel>{resultActions(`${searchResult.url}#${s.url}`)}</ActionPanel>}
/>
))}
</List.Section>
Expand Down
14 changes: 12 additions & 2 deletions src/sourcegraph/stream-search/index.ts
Expand Up @@ -82,7 +82,9 @@ export async function performSearch(

handlers.onResults(
event.data.map((match): SearchResult => {
const url = `${src.instance}${getMatchUrl(match)}`;
const matchURL = `${src.instance}${getMatchUrl(match)}`;
// Do some pre-processing of results, since some of the API outputs are a bit
// confusing, to make it easier later on.
switch (match.type) {
case "commit":
// Commit stuff comes already markdown-formatted?? so strip formatting
Expand All @@ -95,8 +97,16 @@ export async function performSearch(
match.lineMatches.forEach((l) => {
l.lineNumber += 1;
});
break;
case "symbol":
match.symbols.forEach((s) => {
// Trim out the path that we already have in matchURL so that we can just
// append it, similar to other match types where we append the line number
// of the match.
s.url = s.url.split("#").pop() || "";
});
}
return { url, match };
return { url: matchURL, match };
})
);
});
Expand Down