Weftmap
Documentation

Adding a language

The architecture is pluggable: a language is a Tree-sitter grammar plus a handful of queries. Adding one is a few steps.

1. Add the grammar

Copy tree-sitter-<lang>.wasm into public/wasm/. Many ship in the tree-sitter-wasms package; otherwise build it from the grammar with the Tree-sitter CLI.

2. Create the analyzer

Add src/lib/analysis/analyzers/<lang>.ts with a LangSpec: two queries (function definitions and calls) plus the node types that count as a function scope.

src/lib/analysis/analyzers/go.ts
const spec: LangSpec = {
  language: "go",
  wasm: "tree-sitter-go.wasm",
  funcDefQuery: "[(function_declaration) (method_declaration)] @def",
  callQuery: `
    (call_expression function: (identifier) @callee)
    (call_expression function: (selector_expression field: (field_identifier) @callee))
  `,
  importQuery: "(import_spec path: (interpreted_string_literal) @mod)",
  funcDefTypes: new Set(["function_declaration", "method_declaration"]),
  resolveModule: () => null,
};

export const goAnalyzer: LanguageAnalyzer = {
  language: spec.language,
  analyzeProject: (files) => analyzeProjectWith(spec, files),
};

For languages with classes, add classQuery, classNodeTypes andclassBases. For a different diagram type (like SQL โ†’ ER), implementLanguageAnalyzer directly instead of using analyzeProjectWith.

3. Register it

Add one line to src/lib/analysis/registry.ts.

4. Wire the UI

  • EXT and PROJECT_EXTS in route.ts and CodeWorkspace.tsx (extensions).
  • The language selector and a sample in CodeWorkspace.tsx.

5. Add a test

A snippet โ†’ expected nodes/edges check in analyzers.test.ts.

Use go.ts and rust.ts (class-less) or python.ts (with classes) as a template, and read CONTRIBUTING.md. New-language PRs are very welcome!