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

Highlighting cardinality does not work without a space in front of it #661

Open
SimonCockx opened this issue Oct 2, 2023 · 2 comments
Open
Labels
bug Something isn't working subject: UI This issue is about UI features, such as content assist, auto-completion, etc

Comments

@SimonCockx
Copy link
Contributor

SimonCockx commented Oct 2, 2023

image (3)

See the cardinality of the postingParty attribute versus marginType.

The root cause is that the tokenizer is getting confused whether the next thing will be cardinality or type parameters (e.g., number(0..1) versus number(digits: 9) )

We should either fix the issue, or make it a syntax error.

@SimonCockx SimonCockx added bug Something isn't working subject: UI This issue is about UI features, such as content assist, auto-completion, etc labels Oct 2, 2023
@lolabeis
Copy link
Contributor

lolabeis commented Oct 2, 2023

@SimonCockx What's your recommendation: fix the issue, or make it a syntax error?

IMO the fact that the confusion (between cardinality or type parameter) exists suggests that we should remove the ambiguity, i.e. disallow space in the former case, and make it a syntax error. Better than make the language too flexible.

Qn: does the type parameter case support spacing? If so, we should probably disallow it using the same argument.

@SimonCockx
Copy link
Contributor Author

SimonCockx commented Oct 2, 2023

I think we should support highlighting cardinality without a space (i.e., fix the issue). Whitespace formatting is a style issue, and falls under the responsibility of code linting/formatting. As a rule of thumb, it is almost always better (read: user friendlier) to keep the parser as flexible as possible, and to rely on validators and code linters to make the language stricter.

Right now our parser effectively ignores all whitespace, and I think we want to keep it that way. It disambiguates between type parameters and a cardinality constraint by looking at the token after the ( token. E.g., if it is a number, then it's a cardinality constraint, otherwise it is a type parameter. We can probably implement it in the same way in our TextMate tokenizer, which is responsible for syntax highlighting.

That being said, our auto-formatter already inserts spaces between a type and a cardinality constraint, so performing auto-formatting on the given file would already work around the issue. I think auto-formatting is just not used often enough, and we might want to think about improving that by e.g.,

  • Automatically running auto-format on every PR,
  • Integrating support for a configurable code linter (such as Prettier) that can put warnings on these kind of issues and also suggest quickfixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working subject: UI This issue is about UI features, such as content assist, auto-completion, etc
Projects
None yet
Development

No branches or pull requests

2 participants