Diagnostics
Real-time error detection including undefined names, unused variables, and style issues via skylint rules.
skyls is a Language Server Protocol (LSP) implementation for Starlark files. It provides IDE features like diagnostics, completion, hover documentation, go-to-definition, and formatting.
Diagnostics
Real-time error detection including undefined names, unused variables, and style issues via skylint rules.
Completion
Autocomplete for keywords, builtins, modules, and document symbols. Context-aware suggestions.
Hover
Documentation on hover for functions and variables defined in the current file.
Formatting
Format documents using buildifier-compatible formatting via skyfmt.
Go to Definition
Jump to function definitions, variable assignments, and load statement sources.
Document Symbols
Outline view showing all functions and top-level variables in a file.
go install github.com/albertocavalcante/sky/cmd/skyls@latestVerify the installation:
skyls --versionInstall the Sky Starlark extension from the VS Code marketplace, or configure the generic LSP client:
settings.json:{ "starlark.lsp.enabled": true, "starlark.lsp.path": "skyls"}Add to your Neovim configuration:
-- lua/plugins/lsp.lua or init.lualocal lspconfig = require('lspconfig')local configs = require('lspconfig.configs')
-- Register skyls if not already definedif not configs.skyls then configs.skyls = { default_config = { cmd = { 'skyls' }, filetypes = { 'starlark', 'bzl', 'bazel', 'star' }, root_dir = lspconfig.util.root_pattern( 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel', '.buckconfig', 'Tiltfile', '.git' ), settings = {}, }, }end
lspconfig.skyls.setup({ on_attach = on_attach, -- your on_attach function capabilities = capabilities, -- your capabilities})Add filetype detection in ~/.config/nvim/filetype.lua:
vim.filetype.add({ extension = { star = 'starlark', bzl = 'bzl', bazel = 'bazel', }, filename = { ['BUILD'] = 'bazel', ['BUILD.bazel'] = 'bazel', ['WORKSPACE'] = 'bazel', ['WORKSPACE.bazel'] = 'bazel', ['MODULE.bazel'] = 'bazel', ['BUCK'] = 'bzl', ['Tiltfile'] = 'starlark', },})Add to ~/.config/helix/languages.toml:
[[language]]name = "starlark"scope = "source.starlark"injection-regex = "starlark"file-types = ["star", "bzl", "bazel", "BUILD", "WORKSPACE", "Tiltfile"]comment-token = "#"indent = { tab-width = 4, unit = " " }language-servers = ["skyls"]
[language-server.skyls]command = "skyls"Add to your Zed settings (~/.config/zed/settings.json):
{ "lsp": { "skyls": { "binary": { "path": "skyls" } } }, "languages": { "Starlark": { "language_servers": ["skyls"] } }}Install the LSP package, then add to LSP settings:
{ "clients": { "skyls": { "enabled": true, "command": ["skyls"], "selector": "source.starlark | source.bazel" } }}Add to your Emacs configuration:
(use-package lsp-mode :hook ((starlark-mode . lsp) (bazel-mode . lsp)) :config (lsp-register-client (make-lsp-client :new-connection (lsp-stdio-connection '("skyls")) :major-modes '(starlark-mode bazel-mode) :server-id 'skyls)))skyls [options]| Option | Description |
|---|---|
--version | Print version and exit |
--help | Show help message |
The server communicates over stdin/stdout using the JSON-RPC 2.0 protocol as defined by the LSP specification.
| Method | Support |
|---|---|
initialize | Full |
initialized | Full |
shutdown | Full |
exit | Full |
| Method | Support |
|---|---|
textDocument/didOpen | Full |
textDocument/didChange | Full (full sync) |
textDocument/didClose | Full |
textDocument/didSave | Full |
| Method | Support |
|---|---|
textDocument/hover | Functions and globals in current file |
textDocument/completion | Keywords, builtins, modules, document symbols |
textDocument/definition | Same-file definitions |
textDocument/documentSymbol | Functions and top-level assignments |
textDocument/formatting | Full document formatting |
skyls provides two types of diagnostics:
Buildtools-compatible lint rules including:
skyls provides context-aware completions:
def, if, for, return, load, etc.len, range, str, dict, list, etc.json, math, timeWhen typing after a dot (e.g., json.), skyls completes module members:
json. # Completes: decode, encode, indentmath. # Completes: ceil, floor, round, sqrt, pow, log, exp, pi, e, infInside a function body, parameters are included in completions:
def process(input_data, config): # Typing 'in' suggests 'input_data' # Typing 'co' suggests 'config'skyls automatically detects the file type based on filename patterns:
| Pattern | File Kind | Parser Mode |
|---|---|---|
BUILD, BUILD.bazel | BUILD | Bazel BUILD |
*.bzl | Bzl | Bazel extension |
WORKSPACE, WORKSPACE.bazel | WORKSPACE | Bazel workspace |
MODULE.bazel | MODULE | Bazel module |
BUCK | BUCK | Buck2 BUILD |
Tiltfile | Starlark | Generic |
*.star, *.sky | Starlark | Generic |
Verify skyls is in your PATH:
which skylsCheck the server runs manually:
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"capabilities":{}}}' | skylsskyls caches parsed documents and only re-analyzes on changes. If you experience slowness: