Class: Rubino::Compression::TreeSitterCodeSkeleton

Inherits:
LineSkeleton
  • Object
show all
Defined in:
lib/rubino/compression/tree_sitter_code_skeleton.rb

Overview

A LineSkeleton backed by the ‘tree_sitter_language_pack` gem’s HIGH-LEVEL ‘process` API — the shared base for the JS/TS/TSX strategies. Each import, comment, class and signature is kept VERBATIM; only LARGE function/method BODIES are elided behind a pointer (see LineSkeleton for the pointer format and the drill-in invariant).

We use the gem’s ‘process` → `result.structure` (a HIERARCHICAL tree of StructureItem) rather than the low-level `Parser#parse`/raw-node API: the latter’s native ‘parse` is NOT registered in the shipped precompiled build (it silently no-ops), so it would NEVER compress. `process` is the path verified to work at runtime.

NO-OP FALLBACK (the user’s hard rule): the gem is an OPTIONAL development dependency. If it is absent, the grammar can’t be fetched (first-use download offline), or ‘process` raises for any reason, #collect_elisions returns nil and the caller sends the ORIGINAL output unchanged. There is no regex/approximation anywhere — when tree-sitter can’t run, we do not guess.

Constant Summary collapse

CONTAINER_KINDS =

StructureItem kinds that are STRUCTURE, not an elidable body: we never elide them (their brace body holds only nested signatures/members) and we recurse INTO them so their members’ signatures stay verbatim. Everything else with a brace body is a function-like body and is a candidate.

%w[Class Interface Namespace Module Enum Struct].freeze

Instance Method Summary collapse

Methods inherited from LineSkeleton

#build, #initialize

Constructor Details

This class inherits a constructor from Rubino::Compression::LineSkeleton

Instance Method Details

#comment_prefixObject

The pointer reads as a ‘//` line comment in JS/TS source.



30
31
32
# File 'lib/rubino/compression/tree_sitter_code_skeleton.rb', line 30

def comment_prefix
  "//"
end

#grammar_nameObject

Subclass hook: the grammar name passed to ProcessConfig (“javascript”/“typescript”/“tsx”).

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/rubino/compression/tree_sitter_code_skeleton.rb', line 36

def grammar_name
  raise NotImplementedError, "#{self.class} must implement #grammar_name"
end