7.4 KiB
Volar Package API Reference
Docs Index • Repo README • Plugin Authoring • Volar Kit & Editor
This reference summarizes the primary exports and configuration points for the most-used Volar packages. Use it as a quick lookup when wiring custom tooling.
@volar/editor
| Export | Description |
|---|---|
createEditorConnection(languageService) |
Wraps a LanguageService and exposes methods mirroring LSP features (languageFeatures, documents, commands). Ideal for custom editors that do not use JSON-RPC. |
SnapshotDocument |
Text document implementation that tracks versions and provides ts.IScriptSnapshot. |
TextDocuments<T> |
Manages a collection of documents, emits onDidOpen, onDidChangeContent, onDidClose, onDidSave events. |
createUriMap() |
Helper for URI-based maps used by documents/projects. |
Usage Tips:
- Always call
documents.listen()with your editor’s change events so the language service receives updates. - Dispose documents when closed to release snapshots and avoid memory leaks.
- Use
editor.connection.getWorkspaceEdit()to apply edits triggered by code actions/rename.
@volar/language-service
| Export | Description |
|---|---|
createLanguageService(language, plugins, env, project) |
Core factory returning a LanguageService with context, languageFeatures, and commands. |
LanguageServicePlugin |
Interface for authoring plugins (see Plugin Authoring). |
createUriMap, mergeWorkspaceEdits, transformWorkspaceEdit |
Utility helpers used when composing plugins or handling edits. |
FileSystem, LanguageServiceEnvironment |
Shapes describing filesystem + configuration hooks for the service. |
Capabilities: languageService.languageFeatures exposes methods corresponding to LSP requests: getDiagnostics, getCompletionItems, getHover, getDefinition, getCodeActions, etc.
@volar/language-core
| Export | Description |
|---|---|
createLanguage(plugins, scriptRegistry, sync) |
Builds a Language instance that tracks virtual files/embedded codes emitted by language plugins. |
forEachEmbeddedCode |
Generator that iterates embedded files recursively. |
LanguagePlugin |
Interface for describing how to turn source files into virtual code (see Source Map & Code Gen). |
defaultMapperFactory, LinkedCodeMap |
Tools for building and traversing source maps. |
Snapshots: Use language.scripts.get(id) to fetch scripts and language.scripts.set(id, snapshot, languageId) to register new ones.
@volar/typescript
| Export | Description |
|---|---|
createLanguageServiceHost(ts, sys, language, asScriptId, projectHost) |
Bridges Volar’s Language with TypeScript’s LanguageServiceHost. |
decorateLanguageServiceHost(host, opts) |
Augments an existing TS host with Volar hooks. |
createUriConverter(rootFolders) |
Shared helper for converting between file paths and vscode-uri instances. |
createSys |
Builds a virtual ts.System that respects Volar’s FS abstraction. |
TypeScript Plugin Hooks: Within a language plugin you can expose typescript.extraFileExtensions, types definitions, and getServiceScript to feed TS the generated files.
@volar/language-server
| Export | Description |
|---|---|
createServer(connection) |
Low-level factory returning a server object (documents, workspaceFolders, fileWatcher, languageFeatures, etc.). |
createConnection() |
Convenience for creating a VS Code-style connection with proposed features enabled. |
createSimpleProject(languagePlugins) |
Minimal project implementation for non-TypeScript scenarios. |
createTypeScriptProject(ts, tsLocalized, create) |
Full-featured project that manages TS configs, watchers, and workspace diagnostics. |
Features: server.languageFeatures.requestRefresh(clearDiagnostics) forces clients to refresh diagnostics (useful after config changes).
@volar/kit
| Export | Description |
|---|---|
createLanguageServer(options) |
Batteries-included bootstrapper that wires connection, projects, configuration reloads, and restart commands. |
createProjectFactory(opts) |
Helper for building project loaders compatible with the kit. |
Use @volar/kit when you want a ready-made server; drop down to @volar/language-server for custom wiring.
@volar/monaco
See Monaco Playground.
Key Helpers
| Export | Description |
|---|---|
setupLanguageServiceForMonaco(monaco, loaders) |
Registers language service worker + TypeScript loader. |
languageServiceHost (returned) |
Provides writeFile, syncFile, renameFile helpers for your VFS. |
loadTypescript and loadLanguageService should return promises so the worker bundles lazily.
@volar/cli (if used)
While not covered elsewhere, some community tools use @volar/cli as a thin wrapper around the language service. When writing your own CLI, follow the patterns in CLI Integration.
@volar/vue-language-core
| Export | Description |
|---|---|
createVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions, asFileName) |
Default language plugin for .vue SFCs. |
getAllExtensions(vueCompilerOptions) |
Returns file extensions treated as Vue components. |
Utilities (parseSfc, compileTemplate, etc.) |
Used when customizing SFC parsing/compilation. |
Customize via vueCompilerOptions (macros, experimental flags). See TypeScript Plugin Deep Dive.
@volar/vue-language-service
Wraps @volar/language-service with Vue-specific plugins (template completions, directives, twoslash queries).
| Export | Description |
|---|---|
getFullLanguageServicePlugins(ts, opts) |
Returns the default plugin array (TS semantics, CSS, Emmet, Vue-specific features). |
getHybridModeLanguageServicePlugins(ts, getTsPluginClient) |
Reduced set for hybrid environments (e.g., Take Over Mode). |
getVueLanguagePlugin(ts, compilerOptions, vueCompilerOptions) |
Convenience wrapper to create the language plugin. |
Use these helpers when you want the stock Vue feature set without reconfiguring every service manually.
@volar/vue-typescript
TypeScript plugin that injects .vue support into tsserver.
| Export | Description |
|---|---|
createLanguageServerPlugin(ts, resolveConfig) |
Entry point for wiring the plugin inside @volar/language-server / @volar/kit. |
createTypeScriptPlugin(ts, config) |
Low-level API for registering with tsserver directly. |
resolveConfig(workspaceUri) |
Hook for returning vueCompilerOptions per workspace. |
See TypeScript Plugin Deep Dive for details.
@vue/language-core
Vue compiler utilities used under the hood by Volar. Key exports include:
createTsLanguageServiceHost(ts, options)– used when invoking Vue’s TS integrations directly.compileScript,compileTemplate– SFC compilation helpers (useful when customizing macros or template transforms).parseSFC– parse.vuefiles into descriptor objects.
While Volar wraps most of these, advanced integrations may call them directly when customizing compile steps.
With this reference, you can quickly locate the right factory or helper for any integration scenario, complementing the narrative guides throughout the docs.