This page documents the navigation services provided by the TypeScript language service: the navigation bar (file structure outline), outlining spans (code folding), navigate-to (cross-file symbol search), and core go-to-definition and implementation features. These services enable IDEs to provide structured views and rapid movement through the codebase.
The navigation bar gives editors a hierarchical outline of the symbols defined in a source file. It is surfaced through two entry points in the language service:
| Function | Return type | Description |
|---|---|---|
getNavigationBarItems | NavigationBarItem[] | Flat list suitable for a two-level primary/secondary navbar menu |
getNavigationTree | NavigationTree | Full recursive tree of symbols |
Both are implemented in src/services/navigationBar.ts
NavigationBarNodeBefore converting to the public NavigationBarItem or NavigationTree types, the service builds an intermediate tree of NavigationBarNode objects.
The additionalNodes field holds extra source nodes that were merged into a single logical entry (e.g., an interface declared in multiple blocks, or an ES5 class where the constructor and prototype assignments are separate).
Sources: src/services/navigationBar.ts161-168
The service builds the tree by visiting AST nodes recursively. A module-level stack (parentsStack) tracks the current parent node to avoid deep recursion overhead.
Navigation Bar Build Pipeline
Sources: src/services/navigationBar.ts171-229 src/services/navigationBar.ts143-154
JavaScript code using the ES5 prototype pattern produces separate AST nodes. The navigation bar merges these into a single class-like entry using addTrackedEs5Class and tryMergeEs5Class.
Sources: src/services/navigationBar.ts246-253 src/services/navigationBar.ts617-724
The outlining service computes collapsible regions (code folding). It is exposed via collectElements in src/services/outliningElementsCollector.ts
| Field | Type | Description |
|---|---|---|
textSpan | TextSpan | The collapsible range |
hintSpan | TextSpan | The range shown when collapsed (e.g., the header line) |
bannerText | string | Text shown in collapsed state (default: "...") |
kind | OutliningSpanKind | Code, Comment, Imports, or Region |
Sources: src/services/outliningElementsCollector.ts59-65
The collector runs two independent passes: one for node-based structures (functions, blocks) and one for comment-based regions (#region).
Sources: src/services/outliningElementsCollector.ts59-136 src/services/outliningElementsCollector.ts138-162
Navigate-To allows cross-file searching for named declarations. It uses a fuzzy matching engine implemented in src/services/patternMatcher.ts
The service iterates through all files in the Program, retrieving named declarations via sourceFile.getNamedDeclarations().
Navigate-To Search Flow
Sources: src/services/navigateTo.ts42-66 src/services/navigateTo.ts110-128
The matcher splits the search string into segments (by .) and chunks (by word boundaries). It supports exact, prefix, substring, and camelCase matches.
Sources: src/services/patternMatcher.ts17-22 src/services/patternMatcher.ts72-141
These features resolve the location of a symbol's declaration or its concrete implementations.
Implemented in src/services/goToDefinition.ts this feature resolves the symbol at a specific position and returns its declaration sites.
getTouchingPropertyName or getTouchingToken finds the node at the cursor src/services/services.ts125-126TypeChecker is used to find the Symbol associated with the node src/compiler/checker.ts125declarations to DefinitionInfo objects, including support for finding definitions in .d.ts files or original source via source maps src/services/services.ts53-54Exposed via getImplementationAtPosition, this feature specifically looks for overrides of class members or implementations of interface members.
TypeChecker to navigate the inheritance hierarchy (getAnyBaseTypes) src/compiler/checker.ts34Sources: src/services/goToDefinition.ts src/services/services.ts127 src/compiler/checker.ts125
The LanguageService interface in src/services/services.ts coordinates these features.
| Method | Implementation File |
|---|---|
getNavigationBarItems | src/services/navigationBar.ts |
getNavigationTree | src/services/navigationBar.ts |
getOutliningSpans | src/services/outliningElementsCollector.ts |
getNavigateToItems | src/services/navigateTo.ts |
getDefinitionAtPosition | src/services/goToDefinition.ts |
getImplementationAtPosition | src/services/services.ts |
Sources: src/services/services.ts212-280
Refresh this wiki