Skip to content

Commit

Permalink
search: tweak results views
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Dec 1, 2024
1 parent cd2e046 commit 6d2e783
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- **search**: The search pattern selector is now enabled by default, allowing you to easily toggle between standard, literal, regexp, and other search patterns. This can be disabled in the extension preferences if you find the dropdown takes up too much space in the search bar.
- **search**: For search results that have associated file paths, you can now easily copy the path of the file associated with a result or open it in the browser with the new `Copy File Path` and `Open File in Browser` actions.
- **search**: The `Cmd-Enter` shortcut used for options like "Open Query in Browser" is now `Cmd-Shift-Enter` to avoid conflicts with reserved Raycast shortcuts.
- **search**: Fixed cases where a title may be missing in results, and improved handling of unknown result types.
- **search**: Fixed cases where a title may be missing in results, improved handling of unknown result types, and improved results views.
- **proxy**: Proxying requests over Unix domain socket for custom Sourcegraph instances is now supported via the new `Sourcegraph Instance: Proxy` option; note that HTTP proxies are not yet supported ([#21](https://github.com/bobheadxi/raycast-sourcegraph/pull/21))
- **notebooks**: Notebooks have been disabled on Sourcegraph.com for some time now, so the command for interacting with public notebooks on Sourcegraph.com has been removed. The "Find Search Notebooks" command for custom instances is still available for the time being.
- **internal**: The extension now exports some basic telemetry to the connected Sourcegraph instance only. If you are using a self-hosted or on-prem instance, telemetry will be managed according to the instance's telemetry settings. This can be disabled in the extension preferences.
Expand Down
55 changes: 36 additions & 19 deletions src/components/SearchCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ColorDefault, ColorEmphasis, ColorError, ColorPrivate, ColorSubdued } f
import { copyShortcut, drilldownShortcut, tertiaryActionShortcut } from "./shortcuts";
import { SearchHistory } from "../searchHistory";
import { useTelemetry } from "../hooks/telemetry";
import path from "path";

const link = new LinkBuilder("search");

Expand Down Expand Up @@ -653,11 +654,24 @@ function ResultView({

const { match } = searchResult;
const navigationTitle = `View ${match.type} result`;
let markdownTitle: string;
let markdownContent = "";
const metadata: ReactNode[] = [
<Detail.Metadata.TagList title="Match type" key={nanoid()}>
<Detail.Metadata.TagList.Item text={match.type} icon={icon} />
<Detail.Metadata.TagList.Item text={sentenceCase(match.type)} icon={icon} />
{"repoStars" in match && (
<Detail.Metadata.TagList.Item
text={`${match.repoStars}`}
icon={Icon.Star}
color={Color.Yellow}
key={nanoid()}
/>
)}
{"private" in match && (
<Detail.Metadata.TagList.Item
text={match.private ? "Private" : "Public"}
color={match.private ? ColorPrivate : ColorDefault}
/>
)}
</Detail.Metadata.TagList>,
];
if ("repository" in match) {
Expand All @@ -676,17 +690,24 @@ function ResultView({

case "content":
case "symbol":
markdownTitle = bold(match.repository);
return <MultiResultView searchResult={{ url: searchResult.url, match }} key={nanoid()} />;

// Match types that use markdown view

case "repo":
markdownTitle = bold(match.repository);
markdownContent = match.description || "";
metadata.push(
<Detail.Metadata.Label title="Visibility" text={match.private ? "Private" : "Public"} key={nanoid()} />,
);
markdownContent = `${bold(match.repository)}`;
if (match.description) {
markdownContent += ` - ${match.description}\n`;
}
if (match.topics) {
metadata.push(
<Detail.Metadata.TagList title="Topics" key={nanoid()}>
{match.topics.map((topic) => (
<Detail.Metadata.TagList.Item text={topic} color={ColorSubdued} key={nanoid()} />
))}
</Detail.Metadata.TagList>,
);
}
if (!fileContents.called) {
getFileContents({
variables: {
Expand All @@ -702,8 +723,10 @@ function ResultView({
break;

case "path":
markdownTitle = bold(match.repository);
markdownContent = `${codeBlock(match.path)}\n\n---\n\n`;
metadata.push(
<Detail.Metadata.Link title="File" text={path.basename(match.path)} key={nanoid()} target={searchResult.url} />,
);
markdownContent = `${bold(match.path)}\n\n---\n\n`;
if (!fileContents.called) {
getFileContents({
variables: {
Expand All @@ -721,11 +744,10 @@ function ResultView({
break;

case "commit": {
markdownTitle = bold(match.repository);
markdownContent = match.message;
metadata.push(
<Detail.Metadata.Label title="Author" text={match.authorName} key={nanoid()} />,
<Detail.Metadata.Label title="Commit" text={match.oid} key={nanoid()} />,
<Detail.Metadata.Link title="Commit" text={match.oid} target={searchResult.url} key={nanoid()} />,
<Detail.Metadata.Label
title="Committed"
text={DateTime.fromISO(match.authorDate).toRelative() || "Unknown"}
Expand All @@ -736,18 +758,13 @@ function ResultView({
}

default:
markdownTitle = bold(sentenceCase(match.type));
markdownContent = `Unsupported result type - full data:\n\n${codeBlock(JSON.stringify(match, null, " "))}`;
}

if ("repoStars" in match) {
metadata.push(<Detail.Metadata.Label title="Stars" text={`${match.repoStars}`} key={nanoid()} />);
markdownContent = `${bold(sentenceCase(match.type))}\n\n---\n\nUnsupported result type - full data:\n\n${codeBlock(JSON.stringify(match, null, " "))}`;
}

return (
<Detail
navigationTitle={navigationTitle}
markdown={`${markdownTitle}\n\n${markdownContent}`}
markdown={markdownContent}
actions={<ActionPanel>{resultActions(searchResult.url)}</ActionPanel>}
metadata={
<Detail.Metadata>
Expand Down
2 changes: 1 addition & 1 deletion src/markdown/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function codeBlock(str: string): string {
return `\`\`\`\n${str}\n\`\`\``;
return `\`\`\`\n\n${str}\n\`\`\``;
}

export function inlineCode(str: string): string {
Expand Down

0 comments on commit 6d2e783

Please sign in to comment.