Skip to content

Conversation

@fatelei
Copy link

@fatelei fatelei commented Sep 27, 2025

fix issue #3972

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely! Thank you very much. I've added some feedback inline, and we'll also need tests for all the new functionality.

@lpil lpil changed the title fix: https://github.com/gleam-lang/gleam/issues/3972 LS: warn when a Gleam file path is not a valid module name Sep 27, 2025
@lpil lpil marked this pull request as draft September 27, 2025 15:57
@giacomocavalieri
Copy link
Member

Hello! If this is ready for review remember to mark is as ready so we can have a look :)

@fatelei
Copy link
Author

fatelei commented Sep 29, 2025

Hello! If this is ready for review remember to mark is as ready so we can have a look :)

ready

@lpil lpil marked this pull request as ready for review October 1, 2025 16:28
Copy link
Member

@giacomocavalieri giacomocavalieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some changes I'm not sure why they were introduced

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! I've left some notes inline, and could you add tests please 🙏

Sorry for the delay, I didn't get a notification that it was ready. Thank you

];
assert_eq!(
parse_and_order(functions.as_slice(), [].as_slice()).unwrap(),
parse_and_order(functions.as_slice(), [].as_slice()).expect("Expected parse_and_order to succeed"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo these unrelated changes please

hint: None,
};
feedback.append_diagnostic(path.to_path_buf(), diagnostic);
Some(feedback)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return a diagnostic from this function, not the entire feedback container, otherwise this function would be responsible for checking for the mistake and also for the higher level concern of how they are stored.

s = "module".into();
}
if !s.chars().next().map(|c| c.is_ascii_lowercase()).unwrap_or(false) {
s = format!("m{}", s);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this m prefix?

let suggestion = module_name
.split('/')
.map(|seg| {
let mut s = to_snake_case(&ecow::EcoString::from(seg)).to_string();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ecostring rather than string please

s
})
.collect::<Vec<_>>()
.join("/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can suggest invalid module names, such as gleam.


let mut feedback = Feedback::default();
// Highlight the first line to ensure the diagnostic is visible in editors
let first_line_end = src.find('\n').unwrap_or(src.len());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this look in various editors? Could we get some screenshots 🙏

let first_line_end = src.find('\n').unwrap_or(src.len());
let span_end: u32 = first_line_end.max(1).try_into().unwrap_or(1);
let diagnostic = Diagnostic {
title: format!("{module_name} is not a valid name for a Gleam module"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: format!("{module_name} is not a valid name for a Gleam module"),
title: format!("{module_name} is not a valid module name"),

let span_end: u32 = first_line_end.max(1).try_into().unwrap_or(1);
let diagnostic = Diagnostic {
title: format!("{module_name} is not a valid name for a Gleam module"),
text: format!("You should switch to {suggestion} instead."),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include what the rules are for module names, and don't use the word "should", especially in times like this when we don't know what the best option is.

_ => return false,
}
iter.all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_')
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use the existing code for validating module names?

@lpil lpil marked this pull request as draft December 4, 2025 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants