Ninja IntelliSense

Ninja IntelliSense brings language support and IntelliSense features to Ninja build files (.ninja) in Visual Studio Code. Perfect for developers working with CMake-generated Ninja files or writing custom Ninja build scripts.
Features
Syntax Highlighting
Syntax highlighting for Ninja build file elements:
- Keywords:
rule, build, default, pool, include, subninja
- Variables:
$var and ${var} references
- Compiler Flags:
-D, -I, -W, -O, /EHsc, and more
- Constants:
DEBUG, RELEASE, WIN32, _WINDOWS
- File Paths: Automatic detection and highlighting
- Comments: Line comments with
#

Auto-Completion
Context-aware completions that speed up your workflow:
- Keyword Snippets: Type
rule, build, etc., and get complete templates
- Rule Variables: Inside rule blocks, get completions for
command, description, depfile, and more
- Built-in Variables: Type
$ to see $in, $out, $builddir
- User Variables: Automatic detection and completion of all variables defined in your file

Hover Documentation
Hover over any keyword or variable to see detailed documentation:
- Ninja Keywords: Learn what each keyword does
- Rule Variables: Understand command, depfile, deps, and more
- Built-in Variables: See what
$in, $out, and $builddir represent
- CMake Variables: Get help with
DEFINES, FLAGS, INCLUDES, TARGET_PDB, and more
- User Variables: See where variables are defined and their values

Go to Definition
Navigate your build files effortlessly:
- Ctrl+Click (or Cmd+Click on Mac) on variables to jump to their definitions
- Ctrl+Click on rule names in build statements to jump to rule definitions
- Quick navigation through complex build files
Document Outline
Get a bird's-eye view of your build file structure:
- See all rules, build targets, variables, and pools
- Click to navigate instantly
- Perfect for large, auto-generated files

CMake Integration (Requires more testing)
Should be optimized for CMake-generated Ninja files with:
- Recognition of CMake-specific variables
- Hover documentation for common CMake build variables
- Syntax highlighting for MSVC and GCC compiler flags
- Support for C++20 module scanning variables
Supported CMake Variables
The extension provides hover documentation for:
| Variable |
Description |
DEFINES |
Preprocessor definitions (-D flags) |
FLAGS |
Compiler flags for the target |
INCLUDES |
Include directories (-I flags) |
DEP_FILE |
Dependency file path |
OBJECT_DIR |
Object file directory |
OBJECT_FILE_DIR |
Target-specific object directory |
TARGET_PDB |
Program database file (MSVC) |
CONFIG |
Build configuration (Debug/Release) |
DYNDEP_MODULE_MAP_FILE |
C++20 module map file |
And many more!
Installation
From VS Code Marketplace
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "Ninja IntelliSense"
- Click Install
From Source
- Clone this repository
- Run
npm install
- Run
npm run compile
- Press F5 to launch the extension in a new VS Code window
Usage
Simply open any .ninja file and the extension will automatically activate!
Quick Start
- Create or open a
.ninja file
- Start typing - Auto-completion should suggest keywords and snippets
- Hover over keywords - See detailed documentation
- Ctrl+Click variables - Jump to definitions
- Open Outline view - Navigate through your build file structure
Example Ninja File
# Build configuration
builddir = build
cflags = -Wall -O2
rule cc
command = gcc $cflags -c $in -o $out
description = Compiling $in
rule link
command = gcc $in -o $out
description = Linking $out
build $builddir/main.o: cc src/main.c
build $builddir/app: link $builddir/main.o
default $builddir/app
Keyboard Shortcuts
| Action |
Windows/Linux |
macOS |
| Trigger Completion |
Ctrl+Space |
Cmd+Space |
| Go to Definition |
Ctrl+Click or F12 |
Cmd+Click or F12 |
| Show Hover |
Ctrl+K Ctrl+I |
Cmd+K Cmd+I |
| Open Outline |
Ctrl+Shift+O |
Cmd+Shift+O |
Requirements
- Visual Studio Code version 1.107.0 or higher
- Ninja v1.12+
Extension Settings
This extension does not add any VS Code settings. It works out of the box!
Issues
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature)
- Commit your changes (
git commit -m 'Add some AmazingFeature')
- Push to the branch (
git push origin feature/AmazingFeature)
- Open a Pull Request
Release Notes
See CHANGELOG.md for detailed release notes.
License
This extension is licensed under the MIT License.
Acknowledgments
- Built for the Ninja and CMake community
- Inspired by the need for better tooling around build systems
- Thanks to all contributors and users!
Enjoy building with Ninja!
If you find this extension helpful, please consider:
- Starring the repository
- Writing a review
- Reporting issues
- Suggesting features