Skip to content

Commit 49882bb

Browse files
author
Patrick Thomson
authored
Document precise and search-based code navigation strategies. (#23177)
1 parent 77f298f commit 49882bb

5 files changed

Lines changed: 41 additions & 12 deletions

File tree

78.7 KB
Loading
68.4 KB
Loading

content/repositories/working-with-files/using-files/navigating-code-on-github.md

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,34 @@ topics:
1515

1616
## About navigating code on {% data variables.product.prodname_dotcom %}
1717

18-
Code navigation uses the open source library [`tree-sitter`](https://github.com/tree-sitter/tree-sitter). The following languages are supported:
19-
- C#
20-
- CodeQL
21-
- Go
22-
- Java
23-
- JavaScript
24-
- PHP
25-
- Python
26-
- Ruby
27-
- TypeScript
18+
Code navigation helps you to read, navigate, and understand code by showing and linking definitions of a named entity corresponding to a reference to that entity, as well as references corresponding to an entity's definition.
19+
20+
![Code navigation display](/assets/images/help/repository/code-navigation-popover.png)
21+
22+
Code navigation uses the open source [`tree-sitter`](https://github.com/tree-sitter/tree-sitter) library. The following languages and navigation strategies are supported:
23+
24+
| Language | search-based code navigation | precise code navigation |
25+
|:----------:|:----------------------------:|:-----------------------:|
26+
| C# || |
27+
| CodeQL || |
28+
| Go || |
29+
| Java || |
30+
| JavaScript || |
31+
| PHP || |
32+
| Python |||
33+
| Ruby || |
34+
| TypeScript || |
35+
36+
37+
You do not need to configure anything in your repository to enable code navigation. We will automatically extract search-based and precise code navigation information for these supported languages in all repositories and you can switch between the two supported code navigation approaches if your programming language is supported by both.
38+
39+
{% data variables.product.prodname_dotcom %} has developed two code navigation approaches based on the open source [`tree-sitter`](https://github.com/tree-sitter/tree-sitter) and [`stack-graphs`](https://github.com/github/stack-graphs) library:
40+
- search-based - searches all definitions and references across a repository to find entities with a given name
41+
- precise - resolves definitions and references based on the set of classes, functions, and imported definitions at a given point in your code
42+
43+
To learn more about these approaches, see "[Precise and search-based navigation](#precise-and-search-based-navigation)."
44+
45+
Future releases will add *precise code navigation* for more languages, which is a code navigation approach that can give more accurate results.
2846

2947
## Jumping to the definition of a function or method
3048

@@ -38,11 +56,21 @@ You can find all references for a function or method within the same repository
3856

3957
![Find all references tab](/assets/images/help/repository/find-all-references-tab.png)
4058

59+
## Precise and search-based navigation
60+
61+
Certain languages supported by {% data variables.product.prodname_dotcom %} have access to *precise code navigation*, which uses an algorithm (based on the open source [`stack-graphs`](https://github.com/github/stack-graphs) library) that resolves definitions and references based on the set of classes, functions, and imported definitions that are visible at any given point in your code. Other languages use *search-based code navigation*, which searches all definitions and references across a repository to find entities with a given name. Both strategies are effective at finding results and both make sure to avoid inappropriate results such as comments, but precise code navigation can give more accurate results, especially when a repository contains multiple methods or functions with the same name.
62+
63+
If you don't see the results you expect from a precise code navigation query, you can click on the "search-based" link in the displayed popover to perform search-based navigation.
64+
65+
![Search-based code navigation link](/assets/images/help/repository/search-based-code-navigation-link.png)
66+
67+
If your precise results appear inaccurate, you can file a support request.
68+
4169
## Troubleshooting code navigation
4270

4371
If code navigation is enabled for you but you don't see links to the definitions of functions and methods:
4472
- Code navigation only works for active branches. Push to the branch and try again.
45-
- Code navigation only works for repositories with less than 100,000 files.
73+
- Code navigation only works for repositories with fewer than 100,000 files.
4674

4775
## Further reading
4876
- "[Searching code](/github/searching-for-information-on-github/searching-code)"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| Python {% ifversion fpt or ghec %}| {% octicon "check" aria-label="The check icon" %} | {% octicon "check" aria-label="The check icon" %} | {% octicon "check" aria-label="The check icon" %}<br>pip | {% octicon "check" aria-label="The check icon" %}<br>pip | {% octicon "check" aria-label="The check icon" %} | {% octicon "x" aria-label="The X icon" %} |{% elsif ghes %}| {% octicon "check" aria-label="The check icon" %} | {% octicon "check" aria-label="The check icon" %}<br>pip {% ifversion ghes > 3.2 %}| {% octicon "check" aria-label="The check icon" %}<br>pip{% endif %} | {% octicon "check" aria-label="The check icon" %} | {% octicon "x" aria-label="The X icon" %} |{% elsif ghae %}| {% octicon "check" aria-label="The check icon" %} | {% octicon "check" aria-label="The check icon" %} | {% octicon "x" aria-label="The X icon" %} |{% endif %}
1+
| Python {% ifversion fpt or ghec %}| {% octicon "check" aria-label="The check icon" %} <br>precise| {% octicon "check" aria-label="The check icon" %} | {% octicon "check" aria-label="The check icon" %}<br>pip | {% octicon "check" aria-label="The check icon" %}<br>pip | {% octicon "check" aria-label="The check icon" %} | {% octicon "x" aria-label="The X icon" %} |{% elsif ghes %}| {% octicon "check" aria-label="The check icon" %} | {% octicon "check" aria-label="The check icon" %}<br>pip {% ifversion ghes > 3.2 %}| {% octicon "check" aria-label="The check icon" %}<br>pip{% endif %} | {% octicon "check" aria-label="The check icon" %} | {% octicon "x" aria-label="The X icon" %} |{% elsif ghae %}| {% octicon "check" aria-label="The check icon" %} | {% octicon "check" aria-label="The check icon" %} | {% octicon "x" aria-label="The X icon" %} |{% endif %}

tests/meta/repository-references.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const PUBLIC_REPOS = new Set([
5353
'hello-world.git',
5454
'insights-releases',
5555
'help-docs-archived-enterprise-versions',
56+
'stack-graphs',
5657
])
5758

5859
const ALLOW_DOCS_PATHS = [

0 commit comments

Comments
 (0)