Skip to content

google/gn-language-server

GN Language Server

CI

A language server for GN, the build configuration language used in Chromium, Fuchsia, and other projects.

Features

  • Syntax highlighting
  • Syntax error reporting
  • Context-aware completion and auto-import
  • Hover documentation
  • Go to definition
  • Finding target references
  • Following imports
  • Following dependencies
  • Quick fix
  • Sticky scroll with useful lines
  • Code lens
  • Outline
  • Code folding
  • Formatting
  • Go to the nearest BUILD.gn (VSCode only)

Installing

VSCode and its derivatives

You can install an extension with prebuilt language server binaries from the official VSCode marketplace or the OpenVSX marketplace. Search for "GN Language" in the VSCode's extension window.

VSCode Marketplace

JetBrains IDEs (IntelliJ, CLion, Android Studio, etc.)

You can install a plugin with prebuilt language server binaries from the JetBrains marketplace. Search for "GN Language" in the IDE's plugin window.

NeoVim

gn-language-server is registered to nvim-lspconfig, mason-registry, and mason-lspconfig. Thus, assuming that you have enabled mason-lspconfig, you can install and enable it with the following simple command:

:MasonInstall gn-language-server

The language server does not provide syntax highlighting though. You can use nvim-treesitter for this.

Emacs

Install the language server with Cargo.

cargo install --locked gn-language-server

Then set up gn-mode or any syntax highlighting mode for GN, and add the following to your config:

(use-package gn-mode
  :ensure t
  :mode ("\\.gn\\'" "\\.gni\\'")
  :hook (gn-mode . eglot-ensure)
  :config
  (with-eval-after-load 'eglot
    (add-to-list 'eglot-server-programs '(gn-mode . ("gn-language-server")))))

Other Editors/IDEs

You can download prebuilt language server binaries from GitHub releases page.

Alternatively, you can build the language server from source with Cargo.

cargo install --locked gn-language-server

Then follow editor-specific instructions to install the language server.

Gallery

Syntax highlighting

Syntax highlighting

Completion and auto-import

Completion and auto-import

Hover documentation

Hover documentation

Go to definition

Go to definition

Following imports

Following imports

Following dependencies

Following dependencies

Quick fix

Quick fix

Sticky scroll with useful lines

Sticky scroll with useful lines

Code lens

Code lens

Outline

Outline

Code folding

Code folding

Building from source

Language server binary

cargo build --release

VSCode extension

cd vscode-gn
npm install
npm run build
npm run package

Versioning scheme

We use the versioning scheme recommended by the VSCode's official documentation. That is:

  • Pre-release versions are 1.<odd>.x
  • Release versions are 1.<even>.x

For Rust releases on crates.io, we use 1.<even>.x-prerelease for pre-releases.

Architecture

For an overview of the project's architecture, see ARCHITECTURE.md.

Disclaimer

This is not an officially supported Google product. This project is not eligible for the Google Open Source Software Vulnerability Rewards Program.