rubydex 0.1.0.beta12-aarch64-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 (109) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +23 -0
  3. data/README.md +125 -0
  4. data/THIRD_PARTY_LICENSES.html +4562 -0
  5. data/exe/rdx +47 -0
  6. data/ext/rubydex/declaration.c +453 -0
  7. data/ext/rubydex/declaration.h +23 -0
  8. data/ext/rubydex/definition.c +284 -0
  9. data/ext/rubydex/definition.h +28 -0
  10. data/ext/rubydex/diagnostic.c +6 -0
  11. data/ext/rubydex/diagnostic.h +11 -0
  12. data/ext/rubydex/document.c +97 -0
  13. data/ext/rubydex/document.h +10 -0
  14. data/ext/rubydex/extconf.rb +138 -0
  15. data/ext/rubydex/graph.c +681 -0
  16. data/ext/rubydex/graph.h +10 -0
  17. data/ext/rubydex/handle.h +44 -0
  18. data/ext/rubydex/location.c +22 -0
  19. data/ext/rubydex/location.h +15 -0
  20. data/ext/rubydex/reference.c +123 -0
  21. data/ext/rubydex/reference.h +15 -0
  22. data/ext/rubydex/rubydex.c +22 -0
  23. data/ext/rubydex/utils.c +108 -0
  24. data/ext/rubydex/utils.h +34 -0
  25. data/lib/rubydex/3.2/rubydex.so +0 -0
  26. data/lib/rubydex/3.3/rubydex.so +0 -0
  27. data/lib/rubydex/3.4/rubydex.so +0 -0
  28. data/lib/rubydex/4.0/rubydex.so +0 -0
  29. data/lib/rubydex/comment.rb +17 -0
  30. data/lib/rubydex/diagnostic.rb +21 -0
  31. data/lib/rubydex/failures.rb +15 -0
  32. data/lib/rubydex/graph.rb +98 -0
  33. data/lib/rubydex/keyword.rb +17 -0
  34. data/lib/rubydex/keyword_parameter.rb +13 -0
  35. data/lib/rubydex/librubydex_sys.so +0 -0
  36. data/lib/rubydex/location.rb +90 -0
  37. data/lib/rubydex/mixin.rb +22 -0
  38. data/lib/rubydex/version.rb +5 -0
  39. data/lib/rubydex.rb +23 -0
  40. data/rbi/rubydex.rbi +422 -0
  41. data/rust/Cargo.lock +1851 -0
  42. data/rust/Cargo.toml +29 -0
  43. data/rust/about.hbs +78 -0
  44. data/rust/about.toml +10 -0
  45. data/rust/rubydex/Cargo.toml +42 -0
  46. data/rust/rubydex/src/compile_assertions.rs +13 -0
  47. data/rust/rubydex/src/diagnostic.rs +110 -0
  48. data/rust/rubydex/src/errors.rs +28 -0
  49. data/rust/rubydex/src/indexing/local_graph.rs +224 -0
  50. data/rust/rubydex/src/indexing/rbs_indexer.rs +1551 -0
  51. data/rust/rubydex/src/indexing/ruby_indexer.rs +2329 -0
  52. data/rust/rubydex/src/indexing/ruby_indexer_tests.rs +4962 -0
  53. data/rust/rubydex/src/indexing.rs +210 -0
  54. data/rust/rubydex/src/integrity.rs +279 -0
  55. data/rust/rubydex/src/job_queue.rs +205 -0
  56. data/rust/rubydex/src/lib.rs +17 -0
  57. data/rust/rubydex/src/listing.rs +371 -0
  58. data/rust/rubydex/src/main.rs +160 -0
  59. data/rust/rubydex/src/model/built_in.rs +83 -0
  60. data/rust/rubydex/src/model/comment.rs +24 -0
  61. data/rust/rubydex/src/model/declaration.rs +671 -0
  62. data/rust/rubydex/src/model/definitions.rs +1682 -0
  63. data/rust/rubydex/src/model/document.rs +222 -0
  64. data/rust/rubydex/src/model/encoding.rs +22 -0
  65. data/rust/rubydex/src/model/graph.rs +3754 -0
  66. data/rust/rubydex/src/model/id.rs +110 -0
  67. data/rust/rubydex/src/model/identity_maps.rs +58 -0
  68. data/rust/rubydex/src/model/ids.rs +60 -0
  69. data/rust/rubydex/src/model/keywords.rs +256 -0
  70. data/rust/rubydex/src/model/name.rs +298 -0
  71. data/rust/rubydex/src/model/references.rs +111 -0
  72. data/rust/rubydex/src/model/string_ref.rs +50 -0
  73. data/rust/rubydex/src/model/visibility.rs +41 -0
  74. data/rust/rubydex/src/model.rs +15 -0
  75. data/rust/rubydex/src/offset.rs +147 -0
  76. data/rust/rubydex/src/position.rs +6 -0
  77. data/rust/rubydex/src/query.rs +1841 -0
  78. data/rust/rubydex/src/resolution.rs +6517 -0
  79. data/rust/rubydex/src/stats/memory.rs +71 -0
  80. data/rust/rubydex/src/stats/orphan_report.rs +264 -0
  81. data/rust/rubydex/src/stats/timer.rs +127 -0
  82. data/rust/rubydex/src/stats.rs +11 -0
  83. data/rust/rubydex/src/test_utils/context.rs +226 -0
  84. data/rust/rubydex/src/test_utils/graph_test.rs +730 -0
  85. data/rust/rubydex/src/test_utils/local_graph_test.rs +602 -0
  86. data/rust/rubydex/src/test_utils.rs +52 -0
  87. data/rust/rubydex/src/visualization/dot.rs +192 -0
  88. data/rust/rubydex/src/visualization.rs +6 -0
  89. data/rust/rubydex/tests/cli.rs +185 -0
  90. data/rust/rubydex-mcp/Cargo.toml +28 -0
  91. data/rust/rubydex-mcp/src/main.rs +48 -0
  92. data/rust/rubydex-mcp/src/server.rs +1145 -0
  93. data/rust/rubydex-mcp/src/tools.rs +49 -0
  94. data/rust/rubydex-mcp/tests/mcp.rs +302 -0
  95. data/rust/rubydex-sys/Cargo.toml +20 -0
  96. data/rust/rubydex-sys/build.rs +14 -0
  97. data/rust/rubydex-sys/cbindgen.toml +12 -0
  98. data/rust/rubydex-sys/src/declaration_api.rs +485 -0
  99. data/rust/rubydex-sys/src/definition_api.rs +443 -0
  100. data/rust/rubydex-sys/src/diagnostic_api.rs +99 -0
  101. data/rust/rubydex-sys/src/document_api.rs +85 -0
  102. data/rust/rubydex-sys/src/graph_api.rs +948 -0
  103. data/rust/rubydex-sys/src/lib.rs +79 -0
  104. data/rust/rubydex-sys/src/location_api.rs +79 -0
  105. data/rust/rubydex-sys/src/name_api.rs +135 -0
  106. data/rust/rubydex-sys/src/reference_api.rs +267 -0
  107. data/rust/rubydex-sys/src/utils.rs +70 -0
  108. data/rust/rustfmt.toml +2 -0
  109. metadata +159 -0
@@ -0,0 +1,222 @@
1
+ use std::path::PathBuf;
2
+
3
+ use line_index::LineIndex;
4
+ use url::Url;
5
+
6
+ use crate::diagnostic::Diagnostic;
7
+ use crate::model::ids::{ConstantReferenceId, DefinitionId, MethodReferenceId};
8
+
9
+ // Represents a document currently loaded into memory. Identified by its unique URI, it holds the edges to all
10
+ // definitions and references discovered in it
11
+ #[derive(Debug)]
12
+ pub struct Document {
13
+ uri: String,
14
+ line_index: LineIndex,
15
+ definition_ids: Vec<DefinitionId>,
16
+ method_reference_ids: Vec<MethodReferenceId>,
17
+ constant_reference_ids: Vec<ConstantReferenceId>,
18
+ diagnostics: Vec<Diagnostic>,
19
+ }
20
+
21
+ impl Document {
22
+ #[must_use]
23
+ pub fn new(uri: String, source: &str) -> Self {
24
+ Self {
25
+ uri,
26
+ line_index: LineIndex::new(source),
27
+ definition_ids: Vec::new(),
28
+ method_reference_ids: Vec::new(),
29
+ constant_reference_ids: Vec::new(),
30
+ diagnostics: Vec::new(),
31
+ }
32
+ }
33
+
34
+ #[must_use]
35
+ pub fn uri(&self) -> &str {
36
+ &self.uri
37
+ }
38
+
39
+ #[must_use]
40
+ pub fn line_index(&self) -> &LineIndex {
41
+ &self.line_index
42
+ }
43
+
44
+ #[must_use]
45
+ pub fn definitions(&self) -> &[DefinitionId] {
46
+ &self.definition_ids
47
+ }
48
+
49
+ pub fn add_definition(&mut self, definition_id: DefinitionId) {
50
+ debug_assert!(
51
+ !self.definition_ids.contains(&definition_id),
52
+ "Cannot add the same exact definition to a document twice. Duplicate definition IDs"
53
+ );
54
+
55
+ self.definition_ids.push(definition_id);
56
+ }
57
+
58
+ #[must_use]
59
+ pub fn method_references(&self) -> &[MethodReferenceId] {
60
+ &self.method_reference_ids
61
+ }
62
+
63
+ pub fn add_method_reference(&mut self, reference_id: MethodReferenceId) {
64
+ self.method_reference_ids.push(reference_id);
65
+ }
66
+
67
+ #[must_use]
68
+ pub fn constant_references(&self) -> &[ConstantReferenceId] {
69
+ &self.constant_reference_ids
70
+ }
71
+
72
+ pub fn add_constant_reference(&mut self, reference_id: ConstantReferenceId) {
73
+ self.constant_reference_ids.push(reference_id);
74
+ }
75
+
76
+ #[must_use]
77
+ pub fn diagnostics(&self) -> &[Diagnostic] {
78
+ &self.diagnostics
79
+ }
80
+
81
+ pub fn add_diagnostic(&mut self, diagnostic: Diagnostic) {
82
+ self.diagnostics.push(diagnostic);
83
+ }
84
+
85
+ /// Computes the require path for this document given load paths.
86
+ ///
87
+ /// Returns `None` if:
88
+ /// - URI is not `file://` scheme
89
+ /// - URI doesn't end with `.rb`
90
+ /// - File path doesn't match any load path
91
+ /// - `Url::to_file_path()` fails
92
+ ///
93
+ /// # Panics
94
+ ///
95
+ /// Panics if load path entries exceed u16.
96
+ #[must_use]
97
+ pub fn require_path(&self, load_paths: &[PathBuf]) -> Option<(String, u16)> {
98
+ let url = Url::parse(&self.uri).ok()?;
99
+ if url.scheme() != "file" {
100
+ return None;
101
+ }
102
+
103
+ let file_path = url.to_file_path().ok()?;
104
+ if file_path.extension().is_none_or(|ext| ext != "rb") {
105
+ return None;
106
+ }
107
+
108
+ for (load_path_index, load_path) in load_paths.iter().enumerate() {
109
+ if let Ok(relative) = file_path.strip_prefix(load_path) {
110
+ let file_path = relative
111
+ .components()
112
+ .filter_map(|c| c.as_os_str().to_str())
113
+ .collect::<Vec<_>>()
114
+ .join("/");
115
+
116
+ let require_path = file_path.trim_end_matches(".rb").to_string();
117
+ return Some((
118
+ require_path,
119
+ load_path_index.try_into().expect("Load path entries exceed u16"),
120
+ ));
121
+ }
122
+ }
123
+ None
124
+ }
125
+ }
126
+
127
+ #[cfg(test)]
128
+ mod tests {
129
+ use std::str::FromStr;
130
+
131
+ use super::*;
132
+
133
+ fn test_root() -> PathBuf {
134
+ let root = if cfg!(windows) { "C:\\" } else { "/" };
135
+ PathBuf::from_str(root).unwrap()
136
+ }
137
+
138
+ #[test]
139
+ #[should_panic(expected = "Cannot add the same exact definition to a document twice. Duplicate definition IDs")]
140
+ fn inserting_duplicate_definitions() {
141
+ let mut document = Document::new("file:///foo.rb".to_string(), "class Foo; end");
142
+ let def_id = DefinitionId::new(123);
143
+
144
+ document.add_definition(def_id);
145
+ document.add_definition(def_id);
146
+
147
+ assert_eq!(document.definitions().len(), 1);
148
+ }
149
+
150
+ #[test]
151
+ fn tracking_references() {
152
+ let mut document = Document::new("file:///foo.rb".to_string(), "class Foo; end");
153
+ let method_ref = MethodReferenceId::new(1);
154
+ let constant_ref = ConstantReferenceId::new(2);
155
+
156
+ document.add_method_reference(method_ref);
157
+ document.add_constant_reference(constant_ref);
158
+
159
+ assert_eq!(document.method_references(), &[method_ref]);
160
+ assert_eq!(document.constant_references(), &[constant_ref]);
161
+ }
162
+
163
+ #[test]
164
+ fn require_path() {
165
+ let root = test_root();
166
+ let path = root.join("lib").join("foo").join("bar.rb");
167
+ let uri = Url::from_file_path(path).unwrap().to_string();
168
+ let load_paths = [root.join("lib")];
169
+
170
+ let document = Document::new(uri, "");
171
+ assert_eq!(Some(("foo/bar".to_string(), 0)), document.require_path(&load_paths));
172
+ }
173
+
174
+ #[test]
175
+ fn require_path_first_load_path_wins() {
176
+ let root = test_root();
177
+ let path = root.join("a").join("b").join("foo.rb");
178
+ let uri = Url::from_file_path(path).unwrap().to_string();
179
+ let load_path_a = root.join("a");
180
+ let load_path_ab = root.join("a").join("b");
181
+ let load_paths = [load_path_a, load_path_ab];
182
+
183
+ let document = Document::new(uri, "");
184
+ assert_eq!(Some(("b/foo".to_string(), 0)), document.require_path(&load_paths));
185
+ }
186
+
187
+ #[test]
188
+ fn require_path_returns_none() {
189
+ let root = test_root();
190
+ let load_paths = [root.join("lib")];
191
+
192
+ // non-file URI
193
+ let document = Document::new("untitled:Untitled-1".to_string(), "");
194
+ assert!(document.require_path(&load_paths).is_none());
195
+
196
+ // non-.rb extension
197
+ let path = root.join("lib").join("foo.so");
198
+ let uri = Url::from_file_path(path).unwrap().to_string();
199
+ let document = Document::new(uri, "");
200
+ assert!(document.require_path(&load_paths).is_none());
201
+
202
+ // /libfoo is not under /lib - should not match due to partial directory name
203
+ let path = root.join("libfoo").join("bar.rb");
204
+ let uri = Url::from_file_path(path).unwrap().to_string();
205
+ let document = Document::new(uri, "");
206
+ assert!(document.require_path(&load_paths).is_none());
207
+ }
208
+
209
+ #[test]
210
+ fn require_path_with_spaces() {
211
+ let root = test_root();
212
+ let path = root.join("lib").join("space foo").join("bar.rb");
213
+ let uri = Url::from_file_path(path).unwrap().to_string();
214
+ let load_paths = [root.join("lib")];
215
+
216
+ let document = Document::new(uri, "");
217
+ assert_eq!(
218
+ Some(("space foo/bar".to_string(), 0)),
219
+ document.require_path(&load_paths)
220
+ );
221
+ }
222
+ }
@@ -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
+ }