-
Notifications
You must be signed in to change notification settings - Fork 890
Added bracket highlighting for generic angle brackets #8500
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
base: master
Are you sure you want to change the base?
Conversation
@@ -428,7 +520,7 @@ public static List<TokenSequence<?>> getEmbeddedTokenSequences( | |||
for(int i = sequences.size() - 1; i >= 0; i--) { | |||
TokenSequence<?> seq = sequences.get(i); | |||
if (seq.language() == language) { | |||
break; | |||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this. I left a few inline comments, but this needs at least another round. The current state works for simple cases, but fails at others.
I also noticed that comparisons are marked as error:
Bitshifts also look broken:
It might be necessary to create a brace matcher that does not report errors for type braces, but only the matches. Or you'd need to find a marker where to stop scanning.
@@ -428,7 +520,7 @@ public static List<TokenSequence<?>> getEmbeddedTokenSequences( | |||
for(int i = sequences.size() - 1; i >= 0; i--) { | |||
TokenSequence<?> seq = sequences.get(i); | |||
if (seq.language() == language) { | |||
break; | |||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unnessary and wrong as already indicated by @essien. Please remove.
@@ -98,13 +99,13 @@ public int[] findOrigin() throws BadLocationException, InterruptedException { | |||
context.getLimitOffset(), | |||
PAIRS | |||
); | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove space at end of lines (see lines 102, 108, 150, 154, 160)
if (sq.token().id() == JavaTokenId.GTGTGT) { | ||
if (originId == JavaTokenId.GT) { | ||
if (originOffset != sq.offset()) { | ||
int test = sq.offset(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stray test code?
assertMatches2("Map^<Class<? extends AbstractStudent>, Map<CourseTime, List<? extends AbstractCourse>>^>"); | ||
assertMatches2("Map<Class<? extends AbstractStudent>, Map^<CourseTime, List<? extends AbstractCourse>^>>"); | ||
assertMatches2("Map x = new HashMap<String, List^<String^>>()"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs more test cases. I added some and hit a bug:
assertMatches2("^<test^>");
assertMatches2("Map^<Class<? extends AbstractStudent>, Map<CourseTime, List<? extends AbstractCourse>>^>");
assertMatches2("Map<Class<? extends AbstractStudent>, Map^<CourseTime, List<? extends AbstractCourse>^>>");
assertMatches2("Map<Class<? extends AbstractStudent>, Map<CourseTime, List^<? extends AbstractCourse^>>>");
assertMatches2("Map<Class^<? extends AbstractStudent^>, Map<CourseTime, List<? extends AbstractCourse>>>");
assertMatches2("Map^<Map<CourseTime, List<? extends AbstractCourse>>, Class<? extends AbstractStudent>^>");
assertMatches2("Map<Map^<CourseTime, List<? extends AbstractCourse>^>, Class<? extends AbstractStudent>>");
assertMatches2("Map<Map<CourseTime, List^<? extends AbstractCourse^>>, Class<? extends AbstractStudent>>");
assertMatches2("Map<Map<CourseTime, List<? extends AbstractCourse>>, Class^<? extends AbstractStudent^>>");
assertMatches2("Map x = new HashMap<String, List^<String^>>()");
assertMatches2("Map x = new HashMap^<String, List<String>^>()");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I also add that <>
should match in the below:
class LinkedList < T extends Object & Serializable > {
}
but <>
should not match in the below:
int Object = 2;
int Serializable = 3;
boolean result = 1 < Object & Serializable > 4;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there needs to be some way to differentiate generic brackets from comparison/operator brackets.
/* One idea was to modify the input TokenHierachy to split | ||
** GTGT tokens into 2 separate GT and GT tokens. However, | ||
** it seems like almost all token related classes are immutable | ||
** or inaccessible due to private constructors. Leading me to | ||
** write this. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TokenHierarchy/-sequence represents the lexing result and yes, for analysis they are read-only. This comment gives reasoning for the current implementation, but reads more like "note to self", then intentional for others.
} | ||
} | ||
|
||
//Shouldn't happen, but added it anyways. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that this refers to the fact, that after each opening brace a type must be placed? I mean List<TYPE
?
if (sq.token().id() == JavaTokenId.GTGT) { | ||
if (originId == JavaTokenId.GT) { | ||
if (originOffset != sq.offset()) { | ||
counter += (originOffset - sq.offset()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the idea here. Why is the originOffset
used here? Shouldn't count
just count the number of unmatched braces?
Thank you for taking your time to build and review this. I genuinely appreciate the feedback. |
#5024
Added bracket highlighting for generic angle brackets.
Includes a couple of new unit tests.
The biggest hurdle is that bit wise shift operators get tokenized by the lexer. The simplest solution would be to take the input TokenHierarchy and split GTGT tokens into separate GT tokens.
But after diving into the lexer module, it seems that almost all token related classes are either immutable or contain package-private constructors. If there's a way that TokenHierarchy can be modified, I would genuinely like to learn how.
Otherwise, I've opted to add an algorithm that specifically handles angle brackets while managing the counter and offsets accordingly.
Thank you to matthiasblaesing for showing where the appropriate files are and the lexer token stream.
^Add meaningful description above
Click to collapse/expand PR instructions
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
Please make sure (eg.
git log
) that all commits have a valid name and email address for you in the Author field.If you're a first time contributor, see the Contributing guidelines for more information.
If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
PR approval and merge checklist:
If this PR targets the delivery branch: don't merge. (full wiki article)