texlsp LaTeX Language Server for VS Code

VS Code integration for texlsp, with a bundled WASI runtime and an optional
native executable fallback.
Author: Yifan Yang yfyang.86@hotmail.com
No Rust installation is needed for the default runtime. The extension
includes server/texlsp.wasm and uses Microsoft's ms-vscode.wasm-wasi-core
extension, which is installed automatically as a dependency. Native binaries
are optional. This release targets desktop VS Code, not browser workers.
Features
- Diagnostics for unmatched environments, duplicate labels, and undefined
references/citations.
- Context-aware command, environment, label, citation, file, and package
completion.
- Go to definition, hierarchical document symbols, and macro hover.
- Safe-subset document formatting.
texlsp.expandMacro integration that applies the server's edits to the
original document and rejects stale responses.
- Start, stop, restart, output, and LSP trace controls.
File and untitled documents with the latex, tex, or plaintex language ID
are supported. VS Code supplies the built-in TeX/LaTeX grammars; this extension
does not replace them.
Server runtimes
Bundled WASI (default)
No setup is required beyond enabling the ms-vscode.wasm-wasi-core dependency.
The extension starts the bundled server/texlsp.wasm with shared memory and
mounts the current workspace for bibliography and include-file access.
Native executable (optional)
Install the published source with Cargo (requires a Rust toolchain):
cargo install --git https://github.com/yfyang86/rsTexLSP
Alternatively, from a repository checkout, run cargo install --path .. Select
native mode and, if necessary, configure the executable:
{
"texlsp.runtime": "native",
"texlsp.serverPath": "/absolute/path/to/texlsp"
}
A bare texlsp value uses PATH. When using a remote workspace, install the
native server in that remote environment.
Install the extension
Marketplace
code --install-extension yfyang.texlsp-vscode
Local VSIX
From editors/vscode:
npm ci
npm run package
code --install-extension texlsp-vscode-0.1.0.vsix
Reload VS Code if prompted, then open a .tex file. The server starts
automatically by default. Installing a local VSIX does not publish it to the
Marketplace.
Settings
{
"texlsp.runtime": "wasm",
"texlsp.serverPath": "texlsp",
"texlsp.serverArgs": [],
"texlsp.autoStart": true,
"texlsp.trace.server": "off"
}
texlsp.runtime: wasm uses the bundled WASI module; native starts the
configured executable.
texlsp.serverPath: native mode only. An executable name, absolute path, or
workspace-relative path. A bare name uses PATH; a relative path containing
/ or \ is resolved from the current workspace folder.
texlsp.serverArgs: native mode only. Additional executable arguments.
texlsp.autoStart: start when a supported document is activated. If disabled,
use the start command manually.
texlsp.trace.server: off, messages, or verbose. Trace output appears
in texlsp Trace; client messages appear in texlsp.
Changing the runtime, executable, or arguments restarts a running server.
Changing trace verbosity does not require a restart.
Commands
Open the Command Palette and search for texlsp:
- Start Language Server (
texlsp.start)
- Stop Language Server (
texlsp.stop)
- Restart Language Server (
texlsp.restart)
- Expand Macro Under Cursor (
texlsp.expandMacroAtCursor)
- Show Output (
texlsp.showOutput)
For macro expansion, place the cursor on a command defined with \newcommand
and run Expand Macro Under Cursor. For example, with
\newcommand{\swap}[2]{#2/#1}, expanding \swap{A}{B} produces exactly B/A.
Normal VS Code gestures work without extension-specific keybindings: hover,
completion, go to definition, document symbols, and format document.
Development and verification
Use Node.js 22 or newer and install the WASI Rust target once:
rustup target add wasm32-wasip1-threads
npm install
npm run check
npm test
npm test builds native and WASI release artifacts, then runs the complete
integration suite in a real VS Code Extension Development Host once for each
runtime. Fresh profiles and extension directories isolate the tests from your
normal setup; ms-vscode.wasm-wasi-core is installed only in those profiles.
The standard macOS VS Code installation is used when present, otherwise
test-electron downloads VS Code. VSCODE_EXECUTABLE_PATH can select another
actual VS Code executable (not the code CLI wrapper). For example:
VSCODE_EXECUTABLE_PATH="/Applications/Visual Studio Code.app/Contents/MacOS/Code" npm test
The tests exercise diagnostics, definition, completion, symbols, hover,
formatting, macro expansion, bibliography access, incremental updates, restart,
and shutdown. Artifacts are written under target/tmp.
Build the WASM artifact or package the complete extension with:
npm run build:wasm
npm run package
npm run package rebuilds the WASM artifact through vscode:prepublish.
License
The extension and server are available under either the MIT License or Apache
License 2.0, at your option. See LICENSE-MIT and
LICENSE-APACHE.