pawnkit-core

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2026 License: MIT

README

pawnkit-core

pawnkit-core contains the small Go types shared by PawnKit tools: source positions, text edits, diagnostics, and their JSON wire format.

This keeps a diagnostic or workspace edit consistent as it moves between the parser, linter, CLI, and editor. The module has no dependency on another PawnKit repository.

Status

The module is pre-1.0. Breaking changes are recorded in CHANGELOG.md; the version policy is in docs/compatibility.md.

Install

go get github.com/pawnkit/pawnkit-core

Requires Go 1.26 or later.

Choose a package

Package Purpose
source File IDs, URIs, byte spans, snapshots, and editor position conversion
textedit Validated, version-aware file and workspace edits
diagnostic Findings, related locations, fixes, and suppressions
protocol Versioned JSON encoding for diagnostics
hash Stable hashes for content and cache keys

Runnable examples for each package live under examples/.

Quick start

package main

import (
	"fmt"

	"github.com/pawnkit/pawnkit-core/diagnostic"
	"github.com/pawnkit/pawnkit-core/source"
)

func main() {
	reg := source.NewRegistry()
	file := reg.Intern(source.FileURI("/gamemodes/main.pwn"))

	span, _ := source.NewSpan(file, 10, 25)

	d := diagnostic.New(
		"pawnlint:deprecated-func",
		"pawnlint",
		diagnostic.SeverityWarning,
		"SetPlayerColor is deprecated",
		span,
	)

	if err := d.Validate(); err != nil {
		panic(err)
	}

	fmt.Println(d.Message)
}

Contracts worth knowing

  • Source spans use byte offsets. Convert them through LineIndex when an editor needs UTF-8, UTF-16, or UTF-32 positions.
  • source.FileID is process-local. Serialized diagnostics use a URI instead.
  • textedit computes new content but does not write files.
  • Each type documents whether its zero value is usable.

What does not belong here

Parsers, project manifests, API data, CLI frameworks, and tool-specific caches belong in their owning repositories. docs/architecture.md explains the boundary.

Directories

Path Synopsis
Package diagnostic defines PawnKit's shared in-memory diagnostic model.
Package diagnostic defines PawnKit's shared in-memory diagnostic model.
examples
diagnostic command
Command diagnostic demonstrates building a Diagnostic with a related location, a tag, and a safe fix, then validating it.
Command diagnostic demonstrates building a Diagnostic with a related location, a tag, and a safe fix, then validating it.
hash command
Command hash demonstrates building a composite cache key from a file's content hash, a configuration hash, and a tool version.
Command hash demonstrates building a composite cache key from a file's content hash, a configuration hash, and a tool version.
protocol command
Command protocol round-trips a diagnostic across a process boundary.
Command protocol round-trips a diagnostic across a process boundary.
source command
Command source demonstrates the basics of the source package: interning a file, building a snapshot, and converting between byte offsets and line/character positions in UTF-16 (the LSP default).
Command source demonstrates the basics of the source package: interning a file, building a snapshot, and converting between byte offsets and line/character positions in UTF-16 (the LSP default).
textedit command
Command textedit demonstrates computing a single-file edit and a multi-file workspace edit, including the atomic all-or-nothing behaviour of ApplyWorkspaceEdit when one document turns out to be stale.
Command textedit demonstrates computing a single-file edit and a multi-file workspace edit, including the atomic all-or-nothing behaviour of ApplyWorkspaceEdit when one document turns out to be stale.
Package hash provides small, canonical content and configuration hashing helpers for building cache keys.
Package hash provides small, canonical content and configuration hashing helpers for building cache keys.
Package protocol defines the versioned diagnostic JSON format.
Package protocol defines the versioned diagnostic JSON format.
Package source provides shared file identity and position primitives.
Package source provides shared file identity and position primitives.
Package textedit validates and applies version-aware text edits.
Package textedit validates and applies version-aware text edits.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL