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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rubydex/declaration.c +146 -0
  3. data/ext/rubydex/declaration.h +10 -0
  4. data/ext/rubydex/definition.c +234 -0
  5. data/ext/rubydex/definition.h +28 -0
  6. data/ext/rubydex/diagnostic.c +6 -0
  7. data/ext/rubydex/diagnostic.h +11 -0
  8. data/ext/rubydex/document.c +98 -0
  9. data/ext/rubydex/document.h +10 -0
  10. data/ext/rubydex/extconf.rb +36 -15
  11. data/ext/rubydex/graph.c +405 -0
  12. data/ext/rubydex/graph.h +10 -0
  13. data/ext/rubydex/handle.h +44 -0
  14. data/ext/rubydex/location.c +22 -0
  15. data/ext/rubydex/location.h +15 -0
  16. data/ext/rubydex/reference.c +104 -0
  17. data/ext/rubydex/reference.h +16 -0
  18. data/ext/rubydex/rubydex.c +22 -0
  19. data/ext/rubydex/utils.c +27 -0
  20. data/ext/rubydex/utils.h +13 -0
  21. data/lib/rubydex/3.2/rubydex.so +0 -0
  22. data/lib/rubydex/3.3/rubydex.so +0 -0
  23. data/lib/rubydex/3.4/rubydex.so +0 -0
  24. data/lib/rubydex/4.0/rubydex.so +0 -0
  25. data/lib/rubydex/librubydex_sys.so +0 -0
  26. data/lib/rubydex/version.rb +1 -1
  27. data/rust/Cargo.lock +1275 -0
  28. data/rust/Cargo.toml +23 -0
  29. data/rust/about.hbs +78 -0
  30. data/rust/about.toml +9 -0
  31. data/rust/rubydex/Cargo.toml +41 -0
  32. data/rust/rubydex/src/diagnostic.rs +108 -0
  33. data/rust/rubydex/src/errors.rs +28 -0
  34. data/rust/rubydex/src/indexing/local_graph.rs +172 -0
  35. data/rust/rubydex/src/indexing/ruby_indexer.rs +5397 -0
  36. data/rust/rubydex/src/indexing.rs +128 -0
  37. data/rust/rubydex/src/job_queue.rs +186 -0
  38. data/rust/rubydex/src/lib.rs +15 -0
  39. data/rust/rubydex/src/listing.rs +249 -0
  40. data/rust/rubydex/src/main.rs +116 -0
  41. data/rust/rubydex/src/model/comment.rs +24 -0
  42. data/rust/rubydex/src/model/declaration.rs +541 -0
  43. data/rust/rubydex/src/model/definitions.rs +1475 -0
  44. data/rust/rubydex/src/model/document.rs +111 -0
  45. data/rust/rubydex/src/model/encoding.rs +22 -0
  46. data/rust/rubydex/src/model/graph.rs +1387 -0
  47. data/rust/rubydex/src/model/id.rs +90 -0
  48. data/rust/rubydex/src/model/identity_maps.rs +54 -0
  49. data/rust/rubydex/src/model/ids.rs +32 -0
  50. data/rust/rubydex/src/model/name.rs +188 -0
  51. data/rust/rubydex/src/model/references.rs +129 -0
  52. data/rust/rubydex/src/model/string_ref.rs +44 -0
  53. data/rust/rubydex/src/model/visibility.rs +41 -0
  54. data/rust/rubydex/src/model.rs +13 -0
  55. data/rust/rubydex/src/offset.rs +70 -0
  56. data/rust/rubydex/src/position.rs +6 -0
  57. data/rust/rubydex/src/query.rs +103 -0
  58. data/rust/rubydex/src/resolution.rs +4421 -0
  59. data/rust/rubydex/src/stats/memory.rs +71 -0
  60. data/rust/rubydex/src/stats/timer.rs +126 -0
  61. data/rust/rubydex/src/stats.rs +9 -0
  62. data/rust/rubydex/src/test_utils/context.rs +226 -0
  63. data/rust/rubydex/src/test_utils/graph_test.rs +229 -0
  64. data/rust/rubydex/src/test_utils/local_graph_test.rs +166 -0
  65. data/rust/rubydex/src/test_utils.rs +52 -0
  66. data/rust/rubydex/src/visualization/dot.rs +176 -0
  67. data/rust/rubydex/src/visualization.rs +6 -0
  68. data/rust/rubydex/tests/cli.rs +167 -0
  69. data/rust/rubydex-sys/Cargo.toml +20 -0
  70. data/rust/rubydex-sys/build.rs +14 -0
  71. data/rust/rubydex-sys/cbindgen.toml +12 -0
  72. data/rust/rubydex-sys/src/declaration_api.rs +114 -0
  73. data/rust/rubydex-sys/src/definition_api.rs +350 -0
  74. data/rust/rubydex-sys/src/diagnostic_api.rs +99 -0
  75. data/rust/rubydex-sys/src/document_api.rs +54 -0
  76. data/rust/rubydex-sys/src/graph_api.rs +493 -0
  77. data/rust/rubydex-sys/src/lib.rs +9 -0
  78. data/rust/rubydex-sys/src/location_api.rs +79 -0
  79. data/rust/rubydex-sys/src/name_api.rs +81 -0
  80. data/rust/rubydex-sys/src/reference_api.rs +191 -0
  81. data/rust/rubydex-sys/src/utils.rs +50 -0
  82. data/rust/rustfmt.toml +2 -0
  83. 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
+ }