Skip to content

Add missing methods to Language service api - #65815

Open
Isabel Duan (iisaduan) wants to merge 23 commits into
microsoft:mainfrom
iisaduan:languageServiceApi
Open

Isabel Duan (iisaduan) wants to merge 23 commits into
microsoft:mainfrom
iisaduan:languageServiceApi

Conversation

@iisaduan

@iisaduan Isabel Duan (iisaduan) commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Adds these methods to the API for LanguageService

  • getProgram 
  •  getEmitOutput 
  •  getSyntacticDiagnostics 
  •  getSemanticDiagnostics 
  •  getSuggestionDiagnostics 
  •  getDefinitionAtPosition 
  •  getDefinitionAndBoundSpan 
  •  getTypeDefinitionAtPosition 
  •  getImplementationAtPosition 
  •  findReferences 
  •  getReferencesAtPosition 
  • getFileReferences 
  •  getRenameInfo 
  •  findRenameLocations 
  •  getEditsForFileRename 
  •  getQuickInfoAtPosition 
  •  getCompletionEntryDetails 
  •  getCompletionEntrySymbol 
  •  getFormattingEditsAfterKeystroke 
  •  getFormattingEditsForDocument 
  •  getFormattingEditsForRange 
  •  organizeImports 
  •  getJsxClosingTagAtPosition 
  •  getLinkedEditingRangeAtPosition 
  •  toLineColumnOffset 

@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Dec 4, 2026
@iisaduan Isabel Duan (iisaduan) changed the title Language service api Add missing methods to Language service api Dec 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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
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

Comment on lines +1968 to +1969
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)
Comment on lines +230 to +231
if link.OriginSelectionRange != nil {
result.TextSpan, err = l.apiSpan(fileName, *link.OriginSelectionRange)
Comment on lines +373 to +377
for _, ref := range source.ReferencedFiles {
if l.program.GetSourceFileFromReference(source, ref) == file {
entries = append(entries, &ReferenceEntry{kind: entryKindRange, sourceFile: source, textRange: &ref.TextRange})
}
}
Comment on lines +580 to +581
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{}}
Comment on lines +608 to +617
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
}
}
@andrewbranch

Copy link
Copy Markdown
Member

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 SymbolDisplayPart was because Visual Studio needed it for syntax highlighting hovers. Now, the standard way to do that in LSP is to return markdown, so we didn't port the code that generates SymbolDisplayPart. We don't want to have that code sitting around just for API usage—we only want code that's also useful to our existing LSP implementation. (That may end up justifying renaming some of these methods (quick info -> hover) too, but that's an easy change.)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

3 participants