Skip to content

feat: extract access modifiers and decorators via highlights.scm queries #525

Description

@vitali87

Background

Tree-sitter's highlights.scm query files tag every token in source code with a semantic category — keywords, operators, literals, and crucially, access modifiers and decorators/attributes. Every tree-sitter language package ships highlights.scm with full coverage.

Problem

Currently only Java extracts access modifiers and annotations as node properties (via custom logic in parsers/java/utils.py). For the other 11 languages:

  • We can't answer "what are the public methods of this class?"
  • We can't filter by visibility (pub, private, protected, static)
  • We can't find decorated functions ("show all @pytest.mark.parametrize tests", "find all #[test] functions")
  • LLM queries about code visibility/access patterns produce incomplete answers

The information exists in the parse tree but we don't extract it.

Approach

Vendor highlights.scm files for all 12 languages (already available in all pip packages) and extract modifier/decorator captures as node properties.

What highlights.scm captures (relevant subset)

  • @keyword / @keyword.modifierpublic, private, protected, static, abstract, final, async, pub, pub(crate)
  • @attribute / @function.decorator@decorator (Python), #[attr] (Rust), [[attr]] (C++), @Annotation (Java)
  • @type.qualifierconst, volatile, mutable, readonly

Example patterns:

; Python
(decorator "@" @attribute)

; Rust  
(attribute_item) @attribute

; Java
(modifiers) @keyword.modifier
(marker_annotation) @attribute

; TypeScript
(accessibility_modifier) @keyword.modifier

Implementation

  1. Create codebase_rag/queries/highlights/ directory with .scm files per language (or load from pip packages directly since all 12 have them)
  2. During node property building (in function_ingest.py and class_ingest/mixin.py), run highlights query on the node's source range
  3. Collect @keyword.modifier and @attribute captures that fall within the node's declaration
  4. Store as node properties: modifiers: list[str] and decorators: list[str]
  5. Extend Java's existing MethodModifiersAndAnnotations pattern to all languages
  6. Add tests per language verifying modifier and decorator extraction

Property schema additions

Function/Method nodes:
  modifiers: ["public", "static", "async"]    # access and behavior modifiers
  decorators: ["@property", "#[test]"]        # decorators/attributes

Class nodes:
  modifiers: ["abstract", "final", "pub"]
  decorators: ["@dataclass", "#[derive(Debug)]"]

Languages

All 12: Python, JavaScript, TypeScript, Rust, Java, C, C++, Go, Lua, Scala, PHP, C#

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions