Skip to content

Commit

Permalink
fix: allow spaces inside section branch.
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr authored and fbricon committed Jul 8, 2024
1 parent 0cafba7 commit 7b0c9c6
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public void collectDataModel(SearchMatch match, SearchContext context, IProgress

private boolean isApplicable(IField field) {
String fieldTypeName = JDTTypeUtils.getResolvedTypeName(field);
if (fieldTypeName == null) {
return false;
}
for (String typeName : getTypeNames()) {
if (typeName.endsWith(fieldTypeName)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static List<Parameter> parse(int start, int end, ParametersContainer cont
int tokenEnd = scanner.getTokenEnd();
switch (token) {
case Whitespace:
currentParameter = null;
// Do nothing
break;
case ParameterName:
currentParameter = new Parameter(tokenOffset, tokenEnd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ protected TokenType internalScan() {

case WithinParameter: {
if (!methodParameters && splitWithEquals) {
if (stream.skipWhitespace()) {
return finishToken(offset, TokenType.Whitespace);
}
if (stream.advanceIfChar('=')) {
if (!stream.eos() && (stream.peekChar() == ' ' || stream.peekChar() == '=')) {
state = ScannerState.WithinParameters;
} else {
state = ScannerState.AfterAssign;
}
state = ScannerState.AfterAssign;
return finishToken(offset, TokenType.Assign);
}
}
Expand All @@ -105,6 +104,9 @@ protected TokenType internalScan() {
}

case AfterAssign: {
if (stream.skipWhitespace()) {
return finishToken(offset, TokenType.Whitespace);
}
int c = stream.peekChar();
if (c == '"' || c == '\'') {
stream.advance(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,33 @@ public void letSection() {
assertOffsetAndToken(46, TokenType.EOS, "");
}

@Test
public void letSectionWithSpaces() {
// {#let myParent =order.item.parent myPrice= order.price}
scanner = ParameterScanner.createScanner(" myParent =order.item.parent myPrice= order.price");
assertOffsetAndToken(0, TokenType.Whitespace, " ");
assertOffsetAndToken(3, TokenType.ParameterName, "myParent");
assertOffsetAndToken(11, TokenType.Whitespace, " ");
assertOffsetAndToken(13, TokenType.Assign, "=");
assertOffsetAndToken(14, TokenType.ParameterValue, "order.item.parent");
assertOffsetAndToken(31, TokenType.Whitespace, " ");
assertOffsetAndToken(34, TokenType.ParameterName, "myPrice");
assertOffsetAndToken(41, TokenType.Assign, "=");
assertOffsetAndToken(42, TokenType.Whitespace, " ");
assertOffsetAndToken(46, TokenType.ParameterValue, "order.price");
assertOffsetAndToken(57, TokenType.EOS, "");
}

@Test
public void parameterAndAssignOnly() {
// {#let myParent= myPrice=order.price}
scanner = ParameterScanner.createScanner("myParent= myPrice=order.price");
assertOffsetAndToken(0, TokenType.ParameterName, "myParent");
assertOffsetAndToken(8, TokenType.Assign, "=");
assertOffsetAndToken(9, TokenType.Whitespace, " ");
assertOffsetAndToken(10, TokenType.ParameterName, "myPrice");
assertOffsetAndToken(17, TokenType.Assign, "=");
assertOffsetAndToken(18, TokenType.ParameterValue, "order.price");
assertOffsetAndToken(10, TokenType.ParameterValue, "myPrice");
assertOffsetAndToken(17, TokenType.Unknown, "=");
assertOffsetAndToken(18, TokenType.ParameterName, "order.price");
assertOffsetAndToken(29, TokenType.EOS, "");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ public void objectPart() throws Exception {
c("age", "age", r(3, 14, 3, 14)));
}

@Test
public void objectPartWithSpaces() throws Exception {
String template = "{@org.acme.Item item}\r\n" + //
"{#let myParent = item.name isActive =false age= 10} \r\n" + //
" <h1>{myParent.name}</h1>\r\n" + //
" Is active: {|}\r\n" + // <-- completion here
" Age: {age}\r\n" + //
"{/let}";
testCompletionFor(template, //
c("item", "item", r(3, 14, 3, 14)), //
c("myParent", "myParent", r(3, 14, 3, 14)), //
c("isActive", "isActive", r(3, 14, 3, 14)), //
c("age", "age", r(3, 14, 3, 14)));
}

@Test
public void objectPartWithOnlyStartBracket() throws Exception {
String template = "{@org.acme.Item item}\r\n" + //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,33 @@ public void parameterLetSection() throws Exception {
settings);
}

@Test
public void parameterLetSectionWithSpaces() throws Exception {
String template = "{@org.acme.Item item}\r\n" + //
"{#let name =item.name price = item.price bad= item.XXXX}\r\n" + // name[:String]=item.name
// price[:BigInteger]=item.price
// bad=item.XXXX
" \r\n" + //
"{/let}";
testInlayHintFor(template, //
ih(p(1, 10), ihLabel(":"),
ihLabel("String", "Open `java.lang.String` Java type.", cd("java.lang.String"))), //
ih(p(1, 30), ihLabel(":"),
ihLabel("BigInteger", "Open `java.math.BigInteger` Java type.", cd("java.math.BigInteger"))));

// enabled=false
QuteInlayHintSettings settings = new QuteInlayHintSettings();
settings.setEnabled(false);
testInlayHintFor(template, //
settings);

// showSectionParameterType=false
settings = new QuteInlayHintSettings();
settings.setShowSectionParameterType(false);
testInlayHintFor(template, //
settings);
}

@Test
public void parameterCustomSection() throws Exception {
String template = "{@org.acme.Item item}\r\n" + //
Expand Down

0 comments on commit 7b0c9c6

Please sign in to comment.