Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Add new Xtext editor quickfixes on *.xtext files #1448

Closed
miklossy opened this issue May 12, 2020 · 26 comments
Closed

Add new Xtext editor quickfixes on *.xtext files #1448

miklossy opened this issue May 12, 2020 · 26 comments

Comments

@miklossy
Copy link
Contributor

miklossy commented May 12, 2020

The Xtext editor should provide the following quickfixes on *.xtext files:

  • Provide quickfixes for illegal rule references (see #331943)
  • Provide quickfixes for illegal hidden token definitions (see #331942)
  • Provide more quickfixes for missing rules (see #331941)

@loradd Would you like to take care of this issue?

@nbhusare
Copy link
Contributor

@miklossy I would like to work on this issue. Kindly let me know if that is ok.

@miklossy
Copy link
Contributor Author

@nbhusare Would be awesome if you could take care of this issue. Thanks a lot in advance!

@loradd
Copy link
Contributor

loradd commented May 28, 2020

@miklossy sorry for the late reply!
I could also work on this, @nbhusare let me know if you need support.

@miklossy
Copy link
Contributor Author

Thanks for your reply @loradd . I would sugges that @nbhusare will take care of this issue, for you @loradd I created a similar one to the Xtend repository: eclipse/xtext-xtend#1060 . Please comment on that issue if you could take care of that one. Thanks!

@miklossy miklossy added this to the Release_2.23 milestone May 29, 2020
@nbhusare
Copy link
Contributor

nbhusare commented Jun 10, 2020

@cdietrich cdietrich assigned szarnekow and unassigned szarnekow Jun 22, 2020
@nbhusare
Copy link
Contributor

nbhusare commented Jul 1, 2020

@szarnekow - The method XtextGrammarQuickfixProvider.fixUnresolvedRule(Issue, IssueResolutionAcceptor), on line 144, specifically gets a container of type ParserRule. Yet, on line 149, it checks if the if (abstractRule instanceof TerminalRule). I looked at the history (PS comment below) and I don't understand it. Could you please confirm if the code on line 149 is required?

Comment from history - Use textual modification instead of semantic modification for new parser rules as serialization / comment location preserving is to fragile for invalid models

@szarnekow
Copy link
Contributor

@szarnekow - The method XtextGrammarQuickfixProvider.fixUnresolvedRule(Issue, IssueResolutionAcceptor), on line 144, specifically gets a container of type ParserRule. Yet, on line 149, it checks if the if (abstractRule instanceof TerminalRule). I looked at the history (PS comment below) and I don't understand it. Could you please confirm if the code on line 149 is required?

It's a bug. It should probably get a container of type AbstractRule in line 144.

@nbhusare
Copy link
Contributor

nbhusare commented Jul 6, 2020

@szarnekow I have replaced the existing PR's with new ones. I have addressed the review comments in the same. Kindly have a look.

@nbhusare
Copy link
Contributor

@miklossy We have merged the PR's. Could you please close this issue. Tx

@miklossy
Copy link
Contributor Author

Thanks for your contibution @nbhusare ! I would like to try out the new quickfixes before closing this issue.

@miklossy
Copy link
Contributor Author

miklossy commented Jul 20, 2020

@nbhusare I took a look at the current state of the fix and found the following shortcomings:

  • In some cases, the Convert terminal fragment to terminal rule quickfix is offered but has no effect:
    screencast

  • Did you fix the bug #331941 completely? E.g. the Create terminal rule quickfix is not offered where it should be:
    screenshot

  • Would be awesome if you could add some words about this fix to the release notes, see [2020-09] create release notes xtext#1786

@nbhusare
Copy link
Contributor

@miklossy Let me take a look at the above.

@nbhusare
Copy link
Contributor

nbhusare commented Jul 21, 2020

@miklossy I have raised a PR (xtext-eclipse/pull/1492) to address the first issue you reported above. For the second one, to show the two quick-fixes proposals (Create terminal..., Create terminal fragment...), I added the annotation @Fix(XtextLinkingDiagnosticMessageProvider.UNRESOLVED_RULE) on the methods fixUnresolvedTerminalRule(), and fixUnresolvedTerminalFragmentRule(), and also enhanced the method createNewRule(); however, it adds multiple "Change to 'XXX'" proposals in addition to the required ones. Is there a way to only show one "Change to 'XXX'" proposal?

image

@cdietrich
Copy link
Member

@nbhusare why are there 3 quickfixed created at all?
how to reproduce this?

@miklossy
Copy link
Contributor Author

Thanks @cdietrich for jumping in and taking over!

@nbhusare
Copy link
Contributor

@cdietrich Sorry, by 3 quick-fixes do you mean the "Change to 'PQR'" ones, or the Create XX ones?
To reproduce the issue, please add annotation @Fix(XtextLinkingDiagnosticMessageProvider.UNRESOLVED_RULE) to the methods fixUnresolvedTerminalRule(), and fixUnresolvedTerminalFragmentRule() in XtextGrammarQuickFixProvider. Please use Model: a=ID2 grammar as an example.

@cdietrich
Copy link
Member

if you call createLinkingIssueResolutions three times and dont filter the typo fixes then of course you get 3 fixes

@nbhusare
Copy link
Contributor

@cdietrich Tx for the tip. Let me take a look.

@nbhusare
Copy link
Contributor

nbhusare commented Jul 24, 2020

@cdietrich @szarnekow I came across the following issues while working on this task. Please have a look.
Also filed jiras - https://bugs.eclipse.org/bugs/show_bug.cgi?id=565523, https://bugs.eclipse.org/bugs/show_bug.cgi?id=565524 respectively.

  1. In the grammar below, the quick-fix "Remove Hidden token definition" fails with the below error. The serializer is failing while it tries to serialize the broken reference name=IDX
Model hidden(ModelA):  // Reference to a parser-rule
    name=IDX; //IDX is not defined yet
ModelA:
    name=ID;
java.lang.RuntimeException: Could not serialize RuleCall:
RuleCall.rule is required to have a value, but it does not.
Semantic Object: Grammar'org.xtext.example.mydsl.MyDsl'.rules[0]->ParserRule'Model'.alternatives->Assignment.terminal->RuleCall
URI: platform:/resource/org.xtext.example.mydsl/src/org/xtext/example/mydsl/MyDsl.xtext
Context: AssignableTerminal returns RuleCall
  1. In the below grammar, for the hidden token A, I get three proposals - Change to B, Convert terminal fragment to terminal rule, and Remove hidden token definition. In the method XtextValidator#checkHiddenTokenIsNotAFragment(), the number of hidden tokens returned is one, even though we have two tokens defined (one has a broken reference). The index value that is passed to the call to addIssue() is 0, and as a side-effect, we see three proposals for the hidden token definition. In short, the proposals shown (at least the second and the third) applicable to the hidden token B are displayed for the token A.

Now, if I choose the proposal "Remove hidden token definition", all the tokens get removed. Proposal "Change to B" works, but it doesn't make sense since B is a terminal fragment. "Convert terminal Fragment to terminal rule" does not make sense either.

Model hidden(A, B):
	name=ID;
terminal fragment B:
	'b';

@cdietrich
Copy link
Member

ping @szarnekow

@nbhusare
Copy link
Contributor

Would be awesome if you could add some words about this fix to the release notes, see eclipse/xtext#1786
@miklossy Do you want me to add the details as a comment in the jira or directly to the 2020-09-01-version-2-23-0.md file?

@miklossy
Copy link
Contributor Author

Directly to the 2020-09-01-version-2.23.md file with a Pull Request

@nbhusare
Copy link
Contributor

@cdietrich
Copy link
Member

@miklossy what is the state of this issue?

@cdietrich
Copy link
Member

@miklossy @nbhusare is there anything left?

@cdietrich
Copy link
Member

i assume this fixed. if there is anything left, please create a new issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants