Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarrus1 committed Sep 8, 2023
1 parent 8f460dc commit 6caaa47
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
7 changes: 4 additions & 3 deletions crates/sourcepawn_lsp/src/server/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ impl Server {
quiescent: !self.indexing,
message: None,
});
self.report_progress("Indexing", Progress::Begin, None, None, None);

self.parse_directories();
self.report_progress("Indexing", Progress::End, None, None, None);

self.report_progress("Resolving roots", Progress::Begin, None, None, None);
let projects = self.store.write().load_projects_graph();
Expand Down Expand Up @@ -69,7 +68,8 @@ impl Server {
Ok(())
}

fn parse_directories(&mut self) {
pub(crate) fn parse_directories(&mut self) {
self.report_progress("Indexing", Progress::Begin, None, None, None);
let store = self.store.read();
let folders = store.folders();
drop(store);
Expand All @@ -95,6 +95,7 @@ impl Server {
);
self.store.write().discover_documents(path);
}
self.report_progress("Indexing", Progress::End, None, None, None);
}

/// Check if a [uri](Url) is know or not. If it is not, scan its parent folder and analyze all the documents that
Expand Down
43 changes: 29 additions & 14 deletions crates/store/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ impl Store {
let mut graph = Graph::default();

for document in self.documents.values() {
let source = Node {
file_id: document.file_id,
extension: document.extension(),
};
graph.nodes.insert(source.clone());
for (file_id, extension) in self.get_include_ids_from_document(document) {
let source = Node {
file_id: document.file_id,
extension: document.extension(),
};
let target = Node { file_id, extension };
graph.edges.insert(Edge {
source: source.clone(),
target: target.clone(),
});
graph.nodes.insert(source);
graph.nodes.insert(target);
}
}
Expand Down Expand Up @@ -174,18 +174,33 @@ impl Graph {
adj_targets
}

pub fn find_roots(&self) -> Vec<&Node> {
let mut adj_sources: FxHashMap<Node, FxHashSet<Node>> = FxHashMap::default();
pub fn find_roots(&self) -> Vec<Node> {
let mut adj_map: FxHashMap<Node, (u32, u32)> = FxHashMap::default();
for edge in self.edges.iter() {
adj_sources
adj_map
.entry(edge.source.clone())
.or_insert_with(|| (0, 0))
.1 += 1;
adj_map
.entry(edge.target.clone())
.or_insert_with(FxHashSet::default)
.insert(edge.source.clone());
.or_insert_with(|| (0, 0))
.0 += 1;
}
for node in self.nodes.iter() {
adj_map.entry(node.clone()).or_insert_with(|| (0, 0));
}
self.nodes
adj_map
.iter()
.filter(|node| !adj_sources.contains_key(node))
.collect::<Vec<&Node>>()
.filter_map(|(node, (nb_source, nb_target))| {
if *nb_target != 0 {
Some(node.clone())
} else if *nb_source == 0 {

Check failure on line 197 in crates/store/src/graph.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

this `if` has identical blocks

error: this `if` has identical blocks --> crates/store/src/graph.rs:195:36 | 195 | if *nb_target != 0 { | ____________________________________^ 196 | | Some(node.clone()) 197 | | } else if *nb_source == 0 { | |_________________^ | note: same as this --> crates/store/src/graph.rs:197:43 | 197 | } else if *nb_source == 0 { | ___________________________________________^ 198 | | Some(node.clone()) 199 | | } else { | |_________________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else = note: `#[deny(clippy::if_same_then_else)]` on by default
Some(node.clone())
} else {
None
}
})
.collect::<Vec<Node>>()
}

/// Get the root of the [subgraph](SubGraph) from a given [file_id](FileId).
Expand Down Expand Up @@ -247,7 +262,7 @@ impl Graph {
let mut visited = FxHashSet::default();
let mut nodes = vec![];
let mut edges = vec![];
dfs(root, &adj_targets, &mut visited, &mut nodes, &mut edges);
dfs(&root, &adj_targets, &mut visited, &mut nodes, &mut edges);
visited.insert(root.clone());
subgraphs.push(SubGraph {
root: root.clone(),
Expand Down

0 comments on commit 6caaa47

Please sign in to comment.