Repository navigation
Add missing methods to Language service api - #65815
Isabel Duan (iisaduan) wants to merge 23 commits into
Conversation
…anguageServiceApi
There was a problem hiding this comment.
🟡 Changes recommended
Completion responses lose required information: string-literal completions retain a keyword kind and empty documentation, completion mappings without hover mappings lose display details and documentation, and auto-import completions return no symbol even with includeSymbols enabled. Separately, span conversion rescans the entire file for every reference or formatting edit, causing quadratic work in files with many references.
6 open issues
Resolve symbols for auto-import completion entries · New Cache position maps instead of rebuilding them for every span · New Provide a bound span for case and default keyword navigation · New Include type reference directives in file references · New Populate string completion details from the matching result · New Extract completion documentation without requiring hover mapping · New
What changed in this PR
Expands the JavaScript LanguageService API with 25 methods backed by the native compiler and language service.
Changes:
- Adds navigation, references, rename, completion details, formatting, and JSX helpers.
- Exposes program access, diagnostics, emit output, and line-offset conversion.
- Updates protocol generation, synchronous clients, and API tests.
| File | Description |
|---|---|
| tsc/testdata/apiDiff.txt | Updates missing-method inventory. |
| tsc/internal/testutil/contentmappertest/mapper_test.go | Adds subprocess readiness handshake. |
| tsc/internal/ls/rename.go | Extracts reusable rename affixes. |
| tsc/internal/ls/lsutil/userpreferences.go | Exposes configuration merging. |
| tsc/internal/ls/lsutil/api.go | Defines editor API response types. |
| tsc/internal/ls/findallreferences.go | Adds string and comment matches. |
| tsc/internal/ls/displaypartswriter.go | Collects structured display parts. |
| tsc/internal/ls/autoinsert.go | Shares JSX closing-tag detection. |
| tsc/internal/ls/api_editor.go | Implements editor API adapters. |
| tsc/internal/fswatch/watcher_test.go | Refines watcher isolation assertions. |
| tsc/internal/compiler/program.go | Supports forced declaration emission. |
| tsc/internal/compiler/emitter.go | Propagates declaration-emission flags. |
| tsc/internal/api/session.go | Routes requests and handles emit/offset operations. |
| tsc/internal/api/session_editor.go | Adds editor request handlers. |
| tsc/internal/api/proto.go | Registers methods and protocol types. |
| tsc/internal/api/proto_editor.go | Defines editor request parameters. |
| tools/scripts/tsc/generate-enums.ts | Registers organize-imports enum generation. |
| tools/gen-proto/main.go | Supports the organize-imports enum. |
| tools/gen-proto/main_test.go | Tests generated enum integration. |
| packages/typescript/test/sync/api.test.ts | Adds synchronous API coverage. |
| packages/typescript/test/sync/api-generators.test.ts | Adds generator parity coverage. |
| packages/typescript/test/async/api.test.ts | Tests new API behavior and snapshots. |
| packages/typescript/src/api/sync/types.ts | Adds completion source and data fields. |
| packages/typescript/src/api/sync/api.ts | Generates synchronous and generator methods. |
| packages/typescript/src/api/proto.generated.ts | Updates generated protocol declarations. |
| packages/typescript/src/api/async/types.ts | Exposes completion metadata. |
| packages/typescript/src/api/async/api.ts | Adds public asynchronous methods. |
| packages/typescript/enums/organizeImportsMode.js | Provides runtime organize-imports modes. |
| packages/typescript/enums/organizeImportsMode.d.ts | Declares organize-imports modes. |
Review effort: Balanced
| const completions = await this.getCompletionsAtPosition(file, position, { includeSymbol: true }); | ||
| return completions?.entries.find(entry => entry.name === name && (entry.source ?? "") === (source ?? ""))?.symbol; |
| return lsutil.TextSpan{}, err | ||
| } | ||
| rng := l.converters.FromLSPRangeToOriginal(script, r) | ||
| p := ast.ComputePositionMap(script.text) |
| if link.OriginSelectionRange != nil { | ||
| result.TextSpan, err = l.apiSpan(fileName, *link.OriginSelectionRange) |
| for _, ref := range source.ReferencedFiles { | ||
| if l.program.GetSourceFileFromReference(source, ref) == file { | ||
| entries = append(entries, &ReferenceEntry{kind: entryKindRange, sourceFile: source, textRange: &ref.TextRange}) | ||
| } | ||
| } |
| details := l.getSymbolCompletionFromItemData(ctx, c, file, pos, data) | ||
| result := &lsutil.CompletionEntryDetails{Name: name, Kind: "keyword", DisplayParts: []lsutil.SymbolDisplayPart{{Text: name, Kind: "text"}}, Documentation: []lsutil.SymbolDisplayPart{}, Tags: []lsutil.DisplayJSDocTagInfo{}} |
| if details.symbol != nil { | ||
| quickInfo, err := l.apiQuickInfo(c, details.symbol.location, details.symbol.symbol) | ||
| if err != nil { | ||
| done() | ||
| return nil, err | ||
| } | ||
| if quickInfo != nil { | ||
| result.Kind, result.KindModifiers, result.DisplayParts, result.Documentation, result.Tags = quickInfo.Kind, quickInfo.KindModifiers, quickInfo.DisplayParts, quickInfo.Documentation, quickInfo.Tags | ||
| } | ||
| } |
|
So, the rule of thumb here is that the language service exposes the functions used by the LSP. The LSP has more or less the same functionality as the old TS Server, but different shapes here and there. The goal isn't to create perfect compatibility with the TS 6 language service; the goal is, like TS 6 did, expose the functions that powers the language features it serves in the editor. That means we can expect some of these functions to have different return types, and that's ok. For example, the reason TS 6's quick info API used |

Adds these methods to the API for
LanguageService