diff --git a/CHANGELOG.md b/CHANGELOG.md index 8422906c8b7..9de0592c65a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -419,3 +419,7 @@ - Fixed a bug where renaming a local variable which is used in combination with label shorthand syntax would produce invalid code. ([Surya Rose](https://github.com/GearsDatapacks)) + +- Fixed a bug where the language server would not show the "Unqualify type" code + action for record declarations. + ([cysabi](https://github.com/cysabi)) diff --git a/compiler-core/src/ast/visit.rs b/compiler-core/src/ast/visit.rs index dbdc6a506cb..166363995bc 100644 --- a/compiler-core/src/ast/visit.rs +++ b/compiler-core/src/ast/visit.rs @@ -700,10 +700,15 @@ where { } -pub fn visit_typed_custom_type<'a, V>(_v: &mut V, _custom_type: &'a TypedCustomType) +pub fn visit_typed_custom_type<'a, V>(v: &mut V, custom_type: &'a TypedCustomType) where V: Visit<'a> + ?Sized, { + for record in &custom_type.constructors { + for argument in &record.arguments { + v.visit_type_ast(&argument.ast); + } + } } pub fn visit_typed_expr<'a, V>(v: &mut V, node: &'a TypedExpr) diff --git a/compiler-core/src/language_server/tests/action.rs b/compiler-core/src/language_server/tests/action.rs index 50f6dea0cd0..cac7189a87b 100644 --- a/compiler-core/src/language_server/tests/action.rs +++ b/compiler-core/src/language_server/tests/action.rs @@ -2445,6 +2445,22 @@ pub fn main() { ); } +#[test] +fn test_qualified_to_unqualified_import_custom_type_record_declaration() { + let src = r#" +import wobble + +pub type Wibble { + Wibble(wibble: wobble.Wobble) +} +"#; + assert_code_action!( + "Unqualify wobble.Wobble", + TestProject::for_source(src).add_hex_module("wobble", "pub type Wobble { Wibble }"), + find_position_of(".").select_until(find_position_of("Wobble")) + ); +} + #[test] fn test_qualified_to_unqualified_import_basic_type_without_argument() { let src = r#" diff --git a/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__action__qualified_to_unqualified_import_custom_type_record_declaration.snap b/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__action__qualified_to_unqualified_import_custom_type_record_declaration.snap new file mode 100644 index 00000000000..3f043eda347 --- /dev/null +++ b/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__action__qualified_to_unqualified_import_custom_type_record_declaration.snap @@ -0,0 +1,21 @@ +--- +source: compiler-core/src/language_server/tests/action.rs +expression: "\nimport wobble\n\npub type Wibble {\n Wibble(wibble: wobble.Wobble)\n}\n" +--- +----- BEFORE ACTION + +import wobble + +pub type Wibble { + Wibble(wibble: wobble.Wobble) + ▔↑ +} + + +----- AFTER ACTION + +import wobble.{type Wobble} + +pub type Wibble { + Wibble(wibble: Wobble) +}