diff --git a/compiler-core/src/ast.rs b/compiler-core/src/ast.rs index 49e051563c1..c5a52e9f461 100644 --- a/compiler-core/src/ast.rs +++ b/compiler-core/src/ast.rs @@ -914,7 +914,7 @@ impl TypedDefinition { return Some(annotation); } - return Some(Located::RecordConstructor(constructor)); + return Some(Located::VariantConstructorDefinition(constructor)); } // Note that the custom type `.location` covers the function diff --git a/compiler-core/src/build.rs b/compiler-core/src/build.rs index 94fda87d161..fb8c83b2196 100644 --- a/compiler-core/src/build.rs +++ b/compiler-core/src/build.rs @@ -339,7 +339,7 @@ pub enum Located<'a> { Statement(&'a TypedStatement), Expression(&'a TypedExpr), ModuleStatement(&'a TypedDefinition), - RecordConstructor(&'a TypedRecordConstructor), + VariantConstructorDefinition(&'a TypedRecordConstructor), FunctionBody(&'a TypedFunction), Arg(&'a TypedArg), Annotation(SrcSpan, std::sync::Arc), @@ -383,7 +383,7 @@ impl<'a> Located<'a> { module: None, span: statement.location(), }), - Self::RecordConstructor(record) => Some(DefinitionLocation { + Self::VariantConstructorDefinition(record) => Some(DefinitionLocation { module: None, span: record.location, }), @@ -425,7 +425,7 @@ impl<'a> Located<'a> { Located::PatternSpread { .. } => None, Located::ModuleStatement(definition) => None, - Located::RecordConstructor(_) => None, + Located::VariantConstructorDefinition(_) => None, Located::FunctionBody(function) => None, Located::UnqualifiedImport(unqualified_import) => None, Located::ModuleName { .. } => None, diff --git a/compiler-core/src/language_server/engine.rs b/compiler-core/src/language_server/engine.rs index 7ba2e0b1ff0..746fee6072d 100644 --- a/compiler-core/src/language_server/engine.rs +++ b/compiler-core/src/language_server/engine.rs @@ -304,7 +304,7 @@ where Located::FunctionBody(_) => Some(completer.completion_values()), Located::ModuleStatement(Definition::TypeAlias(_) | Definition::CustomType(_)) - | Located::RecordConstructor(_) => Some(completer.completion_types()), + | Located::VariantConstructorDefinition(_) => Some(completer.completion_types()), // If the import completions returned no results and we are in an import then // we should try to provide completions for unqualified values @@ -635,7 +635,9 @@ where }) | Definition::ModuleConstant(ModuleConstant { name_location, .. }), ) - | Located::RecordConstructor(RecordConstructor { name_location, .. }) => { + | Located::VariantConstructorDefinition(RecordConstructor { + name_location, .. + }) => { // When we locate a module statement, we don't know where exactly the cursor // is positioned. In this example, we want to rename the first but not the second: // ```gleam @@ -827,13 +829,15 @@ where &this.compiler.modules, Named::CustomTypeVariant, ), - Located::RecordConstructor(RecordConstructor { name, .. }) => rename_module_value( - ¶ms, - &module.name, - name, - &this.compiler.modules, - Named::CustomTypeVariant, - ), + Located::VariantConstructorDefinition(RecordConstructor { name, .. }) => { + rename_module_value( + ¶ms, + &module.name, + name, + &this.compiler.modules, + Named::CustomTypeVariant, + ) + } Located::Pattern(Pattern::Constructor { constructor: analyse::Inferred::Known(constructor), .. @@ -900,7 +904,7 @@ where )) } Located::ModuleStatement(_) => None, - Located::RecordConstructor(_) => None, + Located::VariantConstructorDefinition(_) => None, Located::UnqualifiedImport(UnqualifiedImport { name, module: module_name, diff --git a/compiler-core/src/language_server/rename.rs b/compiler-core/src/language_server/rename.rs index a85aaaa88e7..4086ea79b4a 100644 --- a/compiler-core/src/language_server/rename.rs +++ b/compiler-core/src/language_server/rename.rs @@ -73,7 +73,9 @@ pub fn rename_module_value( name_kind: Named, ) -> Option { if name::check_name_case( - Default::default(), + // We don't care about the actual error here, just whether the name is valid, + // so we just use the default span. + SrcSpan::default(), ¶ms.new_name.as_str().into(), name_kind, )