Skip to content

Commit 40083cf

Browse files
authored
Merge branch 'main' into graphql-schema-update
2 parents 5afc109 + 49882bb commit 40083cf

8 files changed

Lines changed: 85 additions & 13 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 %}

middleware/redirects/external.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const externalSites = readJsonFile('./lib/redirects/external-sites.json')
44
// blanket redirects to external websites
55
export default function externalRedirects(req, res, next) {
66
if (req.path in externalSites) {
7+
// Undo the cookie setting that CSRF sets.
8+
res.removeHeader('set-cookie')
79
return res.redirect(301, externalSites[req.path])
810
} else {
911
return next()

middleware/redirects/handle-redirects.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ export default function handleRedirects(req, res, next) {
2323
language = req.context.userLanguage
2424
}
2525

26+
// Undo the cookie setting that CSRF sets.
27+
res.removeHeader('set-cookie')
28+
2629
noCacheControl(res)
30+
2731
return res.redirect(302, `/${language}`)
2832
}
2933

@@ -67,6 +71,9 @@ export default function handleRedirects(req, res, next) {
6771
return next()
6872
}
6973

74+
// Undo the cookie setting that CSRF sets.
75+
res.removeHeader('set-cookie')
76+
7077
// do the redirect if the from-URL already had a language in it
7178
if (pathLanguagePrefixed(req.path)) {
7279
cacheControl(res)

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 = [

tests/rendering/server.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import CspParse from 'csp-parse'
77
import { productMap } from '../../lib/all-products.js'
88
import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js'
99
import { jest } from '@jest/globals'
10+
import { languageKeys } from '../../lib/languages.js'
1011

1112
const AZURE_STORAGE_URL = 'githubdocs.azureedge.net'
1213
const activeProducts = Object.values(productMap).filter(
@@ -610,6 +611,7 @@ describe('server', () => {
610611
test('redirects old articles to their English URL', async () => {
611612
const res = await get('/articles/deleting-a-team')
612613
expect(res.statusCode).toBe(302)
614+
expect(res.headers['set-cookie']).toBeUndefined()
613615
// no cache control because a language prefix had to be injected
614616
expect(res.headers['cache-control']).toBeUndefined()
615617
})
@@ -621,17 +623,48 @@ describe('server', () => {
621623
)
622624
})
623625

624-
test('redirects / to /en', async () => {
626+
test('redirects / to /en when no language preference is specified', async () => {
625627
const res = await get('/')
626628
expect(res.statusCode).toBe(302)
627629
expect(res.headers.location).toBe('/en')
628630
expect(res.headers['cache-control']).toBe('private, no-store')
631+
expect(res.headers['set-cookie']).toBeUndefined()
632+
})
633+
634+
test('redirects / to appropriate language preference if specified', async () => {
635+
await Promise.all(
636+
languageKeys.map(async (languageKey) => {
637+
const res = await get('/', {
638+
headers: {
639+
'accept-language': `${languageKey}`,
640+
},
641+
})
642+
expect(res.statusCode).toBe(302)
643+
expect(res.headers.location).toBe(`/${languageKey}`)
644+
expect(res.headers['cache-control']).toBe('private, no-store')
645+
expect(res.headers['set-cookie']).toBeUndefined()
646+
})
647+
)
648+
})
649+
650+
test('redirects / to /en when unsupported language preference is specified', async () => {
651+
const res = await get('/', {
652+
headers: {
653+
// Tagalog: https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?iso_639_1=tl
654+
'accept-language': 'tl',
655+
},
656+
})
657+
expect(res.statusCode).toBe(302)
658+
expect(res.headers.location).toBe('/en')
659+
expect(res.headers['cache-control']).toBe('private, no-store')
660+
expect(res.headers['set-cookie']).toBeUndefined()
629661
})
630662

631663
test('adds English prefix to old article URLs', async () => {
632664
const res = await get('/articles/deleting-a-team')
633665
expect(res.statusCode).toBe(302)
634666
expect(res.headers.location.startsWith('/en/')).toBe(true)
667+
expect(res.headers['set-cookie']).toBeUndefined()
635668
expect(res.headers['cache-control']).toBeUndefined()
636669
})
637670

@@ -646,6 +679,7 @@ describe('server', () => {
646679
const res = await get('/desktop-classic')
647680
expect(res.statusCode).toBe(301)
648681
expect(res.headers.location).toBe('https://desktop.github.com')
682+
expect(res.headers['set-cookie']).toBeUndefined()
649683
expect(res.headers['cache-control']).toBeUndefined()
650684
})
651685

0 commit comments

Comments
 (0)