pub trait Language: Send + Sync {
Show 48 methods
// Required methods
fn name(&self) -> &'static str;
fn extensions(&self) -> &'static [&'static str];
fn grammar_name(&self) -> &'static str;
fn has_symbols(&self) -> bool;
fn container_kinds(&self) -> &'static [&'static str];
fn function_kinds(&self) -> &'static [&'static str];
fn type_kinds(&self) -> &'static [&'static str];
fn import_kinds(&self) -> &'static [&'static str];
fn public_symbol_kinds(&self) -> &'static [&'static str];
fn visibility_mechanism(&self) -> VisibilityMechanism;
fn extract_function(
&self,
node: &Node<'_>,
content: &str,
in_container: bool,
) -> Option<Symbol>;
fn extract_container(
&self,
node: &Node<'_>,
content: &str,
) -> Option<Symbol>;
fn extract_type(&self, node: &Node<'_>, content: &str) -> Option<Symbol>;
fn extract_docstring(
&self,
node: &Node<'_>,
content: &str,
) -> Option<String>;
fn extract_attributes(&self, node: &Node<'_>, content: &str) -> Vec<String>;
fn extract_imports(&self, node: &Node<'_>, content: &str) -> Vec<Import>;
fn format_import(&self, import: &Import, names: Option<&[&str]>) -> String;
fn extract_public_symbols(
&self,
node: &Node<'_>,
content: &str,
) -> Vec<Export>;
fn scope_creating_kinds(&self) -> &'static [&'static str];
fn control_flow_kinds(&self) -> &'static [&'static str];
fn complexity_nodes(&self) -> &'static [&'static str];
fn nesting_nodes(&self) -> &'static [&'static str];
fn signature_suffix(&self) -> &'static str;
fn is_public(&self, node: &Node<'_>, content: &str) -> bool;
fn get_visibility(&self, node: &Node<'_>, content: &str) -> Visibility;
fn is_test_symbol(&self, symbol: &Symbol) -> bool;
fn embedded_content(
&self,
node: &Node<'_>,
content: &str,
) -> Option<EmbeddedBlock>;
fn container_body<'a>(&self, node: &'a Node<'a>) -> Option<Node<'a>>;
fn body_has_docstring(&self, body: &Node<'_>, content: &str) -> bool;
fn node_name<'a>(
&self,
node: &Node<'_>,
content: &'a str,
) -> Option<&'a str>;
fn file_path_to_module_name(&self, path: &Path) -> Option<String>;
fn module_name_to_paths(&self, module: &str) -> Vec<String>;
fn lang_key(&self) -> &'static str;
fn resolve_local_import(
&self,
import_name: &str,
current_file: &Path,
project_root: &Path,
) -> Option<PathBuf>;
fn resolve_external_import(
&self,
import_name: &str,
project_root: &Path,
) -> Option<ResolvedPackage>;
fn is_stdlib_import(&self, import_name: &str, project_root: &Path) -> bool;
fn get_version(&self, project_root: &Path) -> Option<String>;
fn find_package_cache(&self, project_root: &Path) -> Option<PathBuf>;
fn indexable_extensions(&self) -> &'static [&'static str];
fn find_stdlib(&self, project_root: &Path) -> Option<PathBuf>;
fn should_skip_package_entry(&self, name: &str, is_dir: bool) -> bool;
fn package_module_name(&self, entry_name: &str) -> String;
fn package_sources(&self, project_root: &Path) -> Vec<PackageSource>;
fn discover_packages(
&self,
source: &PackageSource,
) -> Vec<(String, PathBuf)>;
fn find_package_entry(&self, path: &Path) -> Option<PathBuf>;
// Provided methods
fn discover_flat_packages(
&self,
source_path: &Path,
) -> Vec<(String, PathBuf)> { ... }
fn discover_recursive_packages(
&self,
base_path: &Path,
current_path: &Path,
) -> Vec<(String, PathBuf)> { ... }
fn discover_npm_scoped_packages(
&self,
source_path: &Path,
) -> Vec<(String, PathBuf)> { ... }
}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”)
Sourcefn has_symbols(&self) -> bool
fn has_symbols(&self) -> bool
Whether this language has code symbols (functions, classes, etc.)
Sourcefn container_kinds(&self) -> &'static [&'static str]
fn container_kinds(&self) -> &'static [&'static str]
Container nodes that can hold methods (class, impl, module)
Sourcefn function_kinds(&self) -> &'static [&'static str]
fn function_kinds(&self) -> &'static [&'static str]
Function/method definition nodes
Sourcefn type_kinds(&self) -> &'static [&'static str]
fn type_kinds(&self) -> &'static [&'static str]
Type definition nodes (struct, enum, interface, type alias)
Sourcefn import_kinds(&self) -> &'static [&'static str]
fn import_kinds(&self) -> &'static [&'static str]
Import statement nodes
Sourcefn public_symbol_kinds(&self) -> &'static [&'static str]
fn public_symbol_kinds(&self) -> &'static [&'static str]
AST node kinds that may contain publicly visible symbols. For JS/TS: export_statement nodes. For Go/Java/Python: function/class/type declaration nodes. The extract_public_symbols() method filters by actual visibility.
Sourcefn visibility_mechanism(&self) -> VisibilityMechanism
fn visibility_mechanism(&self) -> VisibilityMechanism
How this language determines symbol visibility
Sourcefn extract_function(
&self,
node: &Node<'_>,
content: &str,
in_container: bool,
) -> Option<Symbol>
fn extract_function( &self, node: &Node<'_>, content: &str, in_container: bool, ) -> Option<Symbol>
Extract symbol from a function/method node
Sourcefn extract_container(&self, node: &Node<'_>, content: &str) -> Option<Symbol>
fn extract_container(&self, node: &Node<'_>, content: &str) -> Option<Symbol>
Extract symbol from a container node (class, impl, module)
Sourcefn extract_type(&self, node: &Node<'_>, content: &str) -> Option<Symbol>
fn extract_type(&self, node: &Node<'_>, content: &str) -> Option<Symbol>
Extract symbol from a type definition node
Sourcefn extract_docstring(&self, node: &Node<'_>, content: &str) -> Option<String>
fn extract_docstring(&self, node: &Node<'_>, content: &str) -> Option<String>
Extract docstring/doc comment for a node
Sourcefn extract_attributes(&self, node: &Node<'_>, content: &str) -> Vec<String>
fn extract_attributes(&self, node: &Node<'_>, content: &str) -> Vec<String>
Extract attributes/decorators for a node (e.g., #test, @Test)
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 extract_public_symbols(&self, node: &Node<'_>, content: &str) -> Vec<Export>
fn extract_public_symbols(&self, node: &Node<'_>, content: &str) -> Vec<Export>
Extract public symbols from a node. The node is one of the kinds from public_symbol_kinds(). For JS/TS: extracts exported names from export statements. For Go/Java/Python: checks visibility and returns public symbols.
Sourcefn scope_creating_kinds(&self) -> &'static [&'static str]
fn scope_creating_kinds(&self) -> &'static [&'static str]
Nodes that create new variable scopes (for scope analysis) Includes: loops, blocks, comprehensions, lambdas, with statements Note: Functions and containers (from function_kinds/container_kinds) also create scopes
Sourcefn control_flow_kinds(&self) -> &'static [&'static str]
fn control_flow_kinds(&self) -> &'static [&'static str]
Nodes that affect control flow (for CFG analysis) Includes: if, for, while, return, break, continue, try, match
Sourcefn complexity_nodes(&self) -> &'static [&'static str]
fn complexity_nodes(&self) -> &'static [&'static str]
Nodes that increase cyclomatic complexity
Sourcefn nesting_nodes(&self) -> &'static [&'static str]
fn nesting_nodes(&self) -> &'static [&'static str]
Nodes that indicate nesting depth
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
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). Each language must implement this - test conventions are language-specific.
Sourcefn embedded_content(
&self,
node: &Node<'_>,
content: &str,
) -> Option<EmbeddedBlock>
fn embedded_content( &self, node: &Node<'_>, content: &str, ) -> Option<EmbeddedBlock>
Extract embedded content from a node (e.g., JS/CSS in Vue/HTML). Returns None for nodes that don’t contain embedded code in another language.
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 node_name<'a>(&self, node: &Node<'_>, content: &'a str) -> Option<&'a str>
fn node_name<'a>(&self, node: &Node<'_>, content: &'a str) -> Option<&'a str>
Get the name of a node (typically via “name” field)
Sourcefn file_path_to_module_name(&self, path: &Path) -> Option<String>
fn file_path_to_module_name(&self, path: &Path) -> Option<String>
Convert a file path to a module name for this language. Used to find “importers” - files that import a given file. Returns None for languages without module systems or where not applicable.
Sourcefn module_name_to_paths(&self, module: &str) -> Vec<String>
fn module_name_to_paths(&self, module: &str) -> Vec<String>
Convert a module name to candidate file paths (inverse of file_path_to_module_name).
Returns relative paths that could contain the module.
Used for wildcard import resolution (e.g., from foo import *).
Sourcefn lang_key(&self) -> &'static str
fn lang_key(&self) -> &'static str
Language key for package index cache (e.g., “python”, “go”, “js”).
Sourcefn resolve_local_import(
&self,
import_name: &str,
current_file: &Path,
project_root: &Path,
) -> Option<PathBuf>
fn resolve_local_import( &self, import_name: &str, current_file: &Path, project_root: &Path, ) -> Option<PathBuf>
Resolve a local import within the project.
Handles project-relative imports (e.g., from . import foo, crate::,
./module, relative includes).
Sourcefn resolve_external_import(
&self,
import_name: &str,
project_root: &Path,
) -> Option<ResolvedPackage>
fn resolve_external_import( &self, import_name: &str, project_root: &Path, ) -> Option<ResolvedPackage>
Resolve an external import to its source location.
Returns the path to stdlib or installed packages.
Sourcefn is_stdlib_import(&self, import_name: &str, project_root: &Path) -> bool
fn is_stdlib_import(&self, import_name: &str, project_root: &Path) -> bool
Check if an import is from the standard library.
Sourcefn get_version(&self, project_root: &Path) -> Option<String>
fn get_version(&self, project_root: &Path) -> Option<String>
Get the language/runtime version (for package index versioning).
Sourcefn find_package_cache(&self, project_root: &Path) -> Option<PathBuf>
fn find_package_cache(&self, project_root: &Path) -> Option<PathBuf>
Find package cache/installation directory.
Sourcefn indexable_extensions(&self) -> &'static [&'static str]
fn indexable_extensions(&self) -> &'static [&'static str]
File extensions to index when caching a package.
Sourcefn find_stdlib(&self, project_root: &Path) -> Option<PathBuf>
fn find_stdlib(&self, project_root: &Path) -> Option<PathBuf>
Find standard library directory (if applicable). Returns None for languages without a separate stdlib to index.
Sourcefn should_skip_package_entry(&self, name: &str, is_dir: bool) -> bool
fn should_skip_package_entry(&self, name: &str, is_dir: bool) -> bool
Should this entry be skipped when indexing packages?
Called for each file/directory in package directories.
Use helper functions skip_dotfiles() and has_extension(name, self.indexable_extensions()) for common checks.
Sourcefn package_module_name(&self, entry_name: &str) -> String
fn package_module_name(&self, entry_name: &str) -> String
Get the module/package name from a directory entry name.
Sourcefn package_sources(&self, project_root: &Path) -> Vec<PackageSource>
fn package_sources(&self, project_root: &Path) -> Vec<PackageSource>
Return package sources to index for this language. Each source describes a directory containing packages.
Sourcefn discover_packages(&self, source: &PackageSource) -> Vec<(String, PathBuf)>
fn discover_packages(&self, source: &PackageSource) -> Vec<(String, PathBuf)>
Discover packages in a source directory. Returns (package_name, path) pairs for all packages found. Use provided helpers: discover_flat_packages, discover_recursive_packages, discover_npm_scoped_packages.
Sourcefn find_package_entry(&self, path: &Path) -> Option<PathBuf>
fn find_package_entry(&self, path: &Path) -> Option<PathBuf>
Find the entry point file for a package path. If path is a file, returns it directly. If path is a directory, looks for language-specific entry points.
Provided Methods§
Sourcefn discover_flat_packages(&self, source_path: &Path) -> Vec<(String, PathBuf)>
fn discover_flat_packages(&self, source_path: &Path) -> Vec<(String, PathBuf)>
Discover packages in a flat directory (each entry is a package).