Skip to content

Commit

Permalink
Sourcegraph: Smoother search and bug fixes (#15862)
Browse files Browse the repository at this point in the history
* Publish raycast-sourcegraph@ec23429

Version: bobheadxi/raycast-sourcegraph@ec23429

* Publish raycast-sourcegraph@fcbab75

Version: bobheadxi/raycast-sourcegraph@fcbab75

* Publish raycast-sourcegraph@6f1b19b

Version: bobheadxi/raycast-sourcegraph@6f1b19b

* Publish raycast-sourcegraph@ba48cdc

Version: bobheadxi/raycast-sourcegraph@ba48cdc

* Update package.json

* Update CHANGELOG.md and optimise images

---------

Co-authored-by: Per Nielsen Tikær <[email protected]>
Co-authored-by: raycastbot <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 36613d0 commit 5927e56
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 126 deletions.
8 changes: 8 additions & 0 deletions extensions/sourcegraph/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [Smoother search and bug fixes] - 2024-12-14

- **search**: Opening a query in browser now correctly preserves the selected pattern type from the pattern type selector.
- **search**: Typing during ongoing searches should feel less jittery, as the suggestion view is now less likely to show up randomly.
- **search**: Loading state looks better with a better no-results view that shows progress and options to continue the search in browser or cancel it entirely.
- **dotcom**: When using 'Public code on Sourcegraph.com' commands, if an access token is not provided a random anonymous user ID is now generated and used with API requests and telemetry for diagnostics. Telemetry can be disabled in the extension preferences.
- **doc**: 'Sourcegraph.com' commands are now called 'Public code on Sourcegraph.com', and 'Sourcegraph instance' commands are now just referred to as 'Sourcegraph' commands.

## [Search improvements, pattern selector, and proxy support](https://github.com/raycast/extensions/pull/15625) - 2024-11-30

- **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.
Expand Down
21 changes: 17 additions & 4 deletions extensions/sourcegraph/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,28 @@ The current screenshot samples are:

The latest release of this extension is published to [`extensions/sourcegraph` in `raycast/extensions`](https://github.com/raycast/extensions/tree/main/extensions/sourcegraph).

To make a release, set up a clone of the [Raycast extensions repository](https://github.com/raycast/extensions) and create a new branch.
To make a release, set up a clone of the [Raycast extensions repository](https://github.com/raycast/extensions) and create a new branch:

```sh
export RAYCAST_EXTENSIONS_DIR="../../raycast/extensions"
mkdir -p $RAYCAST_EXTENSIONS_DIR
cd $RAYCAST_EXTENSIONS_DIR

git clone --no-checkout --filter=blob:none $FORK .
git sparse-checkout init --cone
git sparse-checkout set extensions/sourcegraph
git checkout main

cd - # back to raycast-sourcegraph
```

Then, in your clone of the `raycast-sourcegraph` repository:

```sh
# check that a build works successfully
npm run build

export RAYCAST_EXTENSIONS_DIR="/path/to/extensions" # defaults to '../../raycast/extensions'
npm run raycast-publish # copy repo into publish directory
# copy repo into publish directory
npm run raycast-publish
```

Then open a pull request upstream and follow the steps in the pull request template.
14 changes: 7 additions & 7 deletions extensions/sourcegraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</h1>

<p align="center">
Search code, browse notebooks, and manage batch changes on <a href="https://about.sourcegraph.com">Sourcegraph</a> with <a href="https://www.raycast.com">Raycast</a>.
Search code, manage batch changes, and browse notebooks on <a href="https://about.sourcegraph.com">Sourcegraph</a> with <a href="https://www.raycast.com">Raycast</a>.
</p>

<p align="center">
Expand Down Expand Up @@ -50,11 +50,11 @@ To configure your own [search contexts](#search-contexts), create search noteboo
Once you have an account, you can create an access token under the "Access tokens" tab in your user settings on [Sourcegraph.com](https://sourcegraph.com/user/settings).
Copy that access token to the "Sourcegraph.com: Access token" field in the Sourcegraph Raycast extension preferences to authenticate your search queries.

To search your private code, please reach out [get a demo of the single-tenant solution](https://about.sourcegraph.com/demo) or [try out a self-hosted installation of Sourcegraph](https://about.sourcegraph.com/get-started/self-hosted).
To search your private code, please reach out [get a demo of the single-tenant solution](https://sourcegraph.com/contact/request-info) or [try out a self-hosted installation of Sourcegraph](https://about.sourcegraph.com/get-started/self-hosted).

### Sourcegraph Instance

To start searching code on a custom Sourcegraph instance (e.g. [self-hosted](https://docs.sourcegraph.com/admin/install) or [managed](https://docs.sourcegraph.com/admin/deploy/managed)), you can set up access through the 'Sourcegraph Instance' variants of this extensions's commands by configuring the "Sourcegraph Instance: Instance URL" and "Sourcegraph Instance: Access token" fields in the Sourcegraph Raycast extension preferences.
To start searching code on a custom Sourcegraph instance (e.g. [self-hosted](https://sourcegraph.com/docs/admin/deploy) or [managed](https://sourcegraph.com/docs/cloud)), you can set up access through the 'Sourcegraph Instance' variants of this extensions's commands by configuring the "Sourcegraph Instance: Instance URL" and "Sourcegraph Instance: Access token" fields in the Sourcegraph Raycast extension preferences.
You can create an access token under the "Access tokens" tab in your user settings on your Sourcegraph instance.

<br />
Expand All @@ -69,7 +69,7 @@ Get results as you type on [code search](https://about.sourcegraph.com/code-sear

#### Search contexts

[Search contexts](https://docs.sourcegraph.com/code_search/explanations/features#search-contexts) allow you to narrow down your search to code you care about.
[Search contexts](https://sourcegraph.com/docs/code-search/features#search-contexts) allow you to narrow down your search to code you care about.
To get started, you can try the [public Sourcegraph.com search contexts](https://sourcegraph.com/contexts), or configure your own in your Sourcegraph.com account or Sourcegraph instance's "Contexts" page!

The Sourcegraph Raycast extension allows you to set a default context for your searches in the "Search Code" command preferences.
Expand All @@ -87,16 +87,16 @@ Recent searches are persisted [locally through a native Raycast API](https://dev
Browse, view, publish, and merge changesets for [batch changes](https://about.sourcegraph.com/batch-changes) straight from Raycast.
Batch changes automate large-scale code changes to keep your code up to date, fix critical security issues, and pay down tech debt across all of your repositories.

Batch changes is currently only supported on [Sourcegraph Instance](#sourcegraph-self-hosted).
Batch changes are currently only supported on [Sourcegraph Instance](#sourcegraph-instance).

![batch changes](metadata/3-batch-change-manage.png)

### Find Search Notebooks

Browse and preview [search notebooks](https://docs.sourcegraph.com/notebooks) straight from Raycast.
Browse and preview [search notebooks](https://sourcegraph.com/docs/notebooks) straight from Raycast.
Notebooks enable powerful live – and persistent – documentation, shareable with your organization or the world.

To get started, you can try the [public Sourcegraph.com notebooks](https://sourcegraph.com/notebooks?tab=explore), or configure your own from your Sourcegraph.com account or Sourcegraph instance!
Notebooks are currently only supported on [Sourcegraph Instance](#sourcegraph-instance).

![notebooks](metadata/4-notebook-view.png)

Expand Down
33 changes: 32 additions & 1 deletion extensions/sourcegraph/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 23 additions & 21 deletions extensions/sourcegraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@
"preferences": [
{
"name": "cloudToken",
"title": "Sourcegraph.com: Access token",
"description": "Available under 'Profile' -> 'Access token' on Sourcegraph.com",
"title": "Public code on Sourcegraph.com: Access token",
"description": "Configures 'Sourcegraph.com' commands - available under 'Profile' -> 'Access token' on Sourcegraph.com",
"required": false,
"type": "password"
},
{
"name": "customInstance",
"title": "Sourcegraph Instance: Instance URL",
"description": "Required to use use 'Sourcegraph Instance' commands - URL of the Sourcegraph instance you want to connect to.",
"title": "Sourcegraph: URL",
"description": "Required to use 'Sourcegraph' commands - Sourcegraph URL you want to connect to.",
"placeholder": "https://sourcegraph.my-company.com",
"required": false,
"type": "textfield"
},
{
"name": "customInstanceToken",
"title": "Sourcegraph Instance: Access token",
"description": "Required to use 'Sourcegraph Instance' commands - available under 'Profile' -> 'Access token' on your Sourcegraph instance.",
"title": "Sourcegraph: Access token",
"description": "Required to use 'Sourcegraph' commands - available under 'Profile' -> 'Access token' in Sourcegraph.",
"required": false,
"type": "password"
},
{
"name": "customInstanceProxy",
"title": "Sourcegraph Instance: Proxy",
"description": "Optional proxy to use when connecting to a custom Sourcegraph instance - presently, only Unix domain sockets are supported.",
"title": "Sourcegraph: Proxy",
"description": "Optional proxy to use when using a custom Sourcegraph connection - presently, only Unix domain sockets are supported.",
"required": false,
"type": "textfield"
},
Expand All @@ -70,8 +70,8 @@
"commands": [
{
"name": "searchDotCom",
"title": "Search Code",
"subtitle": "Sourcegraph.com",
"title": "Search Public Code",
"subtitle": "Sourcegraph",
"description": "Search public repositories on Sourcegraph.com",
"mode": "view",
"keywords": [
Expand All @@ -96,8 +96,8 @@
"name": "searchInstance",
"icon": "logo-bw.png",
"title": "Search Code",
"subtitle": "Sourcegraph Instance",
"description": "Search code on a Sourcegraph instance.",
"subtitle": "Sourcegraph",
"description": "Search code on Sourcegraph.",
"mode": "view",
"keywords": [
"sourcegraph",
Expand All @@ -119,8 +119,8 @@
},
{
"name": "searchHistoryDotCom",
"title": "Code Search History",
"subtitle": "Sourcegraph.com",
"title": "Search Public Code History",
"subtitle": "Sourcegraph",
"description": "Browse and launch recent code searches.",
"mode": "view",
"keywords": [
Expand All @@ -136,7 +136,7 @@
"name": "searchHistoryInstance",
"icon": "logo-bw.png",
"title": "Code Search History",
"subtitle": "Sourcegraph Instance",
"subtitle": "Sourcegraph",
"description": "Browse and launch recent code searches.",
"mode": "view",
"keywords": [
Expand All @@ -152,8 +152,8 @@
"name": "findNotebooksInstance",
"icon": "logo-bw.png",
"title": "Find Search Notebooks",
"subtitle": "Sourcegraph Instance",
"description": "Browse search notebooks on a Sourcegraph instance.",
"subtitle": "Sourcegraph",
"description": "Browse search notebooks in Sourcegraph.",
"mode": "view",
"keywords": [
"sourcegraph",
Expand All @@ -167,8 +167,8 @@
"name": "manageBatchChangesInstance",
"icon": "logo-bw.png",
"title": "Manage Batch Changes",
"subtitle": "Sourcegraph Instance",
"description": "Manage batch changes on a Sourcegraph instance.",
"subtitle": "Sourcegraph",
"description": "Manage batch changes in Sourcegraph.",
"mode": "view",
"keywords": [
"sourcegraph",
Expand All @@ -184,12 +184,14 @@
"@raycast/api": "^1.86.1",
"@raycast/utils": "^1.18.1",
"@sourcegraph/telemetry": "^0.18.0",
"@types/uuid": "^10.0.0",
"cross-fetch": "^4.0.0",
"eventsource": "^2.0.2",
"graphql": "^16.9.0",
"luxon": "^3.5.0",
"nanoid": "^5.0.9",
"node-fetch": "^3.3.2"
"node-fetch": "^3.3.2",
"uuid": "^11.0.3"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.3",
Expand Down Expand Up @@ -219,4 +221,4 @@
"gql": "graphql-codegen --config graphql-codegen.yml && npm run fmt",
"postinstall": "patch-package"
}
}
}
30 changes: 26 additions & 4 deletions extensions/sourcegraph/src/components/DotComCommand.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LaunchProps } from "@raycast/api";
import { useEffect } from "react";
import { Detail, LaunchProps } from "@raycast/api";
import { useEffect, useState } from "react";

import checkAuthEffect from "../hooks/checkAuthEffect";
import { Sourcegraph, sourcegraphDotCom } from "../sourcegraph";
Expand All @@ -14,9 +14,31 @@ export default function DotComCommand({
Command: React.FunctionComponent<{ src: Sourcegraph; props?: LaunchProps }>;
props?: LaunchProps;
}) {
const src = sourcegraphDotCom();
const [src, setSrc] = useState<Sourcegraph>();
useEffect(() => {
async function loadSrc() {
setSrc(await sourcegraphDotCom());
}
loadSrc();
}, []);

useEffect(checkAuthEffect(src), []);
if (!src) {
return <Detail isLoading={true} />;
}
return <CheckAuthCommand src={src} props={props} Command={Command} />;
}

// Inner wrapper for the command to deal with using checkAuthEffect while src
// requires async to initialize.
function CheckAuthCommand({
src,
Command,
props,
}: {
src: Sourcegraph;
props?: LaunchProps;
Command: React.FunctionComponent<{ src: Sourcegraph; props?: LaunchProps }>;
}) {
useEffect(checkAuthEffect(src), []);
return <Command src={src} props={props} />;
}
18 changes: 8 additions & 10 deletions extensions/sourcegraph/src/components/FindNotebooksCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function FindNotebooksCommand({ src }: { src: Sourcegraph }) {
selectedItemId={length > 0 ? "first-result" : undefined}
throttle
>
{!loading && !searchText ? (
{!loading && !searchText && (
<List.Section title={"Suggestions"}>
<List.Item
title="Create a search notebook"
Expand All @@ -63,17 +63,15 @@ export default function FindNotebooksCommand({ src }: { src: Sourcegraph }) {
}
/>
</List.Section>
) : (
<Fragment />
)}

{notebooks && (
<List.Section title={searchText ? "Notebooks" : "Recent notebooks"}>
{notebooks.map((n, i) => (
<NotebookResultItem id={i === 0 ? "first-result" : undefined} key={nanoid()} notebook={n} src={src} />
))}
</List.Section>
)}
{loading && length === 0 && <List.EmptyView title={"Loading..."} />}

<List.Section title={searchText ? "Notebooks" : "Recent notebooks"}>
{notebooks?.map((n, i) => (
<NotebookResultItem id={i === 0 ? "first-result" : undefined} key={nanoid()} notebook={n} src={src} />
))}
</List.Section>
</List>
);
}
Expand Down
Loading

0 comments on commit 5927e56

Please sign in to comment.