rubydex 0.1.0.beta11 → 0.1.0.beta13
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/LICENSE.txt +23 -23
- data/README.md +125 -125
- data/THIRD_PARTY_LICENSES.html +2018 -945
- data/exe/rdx +47 -47
- data/ext/rubydex/declaration.c +453 -388
- data/ext/rubydex/declaration.h +23 -23
- data/ext/rubydex/definition.c +284 -197
- data/ext/rubydex/definition.h +28 -28
- data/ext/rubydex/diagnostic.c +6 -6
- data/ext/rubydex/diagnostic.h +11 -11
- data/ext/rubydex/document.c +97 -98
- data/ext/rubydex/document.h +10 -10
- data/ext/rubydex/extconf.rb +146 -127
- data/ext/rubydex/graph.c +701 -512
- data/ext/rubydex/graph.h +10 -10
- data/ext/rubydex/handle.h +44 -44
- data/ext/rubydex/location.c +22 -22
- data/ext/rubydex/location.h +15 -15
- data/ext/rubydex/reference.c +123 -104
- data/ext/rubydex/reference.h +15 -16
- data/ext/rubydex/rubydex.c +22 -22
- data/ext/rubydex/utils.c +108 -86
- data/ext/rubydex/utils.h +34 -28
- data/lib/rubydex/comment.rb +17 -17
- data/lib/rubydex/declaration.rb +11 -0
- data/lib/rubydex/diagnostic.rb +21 -21
- data/lib/rubydex/failures.rb +15 -15
- data/lib/rubydex/graph.rb +98 -92
- data/lib/rubydex/keyword.rb +17 -0
- data/lib/rubydex/keyword_parameter.rb +13 -0
- data/lib/rubydex/location.rb +90 -90
- data/lib/rubydex/mixin.rb +22 -0
- data/lib/rubydex/version.rb +5 -5
- data/lib/rubydex.rb +24 -20
- data/rbi/rubydex.rbi +425 -310
- data/rust/Cargo.lock +1851 -1851
- data/rust/Cargo.toml +29 -29
- data/rust/about.toml +10 -10
- data/rust/{about.hbs → about_templates/about.hbs} +81 -78
- data/rust/about_templates/mingw_licenses.hbs +1071 -0
- data/rust/rubydex/Cargo.toml +42 -42
- data/rust/rubydex/src/compile_assertions.rs +13 -13
- data/rust/rubydex/src/diagnostic.rs +110 -109
- data/rust/rubydex/src/errors.rs +28 -28
- data/rust/rubydex/src/indexing/local_graph.rs +224 -224
- data/rust/rubydex/src/indexing/rbs_indexer.rs +1551 -1554
- data/rust/rubydex/src/indexing/ruby_indexer.rs +2329 -6753
- data/rust/rubydex/src/indexing/ruby_indexer_tests.rs +4962 -0
- data/rust/rubydex/src/indexing.rs +210 -210
- data/rust/rubydex/src/integrity.rs +279 -278
- data/rust/rubydex/src/job_queue.rs +199 -205
- data/rust/rubydex/src/lib.rs +17 -17
- data/rust/rubydex/src/listing.rs +371 -272
- data/rust/rubydex/src/main.rs +160 -160
- data/rust/rubydex/src/model/built_in.rs +83 -0
- data/rust/rubydex/src/model/comment.rs +24 -24
- data/rust/rubydex/src/model/declaration.rs +679 -588
- data/rust/rubydex/src/model/definitions.rs +1682 -1602
- data/rust/rubydex/src/model/document.rs +222 -252
- data/rust/rubydex/src/model/encoding.rs +22 -22
- data/rust/rubydex/src/model/graph.rs +3782 -3556
- data/rust/rubydex/src/model/id.rs +110 -110
- data/rust/rubydex/src/model/identity_maps.rs +58 -58
- data/rust/rubydex/src/model/ids.rs +60 -38
- data/rust/rubydex/src/model/keywords.rs +256 -256
- data/rust/rubydex/src/model/name.rs +298 -298
- data/rust/rubydex/src/model/references.rs +111 -111
- data/rust/rubydex/src/model/string_ref.rs +50 -50
- data/rust/rubydex/src/model/visibility.rs +41 -41
- data/rust/rubydex/src/model.rs +15 -14
- data/rust/rubydex/src/offset.rs +147 -147
- data/rust/rubydex/src/position.rs +6 -6
- data/rust/rubydex/src/query.rs +1841 -1700
- data/rust/rubydex/src/resolution.rs +1852 -5895
- data/rust/rubydex/src/resolution_tests.rs +4701 -0
- data/rust/rubydex/src/stats/memory.rs +71 -71
- data/rust/rubydex/src/stats/orphan_report.rs +264 -263
- data/rust/rubydex/src/stats/timer.rs +127 -127
- data/rust/rubydex/src/stats.rs +11 -11
- data/rust/rubydex/src/test_utils/context.rs +226 -226
- data/rust/rubydex/src/test_utils/graph_test.rs +730 -679
- data/rust/rubydex/src/test_utils/local_graph_test.rs +602 -602
- data/rust/rubydex/src/test_utils.rs +52 -52
- data/rust/rubydex/src/visualization/dot.rs +192 -176
- data/rust/rubydex/src/visualization.rs +6 -6
- data/rust/rubydex/tests/cli.rs +185 -167
- data/rust/rubydex-mcp/Cargo.toml +28 -28
- data/rust/rubydex-mcp/src/main.rs +48 -48
- data/rust/rubydex-mcp/src/server.rs +1145 -1145
- data/rust/rubydex-mcp/src/tools.rs +49 -49
- data/rust/rubydex-mcp/tests/mcp.rs +302 -302
- data/rust/rubydex-sys/Cargo.toml +20 -20
- data/rust/rubydex-sys/build.rs +14 -14
- data/rust/rubydex-sys/cbindgen.toml +12 -12
- data/rust/rubydex-sys/src/declaration_api.rs +485 -469
- data/rust/rubydex-sys/src/definition_api.rs +443 -352
- data/rust/rubydex-sys/src/diagnostic_api.rs +99 -99
- data/rust/rubydex-sys/src/document_api.rs +85 -54
- data/rust/rubydex-sys/src/graph_api.rs +1017 -700
- data/rust/rubydex-sys/src/lib.rs +79 -9
- data/rust/rubydex-sys/src/location_api.rs +79 -79
- data/rust/rubydex-sys/src/name_api.rs +187 -135
- data/rust/rubydex-sys/src/reference_api.rs +267 -195
- data/rust/rubydex-sys/src/utils.rs +70 -70
- data/rust/rustfmt.toml +2 -2
- metadata +16 -9
- data/lib/rubydex/librubydex_sys.so +0 -0
data/rust/rubydex/src/listing.rs
CHANGED
|
@@ -1,272 +1,371 @@
|
|
|
1
|
-
use crate::{
|
|
2
|
-
errors::Errors,
|
|
3
|
-
job_queue::{Job, JobQueue},
|
|
4
|
-
};
|
|
5
|
-
use crossbeam_channel::{Sender, unbounded};
|
|
6
|
-
use std::{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
let
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
|
|
1
|
+
use crate::{
|
|
2
|
+
errors::Errors,
|
|
3
|
+
job_queue::{Job, JobQueue},
|
|
4
|
+
};
|
|
5
|
+
use crossbeam_channel::{Sender, unbounded};
|
|
6
|
+
use std::{
|
|
7
|
+
collections::HashSet,
|
|
8
|
+
fs,
|
|
9
|
+
hash::BuildHasher,
|
|
10
|
+
path::{Path, PathBuf},
|
|
11
|
+
sync::Arc,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
pub struct FileDiscoveryJob {
|
|
15
|
+
path: PathBuf,
|
|
16
|
+
queue: Arc<JobQueue>,
|
|
17
|
+
paths_tx: Sender<PathBuf>,
|
|
18
|
+
errors_tx: Sender<Errors>,
|
|
19
|
+
excluded_paths: Arc<HashSet<PathBuf>>,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
impl FileDiscoveryJob {
|
|
23
|
+
#[must_use]
|
|
24
|
+
pub fn new(
|
|
25
|
+
path: PathBuf,
|
|
26
|
+
queue: Arc<JobQueue>,
|
|
27
|
+
paths_tx: Sender<PathBuf>,
|
|
28
|
+
errors_tx: Sender<Errors>,
|
|
29
|
+
excluded_paths: Arc<HashSet<PathBuf>>,
|
|
30
|
+
) -> Self {
|
|
31
|
+
Self {
|
|
32
|
+
path,
|
|
33
|
+
queue,
|
|
34
|
+
paths_tx,
|
|
35
|
+
errors_tx,
|
|
36
|
+
excluded_paths,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
impl FileDiscoveryJob {
|
|
42
|
+
fn handle_file(&self, path: &Path) {
|
|
43
|
+
if path.extension().is_some_and(|ext| ext == "rb" || ext == "rbs") {
|
|
44
|
+
self.paths_tx
|
|
45
|
+
.send(path.to_path_buf())
|
|
46
|
+
.expect("file receiver dropped before run completion");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fn handle_symlink(&self, path: &PathBuf) {
|
|
51
|
+
let Ok(canonicalized) = fs::canonicalize(path) else {
|
|
52
|
+
self.send_error(Errors::FileError(format!(
|
|
53
|
+
"Failed to canonicalize symlink: `{}`",
|
|
54
|
+
path.display(),
|
|
55
|
+
)));
|
|
56
|
+
|
|
57
|
+
return;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if self.excluded_paths.contains(&canonicalized) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
self.queue.push(Box::new(FileDiscoveryJob::new(
|
|
65
|
+
canonicalized,
|
|
66
|
+
Arc::clone(&self.queue),
|
|
67
|
+
self.paths_tx.clone(),
|
|
68
|
+
self.errors_tx.clone(),
|
|
69
|
+
Arc::clone(&self.excluded_paths),
|
|
70
|
+
)));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
fn send_error(&self, error: Errors) {
|
|
74
|
+
self.errors_tx
|
|
75
|
+
.send(error)
|
|
76
|
+
.expect("error receiver dropped before run completion");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
impl Job for FileDiscoveryJob {
|
|
81
|
+
fn run(&self) {
|
|
82
|
+
if self.path.is_dir() {
|
|
83
|
+
let Ok(read_dir) = self.path.read_dir() else {
|
|
84
|
+
self.send_error(Errors::FileError(format!(
|
|
85
|
+
"Failed to read directory `{}`",
|
|
86
|
+
self.path.display(),
|
|
87
|
+
)));
|
|
88
|
+
|
|
89
|
+
return;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
for result in read_dir {
|
|
93
|
+
let Ok(entry) = result else {
|
|
94
|
+
self.send_error(Errors::FileError(format!(
|
|
95
|
+
"Failed to read directory `{}`: {result:?}",
|
|
96
|
+
self.path.display(),
|
|
97
|
+
)));
|
|
98
|
+
|
|
99
|
+
continue;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
let kind = entry.file_type().unwrap();
|
|
103
|
+
|
|
104
|
+
if kind.is_dir() {
|
|
105
|
+
if self.excluded_paths.contains(&entry.path()) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
self.queue.push(Box::new(FileDiscoveryJob::new(
|
|
110
|
+
entry.path(),
|
|
111
|
+
Arc::clone(&self.queue),
|
|
112
|
+
self.paths_tx.clone(),
|
|
113
|
+
self.errors_tx.clone(),
|
|
114
|
+
Arc::clone(&self.excluded_paths),
|
|
115
|
+
)));
|
|
116
|
+
} else if kind.is_file() {
|
|
117
|
+
self.handle_file(&entry.path());
|
|
118
|
+
} else if kind.is_symlink() {
|
|
119
|
+
self.handle_symlink(&entry.path());
|
|
120
|
+
} else {
|
|
121
|
+
self.send_error(Errors::FileError(format!(
|
|
122
|
+
"Path `{}` is not a file or directory",
|
|
123
|
+
entry.path().display()
|
|
124
|
+
)));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
} else if self.path.is_file() {
|
|
128
|
+
self.handle_file(&self.path);
|
|
129
|
+
} else if self.path.is_symlink() {
|
|
130
|
+
self.handle_symlink(&self.path);
|
|
131
|
+
} else {
|
|
132
|
+
self.send_error(Errors::FileError(format!(
|
|
133
|
+
"Path `{}` is not a file or directory",
|
|
134
|
+
self.path.display()
|
|
135
|
+
)));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// Recursively collects all Ruby files for the given workspace and dependencies, returning a vector of document instances
|
|
141
|
+
///
|
|
142
|
+
/// # Errors
|
|
143
|
+
///
|
|
144
|
+
/// Returns a `MultipleErrors` if any of the paths do not exist
|
|
145
|
+
///
|
|
146
|
+
/// # Panics
|
|
147
|
+
///
|
|
148
|
+
/// Panics if the errors receiver is dropped before the run completion
|
|
149
|
+
#[must_use]
|
|
150
|
+
pub fn collect_file_paths<S: BuildHasher>(
|
|
151
|
+
paths: Vec<String>,
|
|
152
|
+
excluded: &HashSet<PathBuf, S>,
|
|
153
|
+
) -> (Vec<PathBuf>, Vec<Errors>) {
|
|
154
|
+
let queue = Arc::new(JobQueue::new());
|
|
155
|
+
let (files_tx, files_rx) = unbounded();
|
|
156
|
+
let (errors_tx, errors_rx) = unbounded();
|
|
157
|
+
|
|
158
|
+
// Canonicalize the excluded paths since they may be symlinks
|
|
159
|
+
let excluded: Arc<HashSet<PathBuf>> = Arc::new(excluded.iter().filter_map(|p| fs::canonicalize(p).ok()).collect());
|
|
160
|
+
|
|
161
|
+
for path in paths {
|
|
162
|
+
let Ok(canonicalized) = fs::canonicalize(&path) else {
|
|
163
|
+
errors_tx
|
|
164
|
+
.send(Errors::FileError(format!("Path `{path}` does not exist")))
|
|
165
|
+
.expect("errors receiver dropped before run completion");
|
|
166
|
+
|
|
167
|
+
continue;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
if excluded.contains(&canonicalized) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
queue.push(Box::new(FileDiscoveryJob::new(
|
|
175
|
+
canonicalized,
|
|
176
|
+
Arc::clone(&queue),
|
|
177
|
+
files_tx.clone(),
|
|
178
|
+
errors_tx.clone(),
|
|
179
|
+
Arc::clone(&excluded),
|
|
180
|
+
)));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
JobQueue::run(&queue);
|
|
184
|
+
|
|
185
|
+
drop(files_tx);
|
|
186
|
+
drop(errors_tx);
|
|
187
|
+
|
|
188
|
+
(files_rx.iter().collect(), errors_rx.iter().collect())
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
#[cfg(test)]
|
|
192
|
+
mod tests {
|
|
193
|
+
use super::*;
|
|
194
|
+
use crate::test_utils::Context;
|
|
195
|
+
|
|
196
|
+
fn collect_document_paths(context: &Context, paths: &[&str]) -> (Vec<String>, Vec<Errors>) {
|
|
197
|
+
collect_document_paths_with_exclusions(context, paths, &HashSet::new())
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
fn collect_document_paths_with_exclusions(
|
|
201
|
+
context: &Context,
|
|
202
|
+
paths: &[&str],
|
|
203
|
+
excluded: &HashSet<PathBuf>,
|
|
204
|
+
) -> (Vec<String>, Vec<Errors>) {
|
|
205
|
+
let (files, errors) = collect_file_paths(
|
|
206
|
+
paths
|
|
207
|
+
.iter()
|
|
208
|
+
.map(|p| context.absolute_path_to(p).to_string_lossy().into_owned())
|
|
209
|
+
.collect(),
|
|
210
|
+
excluded,
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
let mut files: Vec<String> = files
|
|
214
|
+
.iter()
|
|
215
|
+
.map(|path| context.relative_path_to(path).to_string_lossy().into_owned())
|
|
216
|
+
.collect();
|
|
217
|
+
|
|
218
|
+
files.sort();
|
|
219
|
+
|
|
220
|
+
(files, errors)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
#[test]
|
|
224
|
+
fn collect_all_documents() {
|
|
225
|
+
let context = Context::new();
|
|
226
|
+
let baz = PathBuf::from("bar").join("baz.rb");
|
|
227
|
+
let qux = PathBuf::from("bar").join("qux.rb");
|
|
228
|
+
let bar = PathBuf::from("foo").join("bar.rb");
|
|
229
|
+
context.touch(&baz);
|
|
230
|
+
context.touch(&qux);
|
|
231
|
+
context.touch(&bar);
|
|
232
|
+
|
|
233
|
+
let (files, errors) = collect_document_paths(&context, &["foo", "bar"]);
|
|
234
|
+
|
|
235
|
+
assert!(errors.is_empty());
|
|
236
|
+
|
|
237
|
+
assert_eq!(
|
|
238
|
+
files,
|
|
239
|
+
[
|
|
240
|
+
baz.to_str().unwrap().to_string(),
|
|
241
|
+
qux.to_str().unwrap().to_string(),
|
|
242
|
+
bar.to_str().unwrap().to_string()
|
|
243
|
+
]
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
#[test]
|
|
248
|
+
fn collect_some_documents_based_on_paths() {
|
|
249
|
+
let context = Context::new();
|
|
250
|
+
let baz = PathBuf::from("bar").join("baz.rb");
|
|
251
|
+
let qux = PathBuf::from("bar").join("qux.rb");
|
|
252
|
+
let bar = PathBuf::from("foo").join("bar.rb");
|
|
253
|
+
|
|
254
|
+
context.touch(&baz);
|
|
255
|
+
context.touch(&qux);
|
|
256
|
+
context.touch(&bar);
|
|
257
|
+
|
|
258
|
+
let (files, errors) = collect_document_paths(&context, &["bar"]);
|
|
259
|
+
|
|
260
|
+
assert!(errors.is_empty());
|
|
261
|
+
|
|
262
|
+
assert_eq!(
|
|
263
|
+
files,
|
|
264
|
+
[baz.to_str().unwrap().to_string(), qux.to_str().unwrap().to_string()]
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
#[test]
|
|
269
|
+
fn collect_rbs_files() {
|
|
270
|
+
let context = Context::new();
|
|
271
|
+
let ruby_file = PathBuf::from("lib").join("foo.rb");
|
|
272
|
+
let rbs_file = PathBuf::from("sig").join("foo.rbs");
|
|
273
|
+
let txt_file = PathBuf::from("lib").join("notes.txt");
|
|
274
|
+
context.touch(&ruby_file);
|
|
275
|
+
context.touch(&rbs_file);
|
|
276
|
+
context.touch(&txt_file);
|
|
277
|
+
|
|
278
|
+
let (files, errors) = collect_document_paths(&context, &["lib", "sig"]);
|
|
279
|
+
|
|
280
|
+
assert!(errors.is_empty());
|
|
281
|
+
|
|
282
|
+
assert_eq!(
|
|
283
|
+
[
|
|
284
|
+
ruby_file.to_str().unwrap().to_string(),
|
|
285
|
+
rbs_file.to_str().unwrap().to_string(),
|
|
286
|
+
],
|
|
287
|
+
files.as_slice()
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
#[test]
|
|
292
|
+
fn collect_non_existing_paths() {
|
|
293
|
+
let context = Context::new();
|
|
294
|
+
|
|
295
|
+
let (files, errors) = collect_file_paths(
|
|
296
|
+
vec![
|
|
297
|
+
context
|
|
298
|
+
.absolute_path_to("non_existing_path")
|
|
299
|
+
.to_string_lossy()
|
|
300
|
+
.into_owned(),
|
|
301
|
+
],
|
|
302
|
+
&HashSet::new(),
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
assert!(files.is_empty());
|
|
306
|
+
|
|
307
|
+
assert_eq!(
|
|
308
|
+
errors,
|
|
309
|
+
[Errors::FileError(format!(
|
|
310
|
+
"Path `{}` does not exist",
|
|
311
|
+
context.absolute_path_to("non_existing_path").display()
|
|
312
|
+
))]
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
#[test]
|
|
317
|
+
fn collect_files_excludes_directories() {
|
|
318
|
+
let context = Context::new();
|
|
319
|
+
let included = PathBuf::from("included").join("foo.rb");
|
|
320
|
+
let excluded_file = PathBuf::from("excluded").join("bar.rb");
|
|
321
|
+
context.touch(&included);
|
|
322
|
+
context.touch(&excluded_file);
|
|
323
|
+
|
|
324
|
+
let mut excluded = HashSet::new();
|
|
325
|
+
excluded.insert(context.absolute_path_to("excluded"));
|
|
326
|
+
|
|
327
|
+
let (files, errors) = collect_document_paths_with_exclusions(&context, &["included", "excluded"], &excluded);
|
|
328
|
+
|
|
329
|
+
assert!(errors.is_empty());
|
|
330
|
+
assert_eq!(files, [included.to_str().unwrap().to_string()]);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
#[test]
|
|
334
|
+
fn collect_files_excludes_nested_directories() {
|
|
335
|
+
let context = Context::new();
|
|
336
|
+
let kept = PathBuf::from("root").join("kept.rb");
|
|
337
|
+
let nested = PathBuf::from("root").join("skip").join("nested.rb");
|
|
338
|
+
context.touch(&kept);
|
|
339
|
+
context.touch(&nested);
|
|
340
|
+
|
|
341
|
+
let mut excluded = HashSet::new();
|
|
342
|
+
excluded.insert(context.absolute_path_to("root/skip"));
|
|
343
|
+
|
|
344
|
+
let (files, errors) = collect_document_paths_with_exclusions(&context, &["root"], &excluded);
|
|
345
|
+
|
|
346
|
+
assert!(errors.is_empty());
|
|
347
|
+
assert_eq!(files, [kept.to_str().unwrap().to_string()]);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
#[cfg(unix)]
|
|
351
|
+
#[test]
|
|
352
|
+
fn collect_files_excludes_symlinked_directories() {
|
|
353
|
+
let context = Context::new();
|
|
354
|
+
let included = PathBuf::from("included").join("foo.rb");
|
|
355
|
+
let excluded_file = PathBuf::from("real_dir").join("bar.rb");
|
|
356
|
+
context.touch(&included);
|
|
357
|
+
context.touch(&excluded_file);
|
|
358
|
+
|
|
359
|
+
// Create a symlink: link -> real_dir
|
|
360
|
+
std::os::unix::fs::symlink(context.absolute_path_to("real_dir"), context.absolute_path_to("link")).unwrap();
|
|
361
|
+
|
|
362
|
+
// Excluding the real directory while requesting to index the symlink should properly exclude the link
|
|
363
|
+
let mut excluded = HashSet::new();
|
|
364
|
+
excluded.insert(context.absolute_path_to("real_dir"));
|
|
365
|
+
|
|
366
|
+
let (files, errors) = collect_document_paths_with_exclusions(&context, &["included", "link"], &excluded);
|
|
367
|
+
|
|
368
|
+
assert!(errors.is_empty());
|
|
369
|
+
assert_eq!(files, [included.to_str().unwrap().to_string()]);
|
|
370
|
+
}
|
|
371
|
+
}
|