pub trait Language: Send + Sync {
Show 21 methods
// Required methods
fn name(&self) -> &'static str;
fn extensions(&self) -> &'static [&'static str];
fn grammar_name(&self) -> &'static str;
// Provided methods
fn as_symbols(&self) -> Option<&dyn LanguageSymbols> { ... }
fn extract_docstring(
&self,
_node: &Node<'_>,
_content: &str,
) -> Option<String> { ... }
fn extract_attributes(
&self,
_node: &Node<'_>,
_content: &str,
) -> Vec<String> { ... }
fn extract_implements(
&self,
_node: &Node<'_>,
_content: &str,
) -> ImplementsInfo { ... }
fn build_signature(&self, node: &Node<'_>, content: &str) -> String { ... }
fn refine_kind(
&self,
node: &Node<'_>,
_content: &str,
tag_kind: SymbolKind,
) -> SymbolKind { ... }
fn extract_imports(&self, _node: &Node<'_>, _content: &str) -> Vec<Import> { ... }
fn format_import(&self, _import: &Import, _names: Option<&[&str]>) -> String { ... }
fn signature_suffix(&self) -> &'static str { ... }
fn get_visibility(&self, _node: &Node<'_>, _content: &str) -> Visibility { ... }
fn is_test_symbol(&self, _symbol: &Symbol) -> bool { ... }
fn test_file_globs(&self) -> &'static [&'static str] { ... }
fn as_embedded(&self) -> Option<&dyn LanguageEmbedded> { ... }
fn container_body<'a>(&self, _node: &'a Node<'a>) -> Option<Node<'a>> { ... }
fn body_has_docstring(&self, _body: &Node<'_>, _content: &str) -> bool { ... }
fn analyze_container_body(
&self,
_body_node: &Node<'_>,
_content: &str,
_inner_indent: &str,
) -> Option<ContainerBody> { ... }
fn extract_module_doc(&self, _src: &str) -> Option<String> { ... }
fn node_name<'a>(
&self,
node: &Node<'_>,
content: &'a str,
) -> Option<&'a str> { ... }
}Expand description
Unified language support trait.
Each language implements this trait to provide:
- Node kind classification
- Symbol extraction (functions, classes, types)
- Import/export parsing
- Complexity analysis nodes
- Visibility detection
- Edit support (container bodies, docstrings)
Required Methods§
Sourcefn extensions(&self) -> &'static [&'static str]
fn extensions(&self) -> &'static [&'static str]
File extensions this language handles (e.g., [“py”, “pyi”, “pyw”])
Sourcefn grammar_name(&self) -> &'static str
fn grammar_name(&self) -> &'static str
Grammar name for arborium (e.g., “python”, “rust”)
Provided Methods§
Sourcefn as_symbols(&self) -> Option<&dyn LanguageSymbols>
fn as_symbols(&self) -> Option<&dyn LanguageSymbols>
Capability query: returns Some(self) if this language has code symbols
(functions, classes, types, etc.). Returns None for config/data languages.
Implement LanguageSymbols and override this to opt in.
Sourcefn extract_docstring(&self, _node: &Node<'_>, _content: &str) -> Option<String>
fn extract_docstring(&self, _node: &Node<'_>, _content: &str) -> Option<String>
Extract the docstring for a definition node. Called by generic extraction for every tagged symbol. Returns None if this language has no docstring convention or the node has no docstring.
Sourcefn extract_attributes(&self, _node: &Node<'_>, _content: &str) -> Vec<String>
fn extract_attributes(&self, _node: &Node<'_>, _content: &str) -> Vec<String>
Extract attributes/annotations/decorators attached to a definition node. Called by generic extraction for every tagged symbol. Returns empty vec if this language has no attribute convention.
Sourcefn extract_implements(&self, _node: &Node<'_>, _content: &str) -> ImplementsInfo
fn extract_implements(&self, _node: &Node<'_>, _content: &str) -> ImplementsInfo
Extract interfaces/traits/superclasses that a container node implements/extends. Called by generic extraction for container nodes only.
Sourcefn build_signature(&self, node: &Node<'_>, content: &str) -> String
fn build_signature(&self, node: &Node<'_>, content: &str) -> String
Build the display signature for a definition node. Default: first line of the node’s source text (trimmed). Override for languages where first-line is incomplete (e.g. Rust, Go, Java).
Sourcefn refine_kind(
&self,
node: &Node<'_>,
_content: &str,
tag_kind: SymbolKind,
) -> SymbolKind
fn refine_kind( &self, node: &Node<'_>, _content: &str, tag_kind: SymbolKind, ) -> SymbolKind
Refine the symbol kind for a tagged node.
Called after tag classification assigns an initial kind (e.g. definition.class → Class).
Languages can override this to return a more specific kind based on the node’s concrete type.
Default: return tag_kind unchanged.
Sourcefn extract_imports(&self, _node: &Node<'_>, _content: &str) -> Vec<Import>
fn extract_imports(&self, _node: &Node<'_>, _content: &str) -> Vec<Import>
Extract imports from an import node (may return multiple)
Sourcefn format_import(&self, _import: &Import, _names: Option<&[&str]>) -> String
fn format_import(&self, _import: &Import, _names: Option<&[&str]>) -> String
Format an import as source code.
If names is Some, only include those names (for multi-import filtering).
If names is None, format the complete import.
Sourcefn signature_suffix(&self) -> &'static str
fn signature_suffix(&self) -> &'static str
Suffix to append to signatures for tree-sitter parsing.
Function signatures are incomplete code fragments that need closing tokens
to parse correctly (e.g., Rust fn foo() needs {}, Lua function foo() needs end).
Returns the suffix to append, or empty string if none needed.
Sourcefn get_visibility(&self, _node: &Node<'_>, _content: &str) -> Visibility
fn get_visibility(&self, _node: &Node<'_>, _content: &str) -> Visibility
Get visibility of a node.
This is a genuine interface method (not just an impl helper): normalize-deps
calls it externally during export detection to decide which tagged nodes are
public. The alternative — calling extract_function/container/type() and
inspecting symbol.visibility — would be correct but unnecessarily heavy
(computes signature, docstring, etc. just to check one field).
Sourcefn is_test_symbol(&self, _symbol: &Symbol) -> bool
fn is_test_symbol(&self, _symbol: &Symbol) -> bool
Check if a symbol is a test (for filtering).
Sourcefn test_file_globs(&self) -> &'static [&'static str]
fn test_file_globs(&self) -> &'static [&'static str]
Glob patterns (relative, using ** wildcards) that identify dedicated test files.
Used to build a GlobSet for fast batch matching.
Return &[] for languages with no dedicated test files (e.g. those using only inline tests).
Sourcefn as_embedded(&self) -> Option<&dyn LanguageEmbedded>
fn as_embedded(&self) -> Option<&dyn LanguageEmbedded>
Capability query: returns Some(self) if this language can contain embedded blocks
in another language (e.g., JS in Vue, CSS in HTML). Returns None for most languages.
Implement LanguageEmbedded and override this to opt in.
Sourcefn container_body<'a>(&self, _node: &'a Node<'a>) -> Option<Node<'a>>
fn container_body<'a>(&self, _node: &'a Node<'a>) -> Option<Node<'a>>
Find the body node of a container (for prepend/append)
Sourcefn body_has_docstring(&self, _body: &Node<'_>, _content: &str) -> bool
fn body_has_docstring(&self, _body: &Node<'_>, _content: &str) -> bool
Detect if first child of body is a docstring
Sourcefn analyze_container_body(
&self,
_body_node: &Node<'_>,
_content: &str,
_inner_indent: &str,
) -> Option<ContainerBody>
fn analyze_container_body( &self, _body_node: &Node<'_>, _content: &str, _inner_indent: &str, ) -> Option<ContainerBody>
Analyze a container body node and return the editable byte range.
body_node is the node returned by container_body.
Returns None if this language doesn’t support container body editing.
Sourcefn extract_module_doc(&self, _src: &str) -> Option<String>
fn extract_module_doc(&self, _src: &str) -> Option<String>
Extract the module-level doc comment from raw file source.
Called when viewing a file (not a specific symbol) to populate ViewReport.summary.
Returns None if this language has no module-doc convention or the file has none.
Conventions by language:
- Rust: leading
//!inner-doc comment lines - Python: first statement is a string literal (
"""...""") - Go: line comment(s) immediately before
package foo - JavaScript/TypeScript: leading
/** ... */block comment at top of file - Ruby: leading
#comment block (ignoring# frozen_string_literallines)