Skip to content

Search suggestions #85

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

Merged
merged 20 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
45e9f2d
wip
brendan-kellam Nov 14, 2024
4c94359
Further wip
brendan-kellam Nov 16, 2024
93dccd8
wip on data fetching repos. Plus some refactoring work
brendan-kellam Nov 18, 2024
019adc8
Further progress on expanding suggestion support to other prefixes
brendan-kellam Nov 19, 2024
f3fb0aa
First version of keyboard nav for suggestions
brendan-kellam Nov 20, 2024
fa7b2ae
Use cursor position to figure out what part of the query we should be…
brendan-kellam Nov 21, 2024
3615d79
Add 'press enter' dialog. Also fix focus issue when clicking a sugges…
brendan-kellam Nov 21, 2024
45dc38a
fix bug where highlight index can go out of bounds after suggestions …
brendan-kellam Nov 21, 2024
c8d342e
Add extension recommendation for tailwindcss + setting to make cva wo…
brendan-kellam Nov 21, 2024
78fd43f
Couple of bug fixes, a little bit of cleanup
brendan-kellam Nov 21, 2024
c732efb
Feed language list as a suggestion data source. Change behaviour of s…
brendan-kellam Nov 21, 2024
dba8026
move searchBar and searchSuggestionsBox into seperate folder
brendan-kellam Nov 21, 2024
0b8aba8
move components into components/ folder
brendan-kellam Nov 21, 2024
35d44dc
more cleanup
brendan-kellam Nov 21, 2024
af78bb7
nits
brendan-kellam Nov 22, 2024
873cf05
final nits
brendan-kellam Nov 22, 2024
61fd4cc
tests for splitQuery
brendan-kellam Nov 22, 2024
1827567
Break out completion handling into standalone function, completeSugge…
brendan-kellam Nov 22, 2024
7127c53
Add github action
brendan-kellam Nov 22, 2024
6af0657
fixes
brendan-kellam Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/test-web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test Web

on:
pull_request:
branches: ["main"]


jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: "true"
- name: Use Node.Js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Install
run: yarn install --frozen-lockfile

- name: Test
run: yarn workspace @sourcebot/web test

3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"recommendations": [
"dbaeumer.vscode-eslint"
"dbaeumer.vscode-eslint",
"bradlc.vscode-tailwindcss"
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,16 @@
{
"pattern": "./packages/*/"
}
],
// @see : https://cva.style/docs/getting-started/installation#intellisense
"tailwindCSS.experimental.classRegex": [
[
"cva\\(([^)]*)\\)",
"[\"'`]([^\"'`]*).*?[\"'`]"
],
[
"cx\\(([^)]*)\\)",
"(?:'|\"|`)([^']*)(?:'|\"|`)"
]
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"scripts": {
"build": "yarn workspaces run build",
"test": "yarn workspace @sourcebot/backend test",
"test": "yarn workspaces run test",
"dev": "npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn workspace @sourcebot/backend dev:watch",
Expand Down
8 changes: 6 additions & 2 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"test": "vitest"
},
"dependencies": {
"@codemirror/commands": "^6.6.0",
Expand Down Expand Up @@ -77,9 +78,12 @@
"eslint-config-next": "14.2.6",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.2",
"jsdom": "^25.0.1",
"npm-run-all": "^4.1.5",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
"typescript": "^5",
"vite-tsconfig-paths": "^5.1.3",
"vitest": "^2.1.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { GitHubLogoIcon, DiscordLogoIcon } from "@radix-ui/react-icons";
import { SettingsDropdown } from "./settingsDropdown";
import { Separator } from "@/components/ui/separator";
import Image from "next/image";
import logoDark from "../../public/sb_logo_dark_small.png";
import logoLight from "../../public/sb_logo_light_small.png";
import logoDark from "../../../public/sb_logo_dark_small.png";
import logoLight from "../../../public/sb_logo_light_small.png";
import { useRouter } from "next/navigation";

const SOURCEBOT_DISCORD_URL = "https://discord.gg/6Fhp27x7Pb";
Expand Down
224 changes: 224 additions & 0 deletions packages/web/src/app/components/searchBar/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
import { Suggestion, SuggestionMode } from "./searchSuggestionsBox";

/**
* List of search prefixes that can be used while the
* `refine` suggestion mode is active.
*/
enum SearchPrefix {
repo = "repo:",
r = "r:",
lang = "lang:",
file = "file:",
rev = "rev:",
revision = "revision:",
b = "b:",
branch = "branch:",
sym = "sym:",
content = "content:",
archived = "archived:",
case = "case:",
fork = "fork:",
public = "public:"
}

const negate = (prefix: SearchPrefix) => {
return `-${prefix}`;
}

type SuggestionModeMapping = {
suggestionMode: SuggestionMode,
prefixes: string[],
}

/**
* Maps search prefixes to a suggestion mode. When a query starts
* with a prefix, the corresponding suggestion mode is enabled.
* @see [searchSuggestionsBox.tsx](./searchSuggestionsBox.tsx)
*/
export const suggestionModeMappings: SuggestionModeMapping[] = [
{
suggestionMode: "repo",
prefixes: [
SearchPrefix.repo, negate(SearchPrefix.repo),
SearchPrefix.r, negate(SearchPrefix.r),
]
},
{
suggestionMode: "language",
prefixes: [
SearchPrefix.lang, negate(SearchPrefix.lang),
]
},
{
suggestionMode: "file",
prefixes: [
SearchPrefix.file, negate(SearchPrefix.file),
]
},
{
suggestionMode: "content",
prefixes: [
SearchPrefix.content, negate(SearchPrefix.content),
]
},
{
suggestionMode: "revision",
prefixes: [
SearchPrefix.rev, negate(SearchPrefix.rev),
SearchPrefix.revision, negate(SearchPrefix.revision),
SearchPrefix.branch, negate(SearchPrefix.branch),
SearchPrefix.b, negate(SearchPrefix.b),
]
},
{
suggestionMode: "symbol",
prefixes: [
SearchPrefix.sym, negate(SearchPrefix.sym),
]
},
{
suggestionMode: "archived",
prefixes: [
SearchPrefix.archived
]
},
{
suggestionMode: "case",
prefixes: [
SearchPrefix.case
]
},
{
suggestionMode: "fork",
prefixes: [
SearchPrefix.fork
]
},
{
suggestionMode: "public",
prefixes: [
SearchPrefix.public
]
}
];

export const refineModeSuggestions: Suggestion[] = [
{
value: SearchPrefix.repo,
description: "Include only results from the given repository.",
spotlight: true,
},
{
value: negate(SearchPrefix.repo),
description: "Exclude results from the given repository."
},
{
value: SearchPrefix.lang,
description: "Include only results from the given language.",
spotlight: true,
},
{
value: negate(SearchPrefix.lang),
description: "Exclude results from the given language."
},
{
value: SearchPrefix.file,
description: "Include only results from filepaths matching the given search pattern.",
spotlight: true,
},
{
value: negate(SearchPrefix.file),
description: "Exclude results from file paths matching the given search pattern."
},
{
value: SearchPrefix.rev,
description: "Search a given branch or tag instead of the default branch.",
spotlight: true,
},
{
value: negate(SearchPrefix.rev),
description: "Exclude results from the given branch or tag."
},
{
value: SearchPrefix.sym,
description: "Include only symbols matching the given search pattern.",
spotlight: true,
},
{
value: negate(SearchPrefix.sym),
description: "Exclude results from symbols matching the given search pattern."
},
{
value: SearchPrefix.content,
description: "Include only results from files if their content matches the given search pattern."
},
{
value: negate(SearchPrefix.content),
description: "Exclude results from files if their content matches the given search pattern."
},
{
value: SearchPrefix.archived,
description: "Include results from archived repositories.",
},
{
value: SearchPrefix.case,
description: "Control case-sensitivity of search patterns."
},
{
value: SearchPrefix.fork,
description: "Include only results from forked repositories."
},
{
value: SearchPrefix.public,
description: "Filter on repository visibility."
},
];

export const publicModeSuggestions: Suggestion[] = [
{
value: "yes",
description: "Only include results from public repositories."
},
{
value: "no",
description: "Only include results from private repositories."
},
];

export const forkModeSuggestions: Suggestion[] = [
{
value: "yes",
description: "Only include results from forked repositories."
},
{
value: "no",
description: "Only include results from non-forked repositories."
},
];

export const caseModeSuggestions: Suggestion[] = [
{
value: "auto",
description: "Search patterns are case-insensitive if all characters are lowercase, and case sensitive otherwise (default)."
},
{
value: "yes",
description: "Case sensitive search."
},
{
value: "no",
description: "Case insensitive search."
},
];

export const archivedModeSuggestions: Suggestion[] = [
{
value: "yes",
description: "Only include results in archived repositories."
},
{
value: "no",
description: "Only include results in non-archived repositories."
},
];

2 changes: 2 additions & 0 deletions packages/web/src/app/components/searchBar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export { SearchBar } from "./searchBar";
Loading