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

fix: allow spaces inside section branch. #965

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}";
fbricon marked this conversation as resolved.
Show resolved Hide resolved
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}";
fbricon marked this conversation as resolved.
Show resolved Hide resolved
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
Loading