Skip to main content
The 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

host
LanguageServiceHost
required
Provides file system access and compilation settings. Implement this interface to provide file content and compiler options.
documentRegistry
DocumentRegistry
Optional. Caches parsed source files across Language Service instances.
syntaxOnlyOrLanguageServiceMode
boolean | LanguageServiceMode
Optional. Controls whether to perform type checking:
  • true / LanguageServiceMode.Syntactic: Syntax-only mode
  • false / LanguageServiceMode.Semantic: Full semantic mode (default)
  • LanguageServiceMode.PartialSemantic: Limited semantic analysis

LanguageService Interface

Lifecycle Methods

cleanupSemanticCache
() => void
Clears the semantic cache. Use this when restarting the language service or when compiler options change.
dispose
() => void
Disposes the language service and releases resources.

Diagnostic Methods

getSyntacticDiagnostics
(fileName: string) => DiagnosticWithLocation[]
Gets syntax errors in a file. These are fast to compute and don’t require type information.
getSemanticDiagnostics
(fileName: string) => Diagnostic[]
Gets type system errors in a file. The first call may be slow as it initializes the type checker.
getSuggestionDiagnostics
(fileName: string) => DiagnosticWithLocation[]
Gets suggestion diagnostics that proactively suggest refactors or improvements.
getCompilerOptionsDiagnostics
() => Diagnostic[]
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.
getDefinitionAtPosition
(fileName: string, position: number) => DefinitionInfo[] | undefined
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.
getTypeDefinitionAtPosition
(fileName: string, position: number) => DefinitionInfo[] | undefined
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.
getReferencesAtPosition
(fileName: string, position: number) => ReferenceEntry[] | undefined
Finds all references to a symbol.
findReferences
(fileName: string, position: number) => ReferencedSymbol[] | undefined
Finds references grouped by definition.

Rename

getRenameInfo
(fileName: string, position: number, preferences: UserPreferences) => RenameInfo
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.
getSupportedCodeFixes
(fileName?: string) => string[]
Gets all supported code fix error codes.

Formatting

getFormattingEditsForRange
(fileName: string, start: number, end: number, options: FormatCodeSettings) => TextChange[]
Formats a range of text.
getFormattingEditsForDocument
(fileName: string, options: FormatCodeSettings) => TextChange[]
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

getProgram
() => Program | undefined
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