How to use cmd/inspector as an example consumer of pkg/jsparse and when to prefer pkg/inspectorapi
cmd/inspector is an example application that demonstrates how to consume the public pkg/jsparse APIs in a real terminal UX. Treat this command as a reference implementation, not as the reusable API layer itself.
For production adapters and multi-surface integrations (CLI + REST + LSP), prefer orchestrating through pkg/inspectorapi and keep pkg/jsparse for lower-level parser/index operations.
Use this guide when you want to:
pkg/jsparse is wired in a real toolBuild and run against a JavaScript file:
go build ./cmd/inspector
./inspector path/to/file.js
Run directly without producing a local binary:
go run ./cmd/inspector ./examples/inspector/inspector-test.js
cmd/inspector/main.go: parses input file, builds jsparse analysis, launches TUI modelcmd/inspector/app/: UI and interaction logic onlypkg/jsparse: parser/index/resolution/completion frameworkpkg/inspectorapi: user-facing orchestration layer for adapter-ready workflowsThis split makes it straightforward to replace the TUI while keeping analysis behavior stable.
Core flows in the example:
Because completion and resolution are delegated to pkg/jsparse, you can replicate these flows in non-TUI tools.
A minimal non-TUI consumer usually needs only this flow:
res := jsparse.Analyze(filename, source, nil)
if res.ParseErr != nil {
// handle diagnostics
}
ts, _ := jsparse.NewTSParser()
defer ts.Close()
root := ts.Parse([]byte(source))
candidates := res.CompleteAt(root, row, col)
From there, choose your own output surface (CLI JSON, HTTP API, LSP, logs). If you are building a full adapter rather than a focused parser experiment, route the workflow through pkg/inspectorapi.
Before publishing tooling built on this pattern:
GOWORK=off go test ./pkg/jsparse -count=1GOWORK=off go test ./cmd/inspector/... -count=1GOWORK=off go build ./cmd/inspectorOptional full-suite check:
GOWORK=off go test ./... -count=1
| Problem | Cause | Solution |
|---|---|---|
| Command exits with parse error banner | JS source contains syntax errors | Fix source; partial AST behavior is expected on some failures |
| Completion popup is empty | Cursor context not recognized as completion site | Try cursor position and one-char-back strategy |
| Go-to-definition does not resolve | Symbol is property access rather than lexical binding | Confirm identifier kind and resolution scope |
| Build/test fails only in workspace | Workspace modules masking deps | Repeat checks with GOWORK=off |
glaze help jsparse-framework-referenceglaze help inspectorapi-hybrid-service-guidegoja-repl help repl-usageglaze help creating-modules