Air

repository·main·Indexed 19 days ago

https://github.com/posit-dev/air

An R formatter and language server written in Rust. Air provides code formatting capabilities and Language Server Protocol (LSP) support for R development, including a Visual Studio Code extension and a command-line tool available via pip, uv, Homebrew, Pixi, and mise.

Tokens
30.6K
Snippets
132
Records
166
Agent score
66%

What's inside air

  1. Overview of biome_ungrammar

    main

    biome_ungrammar is a fork of the rust-analyzer Ungrammar library, maintained by Biome. It provides a grammar specification engine with extended support for specific syntax features not present in the original version.

    Key features added in this fork include:

    • Double-pipe (||) combinator: Specifies "one or more of the alternatives, in any order."
    • Double-amp (&&) combinator: Specifies "all of the alternatives, in any order."
    • Documentation comment parsing: Enables parsing documentation comments to attach them to specific nodes and rules within the grammar.
  2. Run air-formatter without a global installation

    main

    If you do not want to install air globally, you can use uvx to run it as a one-off command. This is useful for temporary formatting tasks.

    To run a one-off command using the latest version:

    uvx --from air-formatter air format path/to/file.R

    To run a specific version of air without installing it:

    uvx --from air-formatter@0.8.2 air format path/to/file.R
  3. Install Air using uv

    main

    If you use uv, you can manage Air via the air-formatter package on PyPI. You can either install it as a global tool or run it as a one-off command without a permanent installation.

    # Global install
    uv tool install air-formatter
    air format path/to/my/script.R
    
    # Invoke once without installing
    uvx --from air-formatter air format path/to/my/script.R
  4. Install Air using Pixi

    main

    You can use Pixi to install Air from the community-maintained conda-forge feedstock. Pixi allows you for adding Air to a specific project, installing it globally, or running it as a one-off command.

    # Add to a project
    pixi add air
    pixi run air format path/to/my/script.R
    
    # Install globally
    pixi global install air
    
    # Run one-off command
    pixi exec air format path/to/my/script.R
  5. Install air-formatter via pip or uv

    main

    You can install the air command-line tool globally using pip or uv. Installing via these methods adds the air command to your PATH, allowing you to run it directly from your terminal.

    To install globally with uv:

    uv tool install air-formatter

    To install globally with pip:

    pip install air-formatter
  6. Generate language syntax crates with `cargo codegen grammar`

    main
    Use the cargo codegen grammar command to automatically generate source code from *.ungram files. This process transforms grammar definitions into the air_*_syntax and air_*_factory crates. The project utilizes a fork of ungrammar to define language syntax via a Domain Specific Language (DSL); after parsing these DSL files, custom logic is applied to generate the corresponding AST (Abstract Syntax Tree) APIs.
    cargo codegen grammar
  7. Install a specific version of air-formatter

    main

    If you need to pin your global installation to a specific version of the formatter, use the @version syntax with uv tool install.

    Example for version 0.8.2:

    uv tool install air-formatter@0.8.2
  8. Run tests generated by `tests_macros`

    main

    You can use standard cargo test commands to execute the generated tests. Use the following patterns to filter your test execution:

    • Run all tests in all crates.
    • Run all tests within a specific crate.
    • Run all tests within a specific crate and a specific module.
    • Run a single specific test generated by the macro.
    # all tests in all crates
    cargo test
    
    # all tests of one crate
    cargo test -p crate-name
    
    # all tests of one crate and one module
    cargo test -p crate-name -- some_mod::
    
    # just one test
    cargo test -p crate-name -- some_mod::somefilename