Language Support

Diff Guardian uses WASM-compiled Tree-Sitter grammars to parse source code. Each language has a dedicated translator module that extracts structured signatures from the syntax tree.


Supported languages

LanguageExtensionsGrammarTranslator
TypeScript.ts, .tsxtree-sitter-typescripttranslators/typescript.ts
JavaScript.js, .jsxtree-sitter-javascripttranslators/typescript.ts
Python.pytree-sitter-pythontranslators/python.ts
Go.gotree-sitter-gotranslators/go.ts
Java.javatree-sitter-javatranslators/java.ts
Rust.rstree-sitter-rusttranslators/rust.ts

What gets extracted

Every translator extracts the same four signature types from the syntax tree, regardless of language:

FunctionSignature

  • Name, parameters (name, type, optional flag, default value, rest flag)
  • Return type, async modifier, visibility (public/protected/private)
  • Generic type parameters with constraints
  • Constructor detection, static detection, export status

InterfaceSignature

  • Name, properties (name, type, optional flag)
  • Generic type parameters

EnumSignature

  • Name, members (name, optional value)

TypeAliasSignature

  • Name, the full type expression, generics

Language-specific notes

TypeScript and JavaScript

TypeScript and JavaScript share the same translator module. The TypeScript grammar handles JSX/TSX syntax natively. JavaScript files are parsed with the TypeScript grammar since it is a superset.

Extracted constructs: function declarations, class methods, arrow functions assigned to const/let,interface, type aliases, and enum.

Python

Python functions are identified by def statements. Type annotations (PEP 484+) are extracted when present. Since Python does not have native interfaces or enums at the language level, only function signatures and class methods are analyzed. Dataclasses and TypedDict are treated as interfaces when decorated.

Go

Go functions and methods are extracted from func andfunc (receiver) name syntax. Interfaces are extracted fromtype Name interface blocks. Structs with exported fields are treated as interface-like contracts. Enums are inferred fromconst blocks with iota.

Java

Java methods, constructors, and interfaces are fully supported. The translator extracts visibility modifiers, generics, and static flags. Enums are extracted from enum declarations with their constant values.

Rust

Rust functions (fn), trait definitions (trait), and enums (enum) are supported. Visibility is determined by the pub modifier. Generic lifetime and type parameters are extracted. The translator handles impl blocks for method extraction.

Adding a new language

To add support for a new language, you need:

  1. Install the Tree-Sitter grammar: npm install tree-sitter-langname
  2. Copy the WASM file to the grammars/ directory
  3. Add a translator module in src/parsers/translators/
  4. Register the extension mapping in src/core/constants.ts
  5. Add a case to the ASTMapper.dispatch() switch