Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

LS: include type name in generate variant code action title

+51 -17
+4
CHANGELOG.md
··· 429 429 430 430 ([Daniel Venable](https://github.com/DanielVenable)) 431 431 432 + - The "Generate Variant" code action now includes the name of the type to add 433 + the variant to in its title. 434 + ([0xda157](https://github.com/0xda157)) 435 + 432 436 ### Formatter 433 437 434 438 - Performance of the formatter has been improved.
+13 -3
language-server/src/code_action.rs
··· 6920 6920 params: &'a CodeActionParams, 6921 6921 line_numbers: &'a LineNumbers, 6922 6922 variant_to_generate: Option<VariantToGenerate<'a>>, 6923 + printer: Printer<'a>, 6923 6924 } 6924 6925 6925 6926 struct VariantToGenerate<'a> { ··· 6964 6965 /// The module this variant will be added to. 6965 6966 /// 6966 6967 module_name: EcoString, 6968 + 6969 + /// The type to add this variant to. 6970 + type_: Arc<Type>, 6967 6971 6968 6972 /// The arguments actually supplied as input to the variant, if any. 6969 6973 /// A variant to generate might as well be just a name passed as an argument ··· 7061 7065 compiler, 7062 7066 line_numbers, 7063 7067 variant_to_generate: None, 7068 + printer: Printer::new(&module.ast.names), 7064 7069 } 7065 7070 } 7066 7071 ··· 7069 7074 7070 7075 let Some(VariantToGenerate { 7071 7076 name, 7077 + type_, 7072 7078 constructors, 7073 7079 arguments_types, 7074 7080 given_arguments, ··· 7127 7133 ); 7128 7134 } 7129 7135 7130 - let mut builder = CodeActionBuilder::new("Generate variant") 7131 - .kind(CodeActionKind::QuickFix) 7132 - .preferred(true); 7136 + let mut builder = CodeActionBuilder::new(&format!( 7137 + "Generate `{}` variant", 7138 + self.printer.print_type(type_) 7139 + )) 7140 + .kind(CodeActionKind::QuickFix) 7141 + .preferred(true); 7133 7142 7134 7143 match edits { 7135 7144 GenerateVariantEdits::GenerateInCurrentModule { ··· 7290 7299 arguments_types, 7291 7300 given_arguments, 7292 7301 module_name, 7302 + type_: custom_type, 7293 7303 end_position, 7294 7304 type_braces, 7295 7305 variant_start: function_name_location.start,
+34 -14
language-server/src/tests/action.rs
··· 193 193 const FILL_UNUSED_FIELDS: &str = "Fill unused fields"; 194 194 const REMOVE_ALL_ECHOS_FROM_THIS_MODULE: &str = "Remove all `echo`s from this module"; 195 195 const WRAP_IN_BLOCK: &str = "Wrap in block"; 196 - const GENERATE_VARIANT: &str = "Generate variant"; 197 196 const REMOVE_BLOCK: &str = "Remove block"; 198 197 const REMOVE_OPAQUE_FROM_PRIVATE_TYPE: &str = "Remove opaque from private type"; 199 198 const COLLAPSE_NESTED_CASE: &str = "Collapse nested case"; ··· 210 209 const ADD_EXTRA_PARENTHESES: &str = "Add extra parentheses"; 211 210 const CONVERT_TO_DOCUMENTATION_COMMENT: &str = "Convert to documentation comment"; 212 211 const CONVERT_TO_REGULAR_COMMENT: &str = "Convert to regular comment"; 212 + 213 + fn generate_variant_message(type_name: &str) -> String { 214 + format!("Generate `{type_name}` variant") 215 + } 213 216 214 217 macro_rules! assert_code_action { 215 218 ($title:expr, $code:literal, $range_selector:expr $(,)?) => { ··· 292 295 ); 293 296 assert_eq!(expected, result); 294 297 }; 298 + 299 + ($title:expr, $code:literal, $range_selector:expr $(,)?) => { 300 + let project = TestProject::for_source($code); 301 + assert_no_code_actions!($title, project, $range_selector); 302 + }; 303 + 304 + ($title:expr, $project:expr, $range_selector:expr $(,)?) => { 305 + let expected: Vec<lsp_types::CodeAction> = vec![]; 306 + let result = actions_with_title( 307 + vec![$title], 308 + &$project, 309 + Origin::Src, 310 + LSP_TEST_ROOT_PACKAGE_NAME, 311 + $range_selector 312 + ); 313 + assert_eq!(expected, result); 314 + }; 295 315 } 296 316 297 317 #[test] ··· 323 343 #[test] 324 344 fn generate_variant_with_fields_in_same_module() { 325 345 assert_code_action!( 326 - GENERATE_VARIANT, 346 + &generate_variant_message("Wibble"), 327 347 r#" 328 348 pub type Wibble { 329 349 Wibble ··· 339 359 #[test] 340 360 fn generate_variant_with_no_fields_in_same_module() { 341 361 assert_code_action!( 342 - GENERATE_VARIANT, 362 + &generate_variant_message("Wibble"), 343 363 r#" 344 364 pub type Wibble { 345 365 Wibble ··· 355 375 #[test] 356 376 fn generate_variant_with_labels_in_same_module() { 357 377 assert_code_action!( 358 - GENERATE_VARIANT, 378 + &generate_variant_message("Wibble"), 359 379 r#" 360 380 pub type Wibble { 361 381 Wibble ··· 371 391 #[test] 372 392 fn generate_variant_from_pattern_with_fields() { 373 393 assert_code_action!( 374 - GENERATE_VARIANT, 394 + &generate_variant_message("Wibble"), 375 395 r#" 376 396 pub type Wibble { 377 397 Wibble ··· 391 411 #[test] 392 412 fn generate_variant_from_pattern_with_labelled_fields() { 393 413 assert_code_action!( 394 - GENERATE_VARIANT, 414 + &generate_variant_message("Wibble"), 395 415 r#" 396 416 pub type Wibble { 397 417 Wibble ··· 411 431 #[test] 412 432 fn generate_variant_from_pattern_with_no_fields() { 413 433 assert_code_action!( 414 - GENERATE_VARIANT, 434 + &generate_variant_message("Wibble"), 415 435 r#" 416 436 pub type Wibble { 417 437 Wibble ··· 441 461 "#; 442 462 443 463 assert_code_action!( 444 - GENERATE_VARIANT, 464 + &generate_variant_message("other.Wibble"), 445 465 TestProject::for_source(src).add_module("other", "pub type Wibble"), 446 466 find_position_of("Wobble").to_selection() 447 467 ); ··· 461 481 "#; 462 482 463 483 assert_code_action!( 464 - GENERATE_VARIANT, 484 + &generate_variant_message("other.Wibble"), 465 485 TestProject::for_source(src).add_module( 466 486 "other", 467 487 "pub type Wibble { ··· 486 506 "#; 487 507 488 508 assert_code_action!( 489 - GENERATE_VARIANT, 509 + &generate_variant_message("other.Wibble"), 490 510 TestProject::for_source(src).add_module( 491 511 "other", 492 512 "pub type Wibble { ··· 509 529 pub fn new() -> other.Wibble { todo } 510 530 "#; 511 531 assert_code_action!( 512 - GENERATE_VARIANT, 532 + &generate_variant_message("other.Wibble"), 513 533 TestProject::for_source(src).add_module("other", "pub type Wibble"), 514 534 find_position_of("Wobble").to_selection() 515 535 ); ··· 518 538 #[test] 519 539 fn do_not_generate_variant_if_one_with_the_same_name_exists() { 520 540 assert_no_code_actions!( 521 - GENERATE_VARIANT, 541 + &generate_variant_message("Wibble"), 522 542 r#" 523 543 pub fn main() -> Wibble { 524 544 let assert Wobble = new() ··· 546 566 pub fn new() -> Wibble { todo } 547 567 "#; 548 568 assert_no_code_actions!( 549 - GENERATE_VARIANT, 569 + &generate_variant_message("Wibble"), 550 570 TestProject::for_source(src).add_module("other", "pub type Wibble { Wobble(String) }"), 551 571 find_position_of("Wobble").to_selection() 552 572 ); ··· 564 584 pub fn new() -> Wibble { todo } 565 585 "#; 566 586 assert_no_code_actions!( 567 - GENERATE_VARIANT, 587 + &generate_variant_message("Wibble"), 568 588 TestProject::for_source(src).add_module("other", "pub type Wibble { Wobble(String) }"), 569 589 find_position_of("Wobble").to_selection() 570 590 );