diff --git a/CHANGELOG.md b/CHANGELOG.md index 940537866d0..8e1545246da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,3 +28,7 @@ - Fixed a bug where a bit array segment matching on a floating point number would match with `NaN` or `Infinity` on the JavaScript target. ([Giacomo Cavalieri](https://github.com/giacomocavalieri)) + +- 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 eb235354edd..350e79d7faf 100644 --- a/compiler-core/src/ast/visit.rs +++ b/compiler-core/src/ast/visit.rs @@ -704,10 +704,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 65d9aaa2227..72633ce5f41 100644 --- a/compiler-core/src/language_server/tests/action.rs +++ b/compiler-core/src/language_server/tests/action.rs @@ -2916,6 +2916,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) +}