LanguageService interface is the main entry point for editor tooling. It provides methods for completions, diagnostics, navigation, refactoring, and more.
Creating a Language Service
Function Signature
Provides file system access and compilation settings. Implement this interface to provide file content and compiler options.
Optional. Caches parsed source files across Language Service instances.
Optional. Controls whether to perform type checking:
true/LanguageServiceMode.Syntactic: Syntax-only modefalse/LanguageServiceMode.Semantic: Full semantic mode (default)LanguageServiceMode.PartialSemantic: Limited semantic analysis
LanguageService Interface
Lifecycle Methods
Clears the semantic cache. Use this when restarting the language service or when compiler options change.
Disposes the language service and releases resources.
Diagnostic Methods
Gets syntax errors in a file. These are fast to compute and don’t require type information.
Gets type system errors in a file. The first call may be slow as it initializes the type checker.
Gets suggestion diagnostics that proactively suggest refactors or improvements.
Gets diagnostics related to the compiler options and program configuration.
Completion Methods
getCompletionsAtPosition
(fileName: string, position: number, options?: GetCompletionsAtPositionOptions, formattingSettings?: FormatCodeSettings) => CompletionInfo | undefined
Gets completion suggestions at a specific position. This powers IntelliSense in editors.See Completions API for detailed documentation.
getCompletionEntryDetails
(fileName: string, position: number, entryName: string, formatOptions: FormatCodeOptions | undefined, source: string | undefined, preferences: UserPreferences | undefined, data: CompletionEntryData | undefined) => CompletionEntryDetails | undefined
Gets extended details for a completion entry, including documentation and full signature.
getCompletionEntrySymbol
(fileName: string, position: number, name: string, source: string | undefined) => Symbol | undefined
Gets the symbol for a completion entry.
Quick Info & Signature Help
getQuickInfoAtPosition
(fileName: string, position: number, maximumLength?: number) => QuickInfo | undefined
Gets hover information at a position. This powers hover tooltips in editors.
getSignatureHelpItems
(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined) => SignatureHelpItems | undefined
Gets signature help for function calls. This powers parameter hints in editors.
Navigation Methods
Gets the definition(s) of a symbol at a position. Powers “Go to Definition”.See Navigation API for more details.
getDefinitionAndBoundSpan
(fileName: string, position: number) => DefinitionInfoAndBoundSpan | undefined
Gets definitions and the span of the identifier at the position.
Gets the type definition(s) of a symbol. Useful for navigating to interface or type alias definitions.
getImplementationAtPosition
(fileName: string, position: number) => ImplementationLocation[] | undefined
Gets implementations of an interface or abstract class.
Finds all references to a symbol.
Finds references grouped by definition.
Rename
Checks if rename is available at a position.
findRenameLocations
(fileName: string, position: number, findInStrings: boolean, findInComments: boolean, preferences: UserPreferences) => RenameLocation[] | undefined
Finds all locations that will be affected by a rename.
Refactoring
getApplicableRefactors
(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined, triggerReason?: RefactorTriggerReason, kind?: string, includeInteractiveActions?: boolean) => ApplicableRefactorInfo[]
Gets available refactorings at a position or range.
getEditsForRefactor
(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined, interactiveRefactorArguments?: InteractiveRefactorArguments) => RefactorEditInfo | undefined
Gets the text edits for a specific refactoring.
organizeImports
(args: OrganizeImportsArgs, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined) => FileTextChanges[]
Organizes imports in a file.
Code Fixes
getCodeFixesAtPosition
(fileName: string, start: number, end: number, errorCodes: number[], formatOptions: FormatCodeSettings, preferences: UserPreferences) => CodeFixAction[]
Gets available code fixes for diagnostics at a position.
Gets all supported code fix error codes.
Formatting
getFormattingEditsForRange
(fileName: string, start: number, end: number, options: FormatCodeSettings) => TextChange[]
Formats a range of text.
Formats an entire document.
getFormattingEditsAfterKeystroke
(fileName: string, position: number, key: string, options: FormatCodeSettings) => TextChange[]
Gets formatting edits after typing a character (e.g., ’;’, ’}’, Enter).
Program Access
Gets the current TypeScript Program.
Example: Complete Editor Integration
Editor.ts
See Also
Completions API
Detailed completion API reference
Diagnostics API
Error reporting and diagnostics
Navigation API
Go to definition and find references