Code Navigation Features
Learn and understand more about Sourcegraph's Code Navigation features and core functionality.
Using our integrations, all code navigation features are available everywhere you read code. This includes browsers and GitHub pull requests.
Popover
Popovers allow you to quickly glance at the type signature and accompanying documentation of a symbol definition without having to context switch to another source file (which may or may not be available while browsing code).
Go to definition
When you click on the Go to definition button in the popover or click on a symbol's name (in the sidebar or code view), you will be navigated directly to the definition of the symbol.
Find references
When you select Find references from the popover, a panel at the bottom of the page lists all references, definitions, and implementations found for both precise and search-based results (from search heuristics).
Dependency navigation
Dependency navigation enables Find references and Go to definition to show usages across multiple repositories, including transitive dependencies.
For example, the animation below demonstrates how to trigger Find references in the github.com/Netflix/Hystrix
repository and navigate to results in the Java standard library (JDK).
The instructions to set up dependency navigation require you to set up auto-indexing. For more information on how to set up auto-indexing, please refer to our auto-indexing documentation.
Find implementations
If precise code navigation is enabled for your repositories, you can click Find Implementations to navigate to a symbol's interface definition. If you're at the interface definition itself, clicking on Find Implementations will show all the places where the interface is being implemented, allowing you to explore how other users across repositories use it. It can also show which interfaces a struct implements.
Perform an Action
Code Search allows you to harness the power of Search and quickly find, discover, and understand code. However, the end result isn't always to view the results of a search query. Code Search empowers you to perform an action given a set of results.
When browsing code, you can perform the following actions:
Ask Cody
Cody is a free and open-core AI coding assistant that writes, fixes, and maintains your code and is available on Sourcegraph. It allows you to ask natural language questions about your code and receive intelligent suggestions and explanations.
When browsing code on Sourcegraph, you can ask Cody a question by clicking the Ask Cody button above the file you are viewing. This will open a chat interface where you can have a conversation with Cody about the code you are viewing.
Having Cody integrated directly into Sourcegraph code search makes it fast and easy to get AI-powered insights as you explore code.
Open in Editor
When viewing a file in Sourcegraph, you can open it in your editor of choice to edit the file. This allows you to seamlessly transition from browsing code in Sourcegraph to editing code in your preferred code editor.
When you click the Open in Editor button, Sourcegraph will detect which editor you have configured and open the file in a new tab in that editor. If you have not configured a default editor, Sourcegraph will prompt you to select an editor before opening the file.
You can read more about this here.
View History
The View History action allows you to see the full commit history for a file directly in Sourcegraph.
When you click this button, a sidebar will open showing every commit that touched the file, ordered chronologically from newest to oldest. For each commit, you can view the following:
- Commit message
- Author
- Date
- Commit SHA
You can click on any commit to view the full diff and see exactly what changed in that particular version of the file.
Exploring the history of a file helps you understand how it evolved over time and why certain changes were made. This additional context can be invaluable when trying to modify or debug code.
The file history integrates tightly with other Sourcegraph navigation features. You can seamlessly transition from browsing history to blaming lines or searching for references.
Blame
The Blame action shows annotation on each line of a file indicating the last commit that modified the line and who the author was.
When you click this button on a file, blame information will be displayed inline. This allows you to easily see the history of every line, without having to explore the full file history. Blame tells you:
- The commit that last modified each line
- The author who made the change
- The commit message
- The timestamp of when it was changed
Using blame makes it easy to answer questions like:
- Who wrote this line of code originally?
- When was this method added?
- What changes were made in this commit?
You can click on any commit in the blame view to explore that snapshot of the file and see the full diff.
Blame data is essential when modifying or debugging existing code in a shared codebase. It helps identify who to talk to when you have questions about particular sections of code.
Open in Code host
The Open in CodeHost button allows you to quickly view the file in its native code host. When you click this button, the file will open in a new browser tab taking you directly to that file on the code host website.
For example, if you are viewing a file from a GitHub repository in Sourcegraph, clicking Open in CodeHost will open GitHub.com
in a new tab with that file displayed.
Copy Link
The Copy Link action allows you to easily copy a permanent link to the exact line range you are viewing in Sourcegraph. When you click this button, the link is copied to your clipboard. You can then paste the link in any text field or document.
Raw download
The Raw download action allows you to download the raw file contents displayed in Sourcegraph. When viewing code, click the Raw download button to save the file to your machine.
Line Wrapping
The Line Wrap toggle allows you to wrap long lines that extend past the width of the code viewer. When enabled, any line longer than the window width will wrap to the next line, similar to text in a document. This makes it easier to read code snippets with very long lines without having to scroll horizontally.
-
When disabled (default), long lines will extend past the edge of the window, requiring horizontal scrolling to see the full line.
-
When enabled, lines will break to the next line before hitting the window edge.
Toggling line wrapping on and off helps optimize code readability depending on personal preference.
Wrapped lines are visually indicated with a faint vertical line connecting the split sections. Hovering also reveals the full continuous line.