Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hint for language-region pair where language is expected #4142

Closed
laurmaedje opened this issue May 16, 2024 · 3 comments · Fixed by #4183
Closed

Hint for language-region pair where language is expected #4142

laurmaedje opened this issue May 16, 2024 · 3 comments · Fixed by #4183
Labels
diagnostics Improvements to compiler errors feature request New feature or request good first issue Good for newcomers

Comments

@laurmaedje
Copy link
Member

Description

When writing #set text(lang: "en-gb"), we should have a hint that you should use the region field instead.

Use Case

Helps people fix the problem.

@laurmaedje laurmaedje added feature request New feature or request good first issue Good for newcomers diagnostics Improvements to compiler errors labels May 16, 2024
@Coekjan
Copy link
Contributor

Coekjan commented May 16, 2024

Hi, I wonder if this diagnostics shall be implemented in Lang::from_str. I see current diagnostics information "expected two or three letter language code (ISO 639-1/2/3)" comes from there.

@laurmaedje
Copy link
Member Author

Unfortunately, the casting infrastructure doesn't support hints yet (FromValue always returns a StrResult). So, I think the only place we can do this at the moment is by augmenting the text.lang with a #[parse] annotation (you can search the codebase to see how it works).

@Coekjan
Copy link
Contributor

Coekjan commented May 18, 2024

I am thinking about when to hint something like "you should use region field". Here are some options I thought out:
Op1: The arg contains -
Op2: Op1 + the length of arg.split('-') is 2
Op3: Op2 + arg[0] can be parsed into Lang & arg[1] can be parsed into Region

Or does anyone have some other ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostics Improvements to compiler errors feature request New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants