rubydex 0.1.0.beta1-x86_64-linux → 0.1.0.beta2-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/rubydex/declaration.c +146 -0
- data/ext/rubydex/declaration.h +10 -0
- data/ext/rubydex/definition.c +234 -0
- data/ext/rubydex/definition.h +28 -0
- data/ext/rubydex/diagnostic.c +6 -0
- data/ext/rubydex/diagnostic.h +11 -0
- data/ext/rubydex/document.c +98 -0
- data/ext/rubydex/document.h +10 -0
- data/ext/rubydex/extconf.rb +36 -15
- data/ext/rubydex/graph.c +405 -0
- data/ext/rubydex/graph.h +10 -0
- data/ext/rubydex/handle.h +44 -0
- data/ext/rubydex/location.c +22 -0
- data/ext/rubydex/location.h +15 -0
- data/ext/rubydex/reference.c +104 -0
- data/ext/rubydex/reference.h +16 -0
- data/ext/rubydex/rubydex.c +22 -0
- data/ext/rubydex/utils.c +27 -0
- data/ext/rubydex/utils.h +13 -0
- data/lib/rubydex/3.2/rubydex.so +0 -0
- data/lib/rubydex/3.3/rubydex.so +0 -0
- data/lib/rubydex/3.4/rubydex.so +0 -0
- data/lib/rubydex/4.0/rubydex.so +0 -0
- data/lib/rubydex/librubydex_sys.so +0 -0
- data/lib/rubydex/version.rb +1 -1
- data/rust/Cargo.lock +1275 -0
- data/rust/Cargo.toml +23 -0
- data/rust/about.hbs +78 -0
- data/rust/about.toml +9 -0
- data/rust/rubydex/Cargo.toml +41 -0
- data/rust/rubydex/src/diagnostic.rs +108 -0
- data/rust/rubydex/src/errors.rs +28 -0
- data/rust/rubydex/src/indexing/local_graph.rs +172 -0
- data/rust/rubydex/src/indexing/ruby_indexer.rs +5397 -0
- data/rust/rubydex/src/indexing.rs +128 -0
- data/rust/rubydex/src/job_queue.rs +186 -0
- data/rust/rubydex/src/lib.rs +15 -0
- data/rust/rubydex/src/listing.rs +249 -0
- data/rust/rubydex/src/main.rs +116 -0
- data/rust/rubydex/src/model/comment.rs +24 -0
- data/rust/rubydex/src/model/declaration.rs +541 -0
- data/rust/rubydex/src/model/definitions.rs +1475 -0
- data/rust/rubydex/src/model/document.rs +111 -0
- data/rust/rubydex/src/model/encoding.rs +22 -0
- data/rust/rubydex/src/model/graph.rs +1387 -0
- data/rust/rubydex/src/model/id.rs +90 -0
- data/rust/rubydex/src/model/identity_maps.rs +54 -0
- data/rust/rubydex/src/model/ids.rs +32 -0
- data/rust/rubydex/src/model/name.rs +188 -0
- data/rust/rubydex/src/model/references.rs +129 -0
- data/rust/rubydex/src/model/string_ref.rs +44 -0
- data/rust/rubydex/src/model/visibility.rs +41 -0
- data/rust/rubydex/src/model.rs +13 -0
- data/rust/rubydex/src/offset.rs +70 -0
- data/rust/rubydex/src/position.rs +6 -0
- data/rust/rubydex/src/query.rs +103 -0
- data/rust/rubydex/src/resolution.rs +4421 -0
- data/rust/rubydex/src/stats/memory.rs +71 -0
- data/rust/rubydex/src/stats/timer.rs +126 -0
- data/rust/rubydex/src/stats.rs +9 -0
- data/rust/rubydex/src/test_utils/context.rs +226 -0
- data/rust/rubydex/src/test_utils/graph_test.rs +229 -0
- data/rust/rubydex/src/test_utils/local_graph_test.rs +166 -0
- data/rust/rubydex/src/test_utils.rs +52 -0
- data/rust/rubydex/src/visualization/dot.rs +176 -0
- data/rust/rubydex/src/visualization.rs +6 -0
- data/rust/rubydex/tests/cli.rs +167 -0
- data/rust/rubydex-sys/Cargo.toml +20 -0
- data/rust/rubydex-sys/build.rs +14 -0
- data/rust/rubydex-sys/cbindgen.toml +12 -0
- data/rust/rubydex-sys/src/declaration_api.rs +114 -0
- data/rust/rubydex-sys/src/definition_api.rs +350 -0
- data/rust/rubydex-sys/src/diagnostic_api.rs +99 -0
- data/rust/rubydex-sys/src/document_api.rs +54 -0
- data/rust/rubydex-sys/src/graph_api.rs +493 -0
- data/rust/rubydex-sys/src/lib.rs +9 -0
- data/rust/rubydex-sys/src/location_api.rs +79 -0
- data/rust/rubydex-sys/src/name_api.rs +81 -0
- data/rust/rubydex-sys/src/reference_api.rs +191 -0
- data/rust/rubydex-sys/src/utils.rs +50 -0
- data/rust/rustfmt.toml +2 -0
- metadata +77 -2
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
use std::thread;
|
|
2
|
+
|
|
3
|
+
use crate::model::graph::Graph;
|
|
4
|
+
use crate::model::ids::DeclarationId;
|
|
5
|
+
|
|
6
|
+
/// # Panics
|
|
7
|
+
///
|
|
8
|
+
/// Will panic if any of the threads panic
|
|
9
|
+
pub fn declaration_search(graph: &Graph, query: &str) -> Vec<DeclarationId> {
|
|
10
|
+
let num_threads = thread::available_parallelism().map(std::num::NonZero::get).unwrap_or(4);
|
|
11
|
+
let declarations = graph.declarations();
|
|
12
|
+
let ids: Vec<DeclarationId> = declarations.keys().copied().collect();
|
|
13
|
+
let chunk_size = ids.len().div_ceil(num_threads);
|
|
14
|
+
|
|
15
|
+
if chunk_size == 0 {
|
|
16
|
+
return Vec::new();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
thread::scope(|s| {
|
|
20
|
+
let handles: Vec<_> = ids
|
|
21
|
+
.chunks(chunk_size)
|
|
22
|
+
.map(|chunk| {
|
|
23
|
+
s.spawn(|| {
|
|
24
|
+
chunk
|
|
25
|
+
.iter()
|
|
26
|
+
.filter(|id| {
|
|
27
|
+
let declaration = declarations.get(id).unwrap();
|
|
28
|
+
// When the query is empty, we return everything as per the LSP specification.
|
|
29
|
+
// Otherwise, we compute the match score and return anything with a score greater than zero
|
|
30
|
+
query.is_empty() || match_score(query, declaration.name()) > 0
|
|
31
|
+
})
|
|
32
|
+
.copied()
|
|
33
|
+
.collect::<Vec<_>>()
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
.collect();
|
|
37
|
+
|
|
38
|
+
handles.into_iter().flat_map(|h| h.join().unwrap()).collect()
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#[must_use]
|
|
43
|
+
fn match_score(query: &str, target: &str) -> usize {
|
|
44
|
+
let mut query_chars = query.chars().peekable();
|
|
45
|
+
let mut score = 0;
|
|
46
|
+
|
|
47
|
+
// Count the number of matches in the order of the query, so that character ordering is taken into account
|
|
48
|
+
for t_char in target.chars() {
|
|
49
|
+
if let Some(&q_char) = query_chars.peek()
|
|
50
|
+
&& q_char.eq_ignore_ascii_case(&t_char)
|
|
51
|
+
{
|
|
52
|
+
score += 1;
|
|
53
|
+
query_chars.next();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// If after going through the target, there are still query characters left, then some of the query can't be found
|
|
58
|
+
// in this target and we return zero to indicate a non-match
|
|
59
|
+
if query_chars.peek().is_some() { 0 } else { score }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#[cfg(test)]
|
|
63
|
+
mod tests {
|
|
64
|
+
use super::*;
|
|
65
|
+
use crate::test_utils::GraphTest;
|
|
66
|
+
|
|
67
|
+
macro_rules! assert_results_eq {
|
|
68
|
+
($context:expr, $query:expr, $expected:expr) => {
|
|
69
|
+
let actual = declaration_search(&$context.graph(), $query);
|
|
70
|
+
assert_eq!(
|
|
71
|
+
actual,
|
|
72
|
+
$expected
|
|
73
|
+
.into_iter()
|
|
74
|
+
.map(|s| DeclarationId::from(s))
|
|
75
|
+
.collect::<Vec<DeclarationId>>(),
|
|
76
|
+
"Unexpected search results: {:?}",
|
|
77
|
+
actual
|
|
78
|
+
.iter()
|
|
79
|
+
.map(|id| $context
|
|
80
|
+
.graph()
|
|
81
|
+
.declarations()
|
|
82
|
+
.get(id)
|
|
83
|
+
.unwrap()
|
|
84
|
+
.name()
|
|
85
|
+
.to_string())
|
|
86
|
+
.collect::<Vec<String>>()
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
#[test]
|
|
92
|
+
fn fuzzy_search_returns_partial_matches() {
|
|
93
|
+
let mut context = GraphTest::new();
|
|
94
|
+
context.index_uri("file:///foo.rb", {
|
|
95
|
+
r"
|
|
96
|
+
class Foo
|
|
97
|
+
end
|
|
98
|
+
"
|
|
99
|
+
});
|
|
100
|
+
context.resolve();
|
|
101
|
+
assert_results_eq!(context, "Fo", vec!["Foo"]);
|
|
102
|
+
}
|
|
103
|
+
}
|