Skip to content

Code navigation #315

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 49 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
fa86370
Initial POC
brendan-kellam May 16, 2025
19b59c4
Add cursor style rule
brendan-kellam May 16, 2025
012823c
wip: resolve symbol definition in pop-up box
brendan-kellam May 16, 2025
ed056ab
further wip
brendan-kellam May 16, 2025
8536185
wip
brendan-kellam May 17, 2025
d82cdb5
wip: started work on bottom panel
brendan-kellam May 20, 2025
30f1e6b
wip: move find references to server action
brendan-kellam May 20, 2025
eb2793d
wip
brendan-kellam May 20, 2025
64ca374
wip on fast readonly syntax highlighting using code mirror
brendan-kellam May 21, 2025
f2158b1
refactor things around
brendan-kellam May 21, 2025
f08f38e
Further wip: discovered that typical HighlightStyle.define highlighte…
brendan-kellam May 22, 2025
ed7f80e
wip: Add line number suppoert to the readonly code block
brendan-kellam May 22, 2025
78d9e6e
further wip: refactored how the bottom panel is rendered s.t., we don…
brendan-kellam May 23, 2025
7e6a0e5
perf: memoize highlight ranges to prevent unecessary re-renders
brendan-kellam May 23, 2025
41d2aa9
chore: move search results list to use readonly ediotr
brendan-kellam May 23, 2025
83b8964
rename readOnlyCodeBlock to lightweightCodeHighlighter
brendan-kellam May 23, 2025
410dfc1
improve syntax highlighting
brendan-kellam May 23, 2025
3529fb0
nits with keyboard shortcuts
brendan-kellam May 23, 2025
52a6bca
move match count aggregation into API layer
brendan-kellam May 24, 2025
02ce63c
wip on adding definitions tab to bottom panel
brendan-kellam May 24, 2025
12c50d4
Add eslint rule for tanstack query
brendan-kellam May 25, 2025
b9127e2
Improve how we communicate multiple symbol definitions
brendan-kellam May 25, 2025
98430db
Add support for revisions
brendan-kellam May 25, 2025
a02ad6c
chore: move stylized resize handle into shared component
brendan-kellam May 25, 2025
e1f4cf8
chore: refactor code nav UI into ee
brendan-kellam May 26, 2025
fb11a44
chore: made /browse the default path when clicking on a search result…
brendan-kellam May 26, 2025
5823168
add code nav to preview panel
brendan-kellam May 26, 2025
8f94f3e
small bug fixes
brendan-kellam May 26, 2025
70d3623
wip: add scroll restoration to search results panel
brendan-kellam May 27, 2025
27eb6fa
small nit improvements
brendan-kellam May 27, 2025
c77c58d
subtle changes to highlighting style
brendan-kellam May 27, 2025
68a657a
Use word boundaries for references
brendan-kellam May 27, 2025
6e2eb7a
make bottom panel larger
msukkari May 27, 2025
cbbcdbe
fix visual artifact issues with filter panel
brendan-kellam May 27, 2025
2a350cd
bidirectional filtering
brendan-kellam May 28, 2025
ec9ee65
debug code
brendan-kellam May 28, 2025
c5e4efd
Improve search heuristic by filtering by language
brendan-kellam May 28, 2025
239b774
Improved collapsed preview panel style
brendan-kellam May 28, 2025
ed814e5
add node types for a bunch of langs
msukkari May 28, 2025
30f20fa
nit: add tooltip to focus search bar shortcut hint
brendan-kellam May 28, 2025
6d3a059
Add cmd+click to open preview panel
brendan-kellam May 28, 2025
2399350
feedback
brendan-kellam May 28, 2025
9b90ca7
changelog
brendan-kellam May 28, 2025
ff0e4a3
posthog events
brendan-kellam May 28, 2025
acf75fd
wip on docs
brendan-kellam May 28, 2025
fce15e8
docs and changelog
brendan-kellam May 28, 2025
8417242
improve code nav search heuristics: search across repositories, and e…
brendan-kellam May 28, 2025
6e05378
delete unused /references route
brendan-kellam May 28, 2025
11a18be
improve search contexts news sub_header
brendan-kellam May 28, 2025
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
7 changes: 7 additions & 0 deletions .cursor/rules/style.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
description:
globs:
alwaysApply: true
---
- Always use 4 spaces for indentation
- 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.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- [Sourcebot EE] Added code navigation (find all references / go to definition). [#315](https://github.com/sourcebot-dev/sourcebot/pull/315)

### Fixed
- Improved scroll performance for large numbers of search results. [#315](https://github.com/sourcebot-dev/sourcebot/pull/315)

## [3.2.1] - 2025-05-15

### Added
Expand Down
3 changes: 2 additions & 1 deletion docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"pages": [
"docs/search/syntax-reference",
"docs/search/multi-branch-indexing",
"docs/search/search-contexts"
"docs/search/search-contexts",
"docs/search/code-navigation"
]
},
{
Expand Down
44 changes: 44 additions & 0 deletions docs/docs/search/code-navigation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Code navigation
sidebarTitle: Code navigation (EE)
---

import SearchContextSchema from '/snippets/schemas/v3/searchContext.schema.mdx'

<Note>
This feature is only available with an active Enterprise license. Please add your [license key](/self-hosting/license-key) to activate it.
</Note>

**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.


<video src="https://framerusercontent.com/assets/B9ZxrlsUeO9NJyzkKyvVV2KSU4.mp4" className="w-full aspect-video" controls></video>

## Features

| Feature | Description |
|:--------|:------------|
| **Hover popover** | Hovering over a symbol reveals the symbol's definition signature as a inline preview. |
| **Go to definition** | Clicking the "go to definition" button in the popover or clicking the symbol name navigates to the symbol's definition. |
| **Find references** | Clicking the "find all references" button in the popover lists all references in the explore panel. |
| **Explore panel** | Lists all references and definitions for the symbol selected in the popover. |

## How does it work?

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:

### Find references
Given a `symbolName`, along with information about the file the symbol is contained within (`git_revision`, and `language`), runs the following search:

```bash
\\b{symbolName}\\b rev:{git_revision} lang:{language} case:yes
```

### Find definitions
Given a `symbolName`, along with information about the file the symbol is contained within (`git_revision`, and `language`), runs the following search:

```bash
sym:\\b{symbolName}\\b rev:{git_revision} lang:{language}
```

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/).
Binary file removed docs/images/demo.mp4
Binary file not shown.
3 changes: 2 additions & 1 deletion packages/web/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"next/core-web-vitals"
"next/core-web-vitals",
"plugin:@tanstack/query/recommended"
],
"rules": {
"react-hooks/exhaustive-deps": "warn",
Expand Down
3 changes: 3 additions & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@codemirror/lang-xml": "^6.1.0",
"@codemirror/lang-yaml": "^6.1.2",
"@codemirror/language": "^6.0.0",
"@codemirror/language-data": "^6.5.1",
"@codemirror/legacy-modes": "^6.4.2",
"@codemirror/search": "^6.5.6",
"@codemirror/state": "^6.4.1",
Expand Down Expand Up @@ -81,6 +82,7 @@
"@tanstack/react-query": "^5.53.3",
"@tanstack/react-table": "^8.20.5",
"@tanstack/react-virtual": "^3.10.8",
"@uidotdev/usehooks": "^2.4.1",
"@uiw/codemirror-themes": "^4.23.6",
"@uiw/react-codemirror": "^4.23.0",
"@viz-js/lang-dot": "^1.0.4",
Expand Down Expand Up @@ -144,6 +146,7 @@
"zod-to-json-schema": "^3.24.5"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.74.7",
"@types/micromatch": "^4.0.9",
"@types/node": "^20",
"@types/nodemailer": "^6.4.17",
Expand Down
12 changes: 12 additions & 0 deletions packages/web/src/app/[domain]/browse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# File browser

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:

```sh
/browse/<repo-name>[@<optional-revision-name>]/-/(blob|tree)/<path_to_file>
```

For example, to view `packages/backend/src/env.ts` in Sourcebot, we would use the following path:
```sh
/browse/github.com/sourcebot-dev/sourcebot@HEAD/-/blob/packages/backend/src/env.ts
```
150 changes: 0 additions & 150 deletions packages/web/src/app/[domain]/browse/[...path]/codePreview.tsx

This file was deleted.

Loading