Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

directiveBadge

Colored chip showing a file's --!nocheck / --!nolint / --!nocheck:<codes> directive state. Input is exactly what lsp.readDirectives(source) returns: { mode = "none" | "all" | "lint" | "codes", codes? = {string} }.

Returns nil when mode == "none" (no directive present) so the caller can drop the result into a layout without conditionals cluttering the call site. Pass opts.showNone = true to render a neutral "no directive" chip for layouts that need the slot occupied.

Exports

  • directiveBadge(skipMode: SkipMode?, opts: Opts?) -> any? — build the chip. Returns nil for mode == "none" unless opts.showNone is set. Returned directly by the module.

Types:

  • SkipMode = { mode?: string, codes?: { string } }
  • Opts = { id?: string, padding?: { number }, showNone?: boolean }

Usage

local directiveBadge = require("@builtin::modules.zui.widget.lsp.directiveBadge")

children[#children + 1] = directiveBadge(lsp.readDirectives(source))
-- or, always-occupy-slot variant:
children[#children + 1] = directiveBadge(d, { showNone = true })

Notes

  • The chip color tracks severity: danger for --!nocheck (all passes skipped), warn for --!nolint and --!nocheck:<codes>.
  • Tooltip text spells out exactly which passes / codes the directive silences so an inspector view doesn't need a separate explanation panel.
  • Pure presentational — no side effects, no LSP calls. The caller is responsible for refreshing the directive state when the source changes.