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,111 @@
1
+ use line_index::LineIndex;
2
+
3
+ use crate::diagnostic::Diagnostic;
4
+ use crate::model::ids::{DefinitionId, ReferenceId};
5
+
6
+ // Represents a document currently loaded into memory. Identified by its unique URI, it holds the edges to all
7
+ // definitions and references discovered in it
8
+ #[derive(Debug)]
9
+ pub struct Document {
10
+ uri: String,
11
+ line_index: LineIndex,
12
+ definition_ids: Vec<DefinitionId>,
13
+ method_reference_ids: Vec<ReferenceId>,
14
+ constant_reference_ids: Vec<ReferenceId>,
15
+ diagnostics: Vec<Diagnostic>,
16
+ }
17
+
18
+ impl Document {
19
+ #[must_use]
20
+ pub fn new(uri: String, source: &str) -> Self {
21
+ Self {
22
+ uri,
23
+ line_index: LineIndex::new(source),
24
+ definition_ids: Vec::new(),
25
+ method_reference_ids: Vec::new(),
26
+ constant_reference_ids: Vec::new(),
27
+ diagnostics: Vec::new(),
28
+ }
29
+ }
30
+
31
+ #[must_use]
32
+ pub fn uri(&self) -> &str {
33
+ &self.uri
34
+ }
35
+
36
+ #[must_use]
37
+ pub fn line_index(&self) -> &LineIndex {
38
+ &self.line_index
39
+ }
40
+
41
+ #[must_use]
42
+ pub fn definitions(&self) -> &[DefinitionId] {
43
+ &self.definition_ids
44
+ }
45
+
46
+ pub fn add_definition(&mut self, definition_id: DefinitionId) {
47
+ debug_assert!(
48
+ !self.definition_ids.contains(&definition_id),
49
+ "Cannot add the same exact definition to a document twice. Duplicate definition IDs"
50
+ );
51
+
52
+ self.definition_ids.push(definition_id);
53
+ }
54
+
55
+ #[must_use]
56
+ pub fn method_references(&self) -> &[ReferenceId] {
57
+ &self.method_reference_ids
58
+ }
59
+
60
+ pub fn add_method_reference(&mut self, reference_id: ReferenceId) {
61
+ self.method_reference_ids.push(reference_id);
62
+ }
63
+
64
+ #[must_use]
65
+ pub fn constant_references(&self) -> &[ReferenceId] {
66
+ &self.constant_reference_ids
67
+ }
68
+
69
+ pub fn add_constant_reference(&mut self, reference_id: ReferenceId) {
70
+ self.constant_reference_ids.push(reference_id);
71
+ }
72
+
73
+ #[must_use]
74
+ pub fn diagnostics(&self) -> &[Diagnostic] {
75
+ &self.diagnostics
76
+ }
77
+
78
+ pub fn add_diagnostic(&mut self, diagnostic: Diagnostic) {
79
+ self.diagnostics.push(diagnostic);
80
+ }
81
+ }
82
+
83
+ #[cfg(test)]
84
+ mod tests {
85
+ use super::*;
86
+
87
+ #[test]
88
+ #[should_panic(expected = "Cannot add the same exact definition to a document twice. Duplicate definition IDs")]
89
+ fn inserting_duplicate_definitions() {
90
+ let mut document = Document::new("file:///foo.rb".to_string(), "class Foo; end");
91
+ let def_id = DefinitionId::new(123);
92
+
93
+ document.add_definition(def_id);
94
+ document.add_definition(def_id);
95
+
96
+ assert_eq!(document.definitions().len(), 1);
97
+ }
98
+
99
+ #[test]
100
+ fn tracking_references() {
101
+ let mut document = Document::new("file:///foo.rb".to_string(), "class Foo; end");
102
+ let method_ref = ReferenceId::new(1);
103
+ let constant_ref = ReferenceId::new(2);
104
+
105
+ document.add_method_reference(method_ref);
106
+ document.add_constant_reference(constant_ref);
107
+
108
+ assert_eq!(document.method_references(), &[method_ref]);
109
+ assert_eq!(document.constant_references(), &[constant_ref]);
110
+ }
111
+ }
@@ -0,0 +1,22 @@
1
+ use line_index::WideEncoding;
2
+
3
+ #[derive(Default, Debug)]
4
+ pub enum Encoding {
5
+ #[default]
6
+ Utf8,
7
+ Utf16,
8
+ Utf32,
9
+ }
10
+
11
+ impl Encoding {
12
+ /// Transform the LSP selected encoding into the expected `WideEncoding` for converting code units with the
13
+ /// `line_index` crate
14
+ #[must_use]
15
+ pub fn to_wide(&self) -> Option<WideEncoding> {
16
+ match self {
17
+ Encoding::Utf8 => None,
18
+ Encoding::Utf16 => Some(WideEncoding::Utf16),
19
+ Encoding::Utf32 => Some(WideEncoding::Utf32),
20
+ }
21
+ }
22
+ }