Skip to content

Commit cf5ecec

Browse files
Code navigation (#315)
* Initial POC * Add cursor style rule * wip: resolve symbol definition in pop-up box * further wip * wip * wip: started work on bottom panel * wip: move find references to server action * wip * wip on fast readonly syntax highlighting using code mirror * refactor things around * Further wip: discovered that typical HighlightStyle.define highlighters cause performance problems when rendering thousands of code cells. The workaround found is to use tagHighlighter and rely on tailwind to drive theming in CSS. * wip: Add line number suppoert to the readonly code block * further wip: refactored how the bottom panel is rendered s.t., we don't need to re-render when doing a goto def * perf: memoize highlight ranges to prevent unecessary re-renders * chore: move search results list to use readonly ediotr * rename readOnlyCodeBlock to lightweightCodeHighlighter * improve syntax highlighting * nits with keyboard shortcuts * move match count aggregation into API layer * wip on adding definitions tab to bottom panel * Add eslint rule for tanstack query * Improve how we communicate multiple symbol definitions * Add support for revisions * chore: move stylized resize handle into shared component * chore: refactor code nav UI into ee * chore: made /browse the default path when clicking on a search result. More cleanup. * add code nav to preview panel * small bug fixes * wip: add scroll restoration to search results panel * small nit improvements * subtle changes to highlighting style * Use word boundaries for references * make bottom panel larger * fix visual artifact issues with filter panel * bidirectional filtering * debug code * Improve search heuristic by filtering by language * Improved collapsed preview panel style * add node types for a bunch of langs * nit: add tooltip to focus search bar shortcut hint * Add cmd+click to open preview panel * feedback * changelog * posthog events * wip on docs * docs and changelog * improve code nav search heuristics: search across repositories, and expand language filter to resolve related langs like TypeScript, JavaScript, TSX, and JSX. * delete unused /references route * improve search contexts news sub_header --------- Co-authored-by: msukkari <michael.sukkarieh@mail.mcgill.ca>
1 parent ed87595 commit cf5ecec

File tree

66 files changed

+3330
-1069
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3330
-1069
lines changed

.cursor/rules/style.mdc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
- Always use 4 spaces for indentation
7+
- Filenames should always be camelCase. Exception: if there are filenames in the same directory with a format other than camelCase, use that format to keep things consistent.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- [Sourcebot EE] Added code navigation (find all references / go to definition). [#315](https://github.com/sourcebot-dev/sourcebot/pull/315)
12+
13+
### Fixed
14+
- Improved scroll performance for large numbers of search results. [#315](https://github.com/sourcebot-dev/sourcebot/pull/315)
15+
1016
## [3.2.1] - 2025-05-15
1117

1218
### Added

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"pages": [
5151
"docs/search/syntax-reference",
5252
"docs/search/multi-branch-indexing",
53-
"docs/search/search-contexts"
53+
"docs/search/search-contexts",
54+
"docs/search/code-navigation"
5455
]
5556
},
5657
{

docs/docs/search/code-navigation.mdx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Code navigation
3+
sidebarTitle: Code navigation (EE)
4+
---
5+
6+
import SearchContextSchema from '/snippets/schemas/v3/searchContext.schema.mdx'
7+
8+
<Note>
9+
This feature is only available with an active Enterprise license. Please add your [license key](/self-hosting/license-key) to activate it.
10+
</Note>
11+
12+
**Code navigation** allows you to jump between symbol definition and references when viewing source files in Sourcebot. This feature is enabled **automatically** when a valid license key is present and works with all popular programming languages.
13+
14+
15+
<video src="https://framerusercontent.com/assets/B9ZxrlsUeO9NJyzkKyvVV2KSU4.mp4" className="w-full aspect-video" controls></video>
16+
17+
## Features
18+
19+
| Feature | Description |
20+
|:--------|:------------|
21+
| **Hover popover** | Hovering over a symbol reveals the symbol's definition signature as a inline preview. |
22+
| **Go to definition** | Clicking the "go to definition" button in the popover or clicking the symbol name navigates to the symbol's definition. |
23+
| **Find references** | Clicking the "find all references" button in the popover lists all references in the explore panel. |
24+
| **Explore panel** | Lists all references and definitions for the symbol selected in the popover. |
25+
26+
## How does it work?
27+
28+
Code navigation is **search-based**, meaning it uses the same code search engine and [query language](/docs/search/syntax-reference) to estimate a symbol's references and definitions. We refer to these estimations as "search heuristics". We have two search heuristics to enable the following operations:
29+
30+
### Find references
31+
Given a `symbolName`, along with information about the file the symbol is contained within (`git_revision`, and `language`), runs the following search:
32+
33+
```bash
34+
\\b{symbolName}\\b rev:{git_revision} lang:{language} case:yes
35+
```
36+
37+
### Find definitions
38+
Given a `symbolName`, along with information about the file the symbol is contained within (`git_revision`, and `language`), runs the following search:
39+
40+
```bash
41+
sym:\\b{symbolName}\\b rev:{git_revision} lang:{language}
42+
```
43+
44+
Note that the `sym:` prefix is used to filter the search by symbol definitions. These are created at index time by [universal ctags](https://ctags.io/).

docs/images/demo.mp4

-9.78 MB
Binary file not shown.

packages/web/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"eslint:recommended",
88
"plugin:@typescript-eslint/recommended",
99
"plugin:react/recommended",
10-
"next/core-web-vitals"
10+
"next/core-web-vitals",
11+
"plugin:@tanstack/query/recommended"
1112
],
1213
"rules": {
1314
"react-hooks/exhaustive-deps": "warn",

packages/web/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@codemirror/lang-xml": "^6.1.0",
3535
"@codemirror/lang-yaml": "^6.1.2",
3636
"@codemirror/language": "^6.0.0",
37+
"@codemirror/language-data": "^6.5.1",
3738
"@codemirror/legacy-modes": "^6.4.2",
3839
"@codemirror/search": "^6.5.6",
3940
"@codemirror/state": "^6.4.1",
@@ -81,6 +82,7 @@
8182
"@tanstack/react-query": "^5.53.3",
8283
"@tanstack/react-table": "^8.20.5",
8384
"@tanstack/react-virtual": "^3.10.8",
85+
"@uidotdev/usehooks": "^2.4.1",
8486
"@uiw/codemirror-themes": "^4.23.6",
8587
"@uiw/react-codemirror": "^4.23.0",
8688
"@viz-js/lang-dot": "^1.0.4",
@@ -144,6 +146,7 @@
144146
"zod-to-json-schema": "^3.24.5"
145147
},
146148
"devDependencies": {
149+
"@tanstack/eslint-plugin-query": "^5.74.7",
147150
"@types/micromatch": "^4.0.9",
148151
"@types/node": "^20",
149152
"@types/nodemailer": "^6.4.17",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# File browser
2+
3+
This directory contains Sourcebot's file browser implementation. URL paths are used to determine what file the user wants to view. The following template is used:
4+
5+
```sh
6+
/browse/<repo-name>[@<optional-revision-name>]/-/(blob|tree)/<path_to_file>
7+
```
8+
9+
For example, to view `packages/backend/src/env.ts` in Sourcebot, we would use the following path:
10+
```sh
11+
/browse/github.com/sourcebot-dev/sourcebot@HEAD/-/blob/packages/backend/src/env.ts
12+
```

packages/web/src/app/[domain]/browse/[...path]/codePreview.tsx

Lines changed: 0 additions & 150 deletions
This file was deleted.

0 commit comments

Comments
 (0)