pub struct GoDependencyExtractor { /* private fields */ }Expand description
Go dependency extractor with tree-sitter query-based import extraction.
Supports go.mod module path resolution and vendor directory mode for mapping import paths to local file system paths.
§Examples
use thread_flow::incremental::extractors::go::GoDependencyExtractor;
use std::path::Path;
let extractor = GoDependencyExtractor::new(Some("github.com/user/repo".to_string()));
let imports = extractor.extract_imports(source, Path::new("main.go")).unwrap();Implementations§
Source§impl GoDependencyExtractor
impl GoDependencyExtractor
Sourcepub fn new(module_path: Option<String>) -> Self
pub fn new(module_path: Option<String>) -> Self
Create a new extractor with optional go.mod module path.
When module_path is provided, imports matching the module prefix
are resolved to local paths relative to the module root.
Sourcepub fn with_vendor(module_path: Option<String>, vendor_mode: bool) -> Self
pub fn with_vendor(module_path: Option<String>, vendor_mode: bool) -> Self
Create a new extractor with vendor directory support.
When vendor_mode is true, external imports are resolved to the
vendor/ directory instead of returning an error.
Sourcepub fn extract_imports(
&self,
source: &str,
_file_path: &Path,
) -> Result<Vec<ImportInfo>, ExtractionError>
pub fn extract_imports( &self, source: &str, _file_path: &Path, ) -> Result<Vec<ImportInfo>, ExtractionError>
Extract all import statements from a Go source file.
Parses the source using tree-sitter and walks import_declaration nodes
to collect import paths, aliases, and import variants (dot, blank).
§Errors
Returns ExtractionError::ParseError if tree-sitter cannot parse the source.
Sourcepub fn resolve_import_path(
&self,
_source_file: &Path,
import_path: &str,
) -> Result<PathBuf, ExtractionError>
pub fn resolve_import_path( &self, _source_file: &Path, import_path: &str, ) -> Result<PathBuf, ExtractionError>
Resolve a Go import path to a local file path.
Resolution strategy:
- If the import matches the module path prefix, strip it to get a relative path.
- If vendor mode is enabled, external imports resolve to
vendor/<import_path>. - Standard library and unresolvable external imports return an error.
§Errors
Returns ExtractionError::UnresolvedImport if the import cannot be mapped
to a local file path.
Sourcepub fn extract_dependency_edges(
&self,
source: &str,
file_path: &Path,
) -> Result<Vec<DependencyEdge>, ExtractionError>
pub fn extract_dependency_edges( &self, source: &str, file_path: &Path, ) -> Result<Vec<DependencyEdge>, ExtractionError>
Extract DependencyEdge values from a Go source file.
Combines import extraction with path resolution to produce edges suitable for the incremental dependency graph. Only module-internal and vendor-resolvable imports produce edges; standard library and unresolvable external imports are silently skipped.
§Errors
Returns an error if the source file cannot be parsed.
Trait Implementations§
Source§impl Clone for GoDependencyExtractor
impl Clone for GoDependencyExtractor
Source§fn clone(&self) -> GoDependencyExtractor
fn clone(&self) -> GoDependencyExtractor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for GoDependencyExtractor
impl RefUnwindSafe for GoDependencyExtractor
impl Send for GoDependencyExtractor
impl Sync for GoDependencyExtractor
impl Unpin for GoDependencyExtractor
impl UnsafeUnpin for GoDependencyExtractor
impl UnwindSafe for GoDependencyExtractor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more