Skip to content

Tooling & IDE Support

Developer tools for writing, debugging, and maintaining Starlark code.

Language servers provide IDE features like completion, diagnostics, and navigation.

Starpls is a standalone Starlark language server.

Features:

  • Code completion
  • Go to definition
  • Find references
  • Hover documentation
  • Diagnostics

Installation:

Terminal window
brew install starpls

VS Code Setup:

Starpls integrates with VS Code through the vscode-bazel extension (v0.10.0+):

{
"bazel.lsp.command": "starpls"
}

bazel-lsp is based on Facebook’s Starlark language server with Bazel-specific extensions.

VS Code Setup:

{
"bazel.lsp.command": "bazel-lsp"
}

Buck2 includes a built-in language server for its Starlark dialect.

Terminal window
buck2 lsp

Features:

  • Full Buck2 API completion
  • Target navigation
  • Provider documentation
  • BXL support

VS Code Setup:

See Buck2 VS Code extension for integration.

Buck2 provides Debug Adapter Protocol support for stepping through Starlark:

Terminal window
buck2 starlark debug-attach

Features:

  • Breakpoints
  • Step in/out/over
  • Variable inspection
  • Call stack viewing

VS Code launch.json:

{
"version": "0.2.0",
"configurations": [
{
"type": "buck2-starlark",
"request": "attach",
"name": "Attach to Buck2 Starlark",
"port": 4567
}
]
}

Bazel

Bazel BUILD files + LSP support (starpls or bazel-lsp)

Install

Kurtosis

Kurtosis Starlark

Install

PluginIDEFeatures
BazelIntelliJ, CLionBUILD syntax, completion
BuckIntelliJBuck file support

Using nvim-lspconfig:

require('lspconfig').starpls.setup({
cmd = { 'starpls' },
filetypes = { 'starlark', 'bzl', 'star' },
})

Or with Mason:

require('mason-lspconfig').setup({
ensure_installed = { 'starpls' },
})

The official formatter for Bazel BUILD files:

Terminal window
# Install
go install github.com/bazelbuild/buildtools/buildifier@latest
# Format
buildifier -r .
# Check only
buildifier -mode=check -r .

Configuration (.buildifier.json):

{
"version": "6.0.0",
"lint": "warn",
"warnings": ["attr-cfg", "attr-license"]
}

Sky includes a Starlark formatter:

Terminal window
skyfmt path/to/file.star
skyfmt --check . # Check without modifying

Buildifier includes lint checks:

Terminal window
buildifier -lint=warn path/to/BUILD.bazel

Common warnings:

  • load-on-top - Load statements should be first
  • same-origin-load - Combine loads from same file
  • unused-variable - Remove unused variables

Sky provides additional Starlark-specific checks:

Terminal window
skylint path/to/file.star

Checks include:

  • Unused imports and variables
  • Naming conventions
  • Performance issues
  • Security concerns

Sky’s test runner:

Terminal window
skytest path/to/test.star

Test file format:

test_math.star
load("math.star", "add", "multiply")
def test_add():
assert_eq(add(1, 2), 3)
assert_eq(add(-1, 1), 0)
def test_multiply():
assert_eq(multiply(2, 3), 6)
assert_eq(multiply(0, 5), 0)

Bazel Skylib testing for Bazel rules:

load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
def _add_test_impl(ctx):
env = unittest.begin(ctx)
asserts.equals(env, 3, add(1, 2))
return unittest.end(env)
add_test = unittest.make(_add_test_impl)

Interactive Starlark shell:

Terminal window
skyrepl
>>> x = [1, 2, 3]
>>> [i * 2 for i in x]
[2, 4, 6]
>>> def greet(name):
... return "Hello, " + name
...
>>> greet("World")
"Hello, World"
Terminal window
go run go.starlark.net/cmd/starlark
Terminal window
buck2 starlark repl

Bazel’s documentation generator:

BUILD.bazel
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
stardoc(
name = "my_rules_docs",
input = "my_rules.bzl",
out = "my_rules.md",
)

Sky’s documentation generator:

Terminal window
skydoc path/to/module.star -o docs/

Generates markdown from docstrings:

def build_target(name, srcs, deps = []):
"""Creates a build target.
Args:
name: Target name (must be unique)
srcs: Source files to compile
deps: Optional dependencies
Returns:
A target object
"""
...
  1. Install Starpls

    Terminal window
    brew install starpls
  2. Configure VS Code

    Install the vscode-bazel extension and configure:

    {
    "bazel.lsp.command": "starpls"
    }
  3. Install Buildifier

    Terminal window
    go install github.com/bazelbuild/buildtools/buildifier@latest
  4. Configure Format on Save

    {
    "[starlark]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "BazelBuild.vscode-bazel"
    }
    }
  5. Set Up Pre-commit Hook

    .pre-commit-config.yaml
    repos:
    - repo: https://github.com/keith/pre-commit-buildifier
    rev: 6.4.0
    hooks:
    - id: buildifier
    - id: buildifier-lint
Toolstarlark-ruststarlark-gostarlark-java
LSP✅ Built-in⚠️ Starpls⚠️ Starpls
DAP✅ Built-in
REPL
Formatter✅ Buildifier✅ Buildifier✅ Buildifier
Linter✅ Buildifier✅ Buildifier✅ Buildifier