1
2
3
4
5
6
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
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
//! Manifest-scoped state that can refine a registry's "latest matching" version selection.
//!
//! Beyond the plain requirement text — e.g. Composer's `minimum-stability` field (#424,
//! #1433, #1444).
//!
//! [`SelectionContext`] used to carry Composer's `minimum-stability` as a raw
//! `Option<String>`, with `Registry::get_latest_matching`/`select_latest_matching` each
//! having a context-less trait method and a separate `_with_context` twin a caller had to
//! remember to call instead. #1444 collapses that: [`crate::Registry::get_latest_matching`]
//! and [`crate::Registry::select_latest_matching`] now take a required
//! [`SelectionContext`] parameter directly (an explicit [`SelectionContext::none()`] is the
//! only way to opt out, and that choice is now visible at every call site instead of an
//! easy-to-forget separate method name), and the stability value itself is the typed
//! [`StabilityFloor`] rather than a free-form string.
use FromStr;
/// A Composer `minimum-stability` floor (or per-dependency `@stability` flag), ranked
/// `Dev < Alpha < Beta < Rc < Stable` (#424, #1444).
///
/// Declaration order is the precedence order: [`Ord`] compares two floors exactly as
/// Composer's own stability scale does, so `StabilityFloor::Beta < StabilityFloor::Rc`
/// holds via the derived comparison, with no separate rank table to keep in sync.
///
/// This is the *manifest-declared* stability floor's own type — strict, via
/// [`FromStr`] — distinct from the lenient qualifier classification a *version string*'s
/// own suffix (e.g. `1.0.0-beta.1`) goes through inside `deps-composer`'s
/// `compare_versions`, which still accepts the `a`/`b` short aliases and maps an
/// unrecognized word to [`Self::Stable`] — that leniency is unchanged by this type.
///
/// # Examples
///
/// ```
/// use deps_core::selection::StabilityFloor;
///
/// assert!(StabilityFloor::Dev < StabilityFloor::Alpha);
/// assert!(StabilityFloor::Alpha < StabilityFloor::Beta);
/// assert!(StabilityFloor::Beta < StabilityFloor::Rc);
/// assert!(StabilityFloor::Rc < StabilityFloor::Stable);
/// ```
/// [`StabilityFloor::from_str`]'s error.
///
/// `raw` was not one of the five recognized stability keywords (`dev`, `alpha`, `beta`,
/// `rc`, `stable`), matched ASCII-case-insensitively and with no surrounding-whitespace
/// tolerance.
///
/// # Examples
///
/// ```
/// use deps_core::selection::{StabilityFloor, UnknownStability};
///
/// assert_eq!("betta".parse::<StabilityFloor>(), Err(UnknownStability));
/// assert_eq!(" beta".parse::<StabilityFloor>(), Err(UnknownStability));
/// ```
;
/// One manifest-declared `minimum-stability` value that failed to parse.
///
/// Failed via [`StabilityFloor::from_str`] — returned by
/// [`crate::ParseResult::invalid_minimum_stability`] and surfaced as a diagnostic by
/// `deps_core::lsp_helpers::diagnostics`' shared notice.
///
/// # Examples
///
/// ```
/// use deps_core::selection::InvalidStabilityOccurrence;
/// use deps_core::position::{Position, Range};
///
/// let occurrence = InvalidStabilityOccurrence {
/// range: Range::new(Position::new(0, 0), Position::new(0, 5)),
/// raw: "betta".to_string(),
/// };
/// assert_eq!(occurrence.raw, "betta");
/// ```
/// Manifest-scoped state that can refine a registry's "latest matching" version selection
/// beyond the plain requirement text — e.g. Composer's `minimum-stability` field (#424,
/// #1433, #1444).
///
/// Opaque and ecosystem-owned: the type carries whatever an ecosystem's own [`crate::ParseResult`]
/// puts into it (today, only Composer's `minimum-stability`), and only that ecosystem's own
/// [`crate::Registry`] implementation reads it back — every other registry ignores it via
/// [`crate::Registry::get_latest_matching`]/[`crate::Registry::select_latest_matching`]'s own
/// default. Every LSP call site that needs "the latest version for this dependency" (hover,
/// completion, code actions, and the background fetch path) obtains one from
/// [`crate::ParseResult::selection_context`] and threads it into those two required-parameter
/// trait methods, so a call site that already has a `ParseResult` in scope no longer has to
/// independently remember to extract and thread the same manifest-level state by hand
/// (#1433).
///
/// [`PartialEq`] is derived so a caller can detect *that* the context changed between two
/// parses (e.g. `deps-lsp`'s edit-triggered refetch escalation) without needing to know what
/// changed.
///
/// # Examples
///
/// ```
/// use deps_core::selection::{SelectionContext, StabilityFloor};
///
/// let none = SelectionContext::none();
/// assert_eq!(none.minimum_stability(), None);
///
/// let composer = SelectionContext::with_minimum_stability(StabilityFloor::Alpha);
/// assert_eq!(composer.minimum_stability(), Some(StabilityFloor::Alpha));
/// assert_ne!(none, composer);
/// ```