|
4 | 4 |
|
5 | 5 | use crate::{GotoDefinition, HoverDocumentation, Rename}; |
6 | 6 | use assert_json_diff::assert_json_eq; |
| 7 | +use rayon::vec; |
7 | 8 | use regex::Regex; |
8 | 9 | use serde_json::json; |
9 | 10 | use std::{borrow::Cow, path::Path}; |
@@ -241,21 +242,118 @@ pub(crate) async fn inlay_hints_request<'a>( |
241 | 242 | text_document: TextDocumentIdentifier { uri: uri.clone() }, |
242 | 243 | range: Range { |
243 | 244 | start: Position { |
244 | | - line: 0, |
| 245 | + line: 25, |
245 | 246 | character: 0, |
246 | 247 | }, |
247 | 248 | end: Position { |
248 | | - line: 14, |
| 249 | + line: 26, |
249 | 250 | character: 1, |
250 | 251 | }, |
251 | 252 | }, |
252 | 253 | work_done_progress_params: Default::default(), |
253 | 254 | }; |
254 | | - let res = request::handle_inlay_hints(server, params).await.unwrap(); |
| 255 | + let res = request::handle_inlay_hints(server, params) |
| 256 | + .await |
| 257 | + .unwrap() |
| 258 | + .unwrap(); |
| 259 | + let expected = vec![ |
| 260 | + InlayHint { |
| 261 | + position: Position { |
| 262 | + line: 25, |
| 263 | + character: 25, |
| 264 | + }, |
| 265 | + label: InlayHintLabel::String("foo: ".to_string()), |
| 266 | + kind: Some(InlayHintKind::PARAMETER), |
| 267 | + text_edits: None, |
| 268 | + tooltip: None, |
| 269 | + padding_left: Some(false), |
| 270 | + padding_right: Some(false), |
| 271 | + data: None, |
| 272 | + }, |
| 273 | + InlayHint { |
| 274 | + position: Position { |
| 275 | + line: 25, |
| 276 | + character: 28, |
| 277 | + }, |
| 278 | + label: InlayHintLabel::String("bar: ".to_string()), |
| 279 | + kind: Some(InlayHintKind::PARAMETER), |
| 280 | + text_edits: None, |
| 281 | + tooltip: None, |
| 282 | + padding_left: Some(false), |
| 283 | + padding_right: Some(false), |
| 284 | + data: None, |
| 285 | + }, |
| 286 | + InlayHint { |
| 287 | + position: Position { |
| 288 | + line: 25, |
| 289 | + character: 31, |
| 290 | + }, |
| 291 | + label: InlayHintLabel::String("long_argument_name: ".to_string()), |
| 292 | + kind: Some(InlayHintKind::PARAMETER), |
| 293 | + text_edits: None, |
| 294 | + tooltip: None, |
| 295 | + padding_left: Some(false), |
| 296 | + padding_right: Some(false), |
| 297 | + data: None, |
| 298 | + }, |
| 299 | + InlayHint { |
| 300 | + position: Position { |
| 301 | + line: 25, |
| 302 | + character: 10, |
| 303 | + }, |
| 304 | + label: InlayHintLabel::String(": u64".to_string()), |
| 305 | + kind: Some(InlayHintKind::TYPE), |
| 306 | + text_edits: None, |
| 307 | + tooltip: None, |
| 308 | + padding_left: Some(false), |
| 309 | + padding_right: Some(false), |
| 310 | + data: None, |
| 311 | + }, |
| 312 | + ]; |
255 | 313 |
|
256 | | - eprintln!("INLAY HINTS RESULTS"); |
257 | | - eprintln!("{:#?}", res); |
258 | | - res |
| 314 | + assert!( |
| 315 | + compare_inlay_hint_vecs(&expected, &res), |
| 316 | + "InlayHint vectors are not equal.\nExpected:\n{:#?}\n\nActual:\n{:#?}", |
| 317 | + expected, |
| 318 | + res |
| 319 | + ); |
| 320 | + Some(res) |
| 321 | +} |
| 322 | + |
| 323 | +fn compare_inlay_hints(a: &InlayHint, b: &InlayHint) -> bool { |
| 324 | + a.position == b.position |
| 325 | + && compare_inlay_hint_labels(&a.label, &b.label) |
| 326 | + && a.kind == b.kind |
| 327 | + && a.text_edits == b.text_edits |
| 328 | + && compare_inlay_hint_tooltips(&a.tooltip, &b.tooltip) |
| 329 | + && a.padding_left == b.padding_left |
| 330 | + && a.padding_right == b.padding_right |
| 331 | + && a.data == b.data |
| 332 | +} |
| 333 | + |
| 334 | +fn compare_inlay_hint_vecs(a: &[InlayHint], b: &[InlayHint]) -> bool { |
| 335 | + a.len() == b.len() && a.iter().zip(b).all(|(a, b)| compare_inlay_hints(a, b)) |
| 336 | +} |
| 337 | + |
| 338 | +fn compare_inlay_hint_labels(a: &InlayHintLabel, b: &InlayHintLabel) -> bool { |
| 339 | + match (a, b) { |
| 340 | + (InlayHintLabel::String(a), InlayHintLabel::String(b)) => a == b, |
| 341 | + _ => false, |
| 342 | + } |
| 343 | +} |
| 344 | + |
| 345 | +fn compare_inlay_hint_tooltips(a: &Option<InlayHintTooltip>, b: &Option<InlayHintTooltip>) -> bool { |
| 346 | + match (a, b) { |
| 347 | + (None, None) => true, |
| 348 | + (Some(a), Some(b)) => match (a, b) { |
| 349 | + (InlayHintTooltip::String(a), InlayHintTooltip::String(b)) => a == b, |
| 350 | + (InlayHintTooltip::MarkupContent(a), InlayHintTooltip::MarkupContent(b)) => { |
| 351 | + a.kind == b.kind && a.value == b.value |
| 352 | + } |
| 353 | + _ => false, |
| 354 | + }, |
| 355 | + _ => false, |
| 356 | + } |
259 | 357 | } |
260 | 358 |
|
261 | 359 | pub(crate) async fn semantic_tokens_request(server: &ServerState, uri: &Url) { |
|
0 commit comments