Inspector Example User Guide

How to use cmd/inspector as an example consumer of pkg/jsparse and when to prefer pkg/inspectorapi

Sections

Terminology & Glossary
πŸ“– Documentation
Navigation
31 sectionsv0.1
πŸ“„ Inspector Example User Guide β€” glaze help inspector-example-user-guide
inspector-example-user-guide

Inspector Example User Guide

How to use cmd/inspector as an example consumer of pkg/jsparse and when to prefer pkg/inspectorapi

Tutorialinspectorjavascriptastcompletiontoolinginspector

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.

When to Use This Guide

Use this guide when you want to:

  • run and explore the inspector example
  • understand how pkg/jsparse is wired in a real tool
  • copy integration patterns for your own developer tooling

Quick Start

Build 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

How the Command Is Structured

  • cmd/inspector/main.go: parses input file, builds jsparse analysis, launches TUI model
  • cmd/inspector/app/: UI and interaction logic only
  • pkg/jsparse: parser/index/resolution/completion framework
  • pkg/inspectorapi: user-facing orchestration layer for adapter-ready workflows

This split makes it straightforward to replace the TUI while keeping analysis behavior stable.

Key Interaction Model

Core flows in the example:

  • Source cursor movement -> AST node selection sync
  • Tree selection movement -> source highlight sync
  • Drawer input -> completion context extraction -> candidate resolution
  • Go-to-definition/highlight-usages -> resolution graph lookups

Because completion and resolution are delegated to pkg/jsparse, you can replicate these flows in non-TUI tools.

Reusing the Pattern in Other 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.

Validation Checklist

Before publishing tooling built on this pattern:

  1. GOWORK=off go test ./pkg/jsparse -count=1
  2. GOWORK=off go test ./cmd/inspector/... -count=1
  3. GOWORK=off go build ./cmd/inspector

Optional full-suite check:

GOWORK=off go test ./... -count=1

Troubleshooting

ProblemCauseSolution
Command exits with parse error bannerJS source contains syntax errorsFix source; partial AST behavior is expected on some failures
Completion popup is emptyCursor context not recognized as completion siteTry cursor position and one-char-back strategy
Go-to-definition does not resolveSymbol is property access rather than lexical bindingConfirm identifier kind and resolution scope
Build/test fails only in workspaceWorkspace modules masking depsRepeat checks with GOWORK=off

See Also

  • glaze help jsparse-framework-reference
  • glaze help inspectorapi-hybrid-service-guide
  • goja-repl help repl-usage
  • glaze help creating-modules