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

Support users to replace parser rules which are used only as type for cross-references by type declarations #1391

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

JohannesMeierSE
Copy link
Contributor

@JohannesMeierSE JohannesMeierSE commented Feb 29, 2024

This PR contributes the following things and closes #1309:

  • At the moment parser rules which are used not for parsing but whose type is used in cross-references are marked as "unused" for users. This message is not accurate and could confuse inexperienced users. Therefore, the message of the validation is improved to "This parser rule is not used for parsing, but referenced by cross-references. Consider to replace this rule by a type declaration.". See Parser rule used as type for cross-reference is marked as "unused" #1309 for details.
  • Additionally, a quick-fix is provided for users to replace such a parser rule by a type declaration.
  • While the two contributions above target a quite special case, this PR contributes also a generic helper functionality to check quick-fixes (testQuickFix in packages/langium/src/test/langium-test.ts). This function is tested by applying it to the mentioned new quick-fix for the Langium grammar.

@JohannesMeierSE JohannesMeierSE force-pushed the validation-unused-rule-crossreference branch from 59cd7b0 to 136a1f9 Compare March 8, 2024 14:51
@JohannesMeierSE JohannesMeierSE force-pushed the validation-unused-rule-crossreference branch from 136a1f9 to b05bcac Compare October 8, 2024 11:41
@JohannesMeierSE
Copy link
Contributor Author

FYI: I just resolved conflicts with main. This PR is ready to review.

@JohannesMeierSE JohannesMeierSE force-pushed the validation-unused-rule-crossreference branch from b05bcac to 359e54e Compare February 17, 2025 08:58
@JohannesMeierSE
Copy link
Contributor Author

FYI: I just resolved conflicts with main. This PR is ready to review.

While this validation looks like a small one, I found this issue in several projects in practice 🙂

@JohannesMeierSE JohannesMeierSE added the validation Validation related issue label Feb 17, 2025
@@ -180,6 +183,67 @@ export class LangiumGrammarCodeActionProvider implements CodeActionProvider {
return undefined;
}

private isRuleReplaceable(rule: ast.ParserRule): boolean {
/** at the moment, only "pure" parser rules are supported:
Copy link
Member

Choose a reason for hiding this comment

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

Question: Do you plan to support more parser rules? I.e. those that should be transformed into interfaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the moment, I don't plan to support more parser rules. In practice, I saw only the handled "simple" cases. I am not sure whether it is worth the effort to support more cases. Do you have some examples we should handle?

@JohannesMeierSE
Copy link
Contributor Author

Thanks @msujew for your review! I just pushed the corresponding fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
validation Validation related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parser rule used as type for cross-reference is marked as "unused"
2 participants