Crates.io | gossiphs |
lib.rs | gossiphs |
version | 0.3.2 |
source | src |
created_at | 2024-04-19 13:38:29.257594 |
updated_at | 2024-05-08 16:06:17.97451 |
description | A Rust lib for general code file relationship analysis. Based on tree-sitter and git analysis. |
homepage | https://github.com/williamfzc/gossiphs |
repository | |
max_upload_size | |
id | 1213697 |
size | 112,552 |
An experimental Rust library for general code file relationship analysis. Based on tree-sitter and git analysis.
Code navigation is a fascinating subject that plays a pivotal role in various domains, such as:
In the past, I endeavored to apply LSP/LSIF technologies and techniques like Github's Stack-Graphs to impact analysis, encountering different challenges along the way. For our needs, a method akin to Stack-Graphs aligns most closely with our expectations. However, the challenges are evident: it requires crafting highly language-specific rules, which is a considerable investment for us, given that we do not require such high precision data.
We attempt to make some trade-offs on the challenges currently faced by stack-graphs to achieve our expected goals to a certain extent:
Gossiphs constructs a graph that interconnects symbols of definitions and references.
Unlike stack-graphs, we have omitted the highly complex scope analysis and instead opted to refine our edges using commit histories. This approach significantly reduces the complexity of rule writing, as the rules only need to specify which types of symbols should be exported or imported for each file.
While there is undoubtedly a trade-off in precision, the benefits are clear:
The project is still in the experimental stage.
You can find pre-compiled files for your platform
on Our Release Page. After extraction, you can use gossiphs --help
to find the corresponding help.
For example, you can use this command to generate an obsidian vault:
gossiphs obsidian --project-path . --vault-dir ./target_vault
and get a code relation graph:
Please refer to examples for usage.
fn main() {
let config = GraphConfig::default();
let g = Graph::from(config);
// done! just try it
let all_files = g.files();
for file in &all_files {
// related file search
let related_files = g.related_files(file);
for each_related in &related_files {
println!("{} -> {}: {}", file, each_related.name, each_related.score);
}
// file details
if !related_files.is_empty() {
let random_file = related_files[0].name.clone();
let meta = g.file_metadata(&random_file);
println!("symbols in {}: {:?}", random_file, meta.symbols.len());
// and query the symbol infos
}
}
}
Starting a local server similar to LSP for other clients to use may be a reasonable approach, which is what we are currently doing.
./gossiphs server --project-path ./your/project --strict
API desc can be found here.
The method we use to demonstrate accuracy is to compare the results with those of LSP/LSIF. It must be admitted that static inference is almost impossible to obtain all reference relationships like LSP, but in strict mode, our calculation accuracy is still quite considerable. In normal mode, you can decide whether to adopt the relationship based on the weight returned.
Repo | Precision (Strict Mode) | Graph Generated Time |
---|---|---|
https://github.com/williamfzc/srctx | 80/80 = 100 % | 83.139791ms |
https://github.com/gin-gonic/gin | 160/167 = 95.80838 % | 310.6805ms |
The project is still in a very early and experimental stage. If you are interested, please leave your thoughts through an issue. In the short term, we hope to add support for more languages, which is not too complicated.