Skip to content

About

Unofficial language server for Virgil, written in Virgil on the compiler's own parser and type checker. Works in Neovim and VS Code.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Virgil Language Server

CI

A Language Server Protocol implementation for the Virgil programming language, written in Virgil and built on the Aeneas compiler's own parser and type checker.

Unofficial project. This is an independent community tool. It is not affiliated with or endorsed by the Virgil maintainers.

Status: stable. 1.0.0 is the first stable release, on pinned Virgil 4aa91254. Its server code is that of 1.0.0-rc.1, except that the JVM build's default analysis time limit is now 30 seconds. From 1.0, the declared public API follows Semantic Versioning: an intentional incompatible change to the server's command line or initialization options needs a new server major version, and one to a client setting a new major version of the extension. VS Code extension 1.0.0 is no longer marked as a preview, and the LazyVim configuration indents Virgil buffers with tabs (CHANGELOG.md). 1.0.0-rc.1 fixed the VS Code pending-edit restart error by updating vscode-languageclient to 11.0.1 (#211), set bounded heap and GC settings on the preview JVM build (#463), and fixed four more rare formatter layouts (#551, #598). The formatter came with 0.1.0-alpha.8: virgil-lsp format prints a file's formatted text, --check reports the files that would change, and --write replaces them on native builds, and the server formats open Virgil documents through textDocument/formatting (Formatting in Neovim and LazyVim, Formatting in VS Code). The diagnostics and navigation milestones (M2–M4) were completed with 0.1.0-alpha.1, and the references, rename, signature help, and completion milestone (M5) with 0.1.0-alpha.2; see ROADMAP.md. The server reports syntax errors and a document outline for open files, including unsaved edits, plus type errors, go-to-definition, go-to-type-definition, hover, references, rename, workspace symbols, and signature help, including for calls still being typed, across the files of a configured project. Document highlights mark a symbol's declaration and uses in the current document. Go to implementation lists the classes that extend a class and the methods that override a method. Type hierarchy shows a class's or variant's supertype and the types that extend it, one level at a time. Call hierarchy shows the callers of a method or constructor and the functions it calls, one level at a time. Completion offers keywords in any open file, even one that doesn't parse, the declarations in scope at the cursor in a configured project, and, after ., the members of the receiver's type, repairing incomplete code at the cursor. The occurrence index defines which names resolve, and the architecture guide describes how each part works.

Since 0.1.0-alpha.5, syntax-based folding ranges fold brace blocks and multiline comments from the current open document, including unsaved edits.

Since 0.1.0-alpha.5, selection ranges expand selections through tokens, bracket groups, declarations, and the document from the current open text.

Since 0.1.0-alpha.5, semantic tokens color the names in a project by the declarations that they resolve to.

Why

Virgil has a self-hosted compiler. Running v3c on save gives diagnostics for saved files only. It can't provide go-to-definition or hover, which need the compiler's bound syntax tree. This project uses Aeneas's front end so editors can get the compiler's real semantics instead of a reimplementation; see the process model.

0.1.0-alpha.5 also provides the missing-semicolon quick fix through versioned code actions in VS Code and Neovim.

v0.1 scope

One server, used by both LazyVim/Neovim and VS Code, providing:

  • .v3 file detection
  • parser and type-checker diagnostics for unsaved buffers
  • document symbols
  • go-to-definition for locals, members, methods, and named types
  • go-to-type-definition from resolved value and call-result types, including generic types and type parameters
  • inlay hints for inferred local types and direct-call parameter names
  • hover with declaration signatures and inferred types; leading comments also appear below them
  • a .virgil-lsp.json project file describing which sources form a program

Incremental analysis comes after v0.1. Some later features are already available: references and signature help since 0.1.0-alpha.1, and rename and completion of keywords, in-scope declarations, and members since 0.1.0-alpha.2; completion items also show their declarations' leading comments. Since 0.1.0-alpha.8, the virgil-lsp format command keeps the author's line breaks apart from moving eligible body braces up to their headers, joining eligible } and else lines, and normalizing the end of the file. virgil-lsp format --check reports files that aren't formatted. virgil-lsp format --write replaces the files that formatting changes on native builds, through a new file renamed over each one. It takes no lock, so a save between its last check and the rename can be lost (Running, ADR-0019). The server also formats open Virgil documents by the same rules when the editor asks (textDocument/formatting), with separate edits confined to changed whitespace and a single edit across the changed span when there are more than 10,000 changes. The Neovim and LazyVim tests cover formatting on demand, and the LazyVim test also covers its default format-on-save behavior (Formatting). With a server that supports formatting, VS Code extension 0.1.7 enables formatting on explicit saves by default, and its Extension Host test checks it (Formatting). Debugging is out of scope. Known limitations lists what else the server doesn't do yet.

Architecture

The architecture guide describes the server and its compiler adapter. The analysis worker serves the development analyze command and the unadvertised development stdio requests. See the configuration guide for project discovery and configuration diagnostics.

Building

Requirements: Linux x86-64 or an Apple Silicon Mac with Rosetta 2, plus the development prerequisites. WSL 2 on Windows is best effort. See docs/compatibility.md for the full platform list. The Virgil compiler comes from the pinned submodule, so you don't need a separate Virgil install.

git clone --recurse-submodules https://github.com/SaltedTan/virgil-language-server.git
cd virgil-language-server
make test        # builds build/virgil-lsp and build/virgil-lsp-worker, and runs available tests

Keep virgil-lsp-worker next to virgil-lsp when moving the executables. New release archives also include virgil/ with the pinned library and the x86-64-linux runtime sources: keep it beside the executables to analyze virgilDependencies under lib/ and x86-64-linux target projects without a separate checkout. An optional client root overrides the bundle; other sources outside lib/ still need a checkout (root selection). Releases describes the release archives, how to verify them, and how to install them.

Try the current development command:

build/virgil-lsp --version
build/virgil-lsp parse test/fixtures/syntax/tab-error.v3
build/virgil-lsp analyze --bindings test/fixtures/analysis/two-file/*.v3
build/virgil-lsp format --check src/main.v3

See docs/development.md for details.

Editor setup

For VS Code, install the VSIX for your workspace platform: linux-x64, darwin-arm64 (requires Rosetta 2), or darwin-x64. It includes the server, worker, and pinned library. No separate server installation or path setting is needed. On Apple Silicon without Rosetta 2, use the darwin-arm64-jvm VSIX, a preview JVM build with its own Java runtime. The universal VSIX is available for external-server installations.

For Neovim, LazyVim, Emacs, or an external VS Code server, install the server first. On Apple Silicon without Rosetta 2, use the JVM archive. On Linux x86-64, with curl, tar, and sha256sum installed, run the following in a terminal. Replace server_version with the release version and download_url with that release's asset download location (or a directory served over HTTP containing the downloaded assets). The checksum comes from the same release; download it along with the archive.

server_version=1.0.0
download_url=https://github.com/SaltedTan/virgil-language-server/releases/download/v$server_version
archive=virgil-lsp-$server_version-x86-64-linux.tar.gz
mkdir -p "$HOME/Downloads/virgil-lsp" &&
cd "$HOME/Downloads/virgil-lsp" &&
curl --fail --location "$download_url/$archive" -o "$archive" &&
curl --fail --location "$download_url/SHA256SUMS" -o SHA256SUMS &&
awk -v file="$archive" '$2 == file' SHA256SUMS | sha256sum --check --strict &&
mkdir -p "$HOME/.local/opt" "$HOME/.local/bin" &&
tar -xzf "$archive" -C "$HOME/.local/opt" &&
ln -sf "$HOME/.local/opt/virgil-lsp-$server_version-x86-64-linux/virgil-lsp" "$HOME/.local/bin/virgil-lsp" &&
export PATH="$HOME/.local/bin:$PATH" &&
virgil-lsp --version

Keep the worker and virgil/ beside the server. Add the export PATH line to your shell's startup file for future terminals, and start your editor from this terminal for the first install. For macOS downloads, checksum verification, and Rosetta 2, see Installing.

For VS Code, install the VSIX. Neovim and LazyVim setup and integration status live in editors/nvim/. For Helix, a best-effort, grammar-free configuration and setup guide live in editors/helix/; it is outside the supported editor matrix. A best-effort Emacs configuration for Eglot, outside the tested editor matrix, is in editors/emacs/. Once the server is installed, try your first project: a small checked-in example with a deliberate type error, its one-word fix, and a hover and go-to-definition to check.

If the server doesn't start, or a file gets no diagnostics or navigation, see Troubleshooting. PRIVACY.md states what the server and the editor integrations read, write, and start; they collect no telemetry and make no network connections.

Contributing

Bug reports, documentation, tests, and code are all welcome. Please read CONTRIBUTING.md and the Code of Conduct. Report security issues as described in SECURITY.md.

License

The project's code is licensed under the Apache License, Version 2.0. Third-party material retains its upstream licenses; see THIRD_PARTY_NOTICES.md.

About

Unofficial language server for Virgil, written in Virgil on the compiler's own parser and type checker. Works in Neovim and VS Code.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages