Skip to content

Commit

Permalink
Improved AQL completion for EClassifier and EEnumLiteral.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Feb 27, 2024
1 parent 7a6aedb commit 3e89f61
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ public List<ICompletionProposal> caseErrorCall(ErrorCall object) {
} else {
final Expression firstArg = object.getArguments().get(1);
if (firstArg instanceof Lambda) {
result.add(new TextCompletionProposal(", ", 0));
result.add(new TextCompletionProposal(")", 0));
final Lambda lambda = (Lambda)firstArg;
result.addAll(getExpressionTextFollows(validationResult.getPossibleTypes(lambda
.getExpression())));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015 Obeo.
* Copyright (c) 2015, 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -102,7 +102,8 @@ private String getPrefix(String expression, int offset) {
int start = offset;
while (start - 1 >= 0) {
char charAt = expression.charAt(start - 1);
if (Character.isLetter(charAt) || Character.isDigit(charAt) || charAt == '_' || charAt == ':') {
if (Character.isLetter(charAt) || Character.isDigit(charAt) || charAt == '_'
|| charAt == ':') {
--start;
} else {
break;
Expand All @@ -111,6 +112,27 @@ private String getPrefix(String expression, int offset) {
final String prefix = expression.substring(start, offset);
if (COLON.equals(prefix)) {
result = "";
} else if (!prefix.endsWith(COLON)) {
// special case of valid EClassifier and EEnumLiteral
final String[] splited = prefix.split(COLON + COLON);
if (splited.length == 2) {
// EClassifier
if (!queryEnvironment.getEPackageProvider().getTypes(splited[0], splited[1]).isEmpty()) {
result = "";
} else {
result = prefix;
}
} else if (splited.length == 3) {
// EEnumLiteral
if (!queryEnvironment.getEPackageProvider().getEnumLiterals(splited[0], splited[1],
splited[2]).isEmpty()) {
result = "";
} else {
result = prefix;
}
} else {
result = prefix;
}
} else {
result = prefix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3446,4 +3446,30 @@ public void enumLiteralInSelectWithMissingClosingParenthesis() {
.getArguments().get(1));
}

@Test
public void enumLiteralInSelectWithMissingClosingParenthesisAfterCall() {
AstResult build = engine.build("self.toString()->select(s | s = anydsl::Color::black");
Expression ast = build.getAst();

assertEquals(1, build.getErrors().size());
assertEquals(Diagnostic.ERROR, build.getDiagnostic().getSeverity());
assertExpression(build, ErrorCall.class, 0, 0, 0, 52, 0, 52, ast);
assertEquals("select", ((ErrorCall)ast).getServiceName());
assertFalse(((ErrorCall)ast).isSuperCall());
assertTrue(((ErrorCall)ast).isMissingEndParenthesis());
assertEquals(CallType.COLLECTIONCALL, ((ErrorCall)ast).getType());
assertEquals(2, ((ErrorCall)ast).getArguments().size());
assertExpression(build, Call.class, 0, 0, 0, 15, 0, 15, ((ErrorCall)ast).getArguments().get(0));
assertExpression(build, Lambda.class, 24, 0, 24, 52, 0, 52, ((ErrorCall)ast).getArguments().get(1));
final Lambda lambda = (Lambda)((ErrorCall)ast).getArguments().get(1);
assertExpression(build, Call.class, 28, 0, 28, 52, 0, 52, lambda.getExpression());
assertFalse(((Call)lambda.getExpression()).isSuperCall());
assertEquals("equals", ((Call)lambda.getExpression()).getServiceName());
assertEquals(2, ((Call)lambda.getExpression()).getArguments().size());
assertExpression(build, VarRef.class, 28, 0, 28, 29, 0, 29, ((Call)lambda.getExpression())
.getArguments().get(0));
assertExpression(build, EnumLiteral.class, 32, 0, 32, 52, 0, 52, ((Call)lambda.getExpression())
.getArguments().get(1));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,22 @@ public void testBindingCompletionWithErrorType() {
}

@Test
public void testBindingCompletionWithTypeNoSpace() {
final ICompletionResult completionResult = engine.getCompletion("let a : ecore::EClass", 21,
public void testBindingCompletionWithInvalidTypeNoSpace() {
final ICompletionResult completionResult = engine.getCompletion("let a : ecore::EClas", 20,
variableTypes);

assertCompletion(completionResult, 2, "ecore::EClass", "", 8, 13, "ecore::EClass",
assertCompletion(completionResult, 2, "ecore::EClas", "", 8, 12, "ecore::EClass",
"ecore::EClassifier");
}

@Test
public void testBindingCompletionWithValidTypeNoSpace() {
final ICompletionResult completionResult = engine.getCompletion("let a : ecore::EClass", 21,
variableTypes);

assertCompletion(completionResult, 1, "", "", 21, 0, "= ");
}

@Test
public void testBindingCompletionWithTypeAndSpace() {
final ICompletionResult completionResult = engine.getCompletion("let a : ecore::EClass ", 22,
Expand Down Expand Up @@ -1032,7 +1040,7 @@ public void missingClosingParenthesisIterationCallNoArguments_465037() {

final ICompletionResult completionResult = engine.getCompletion("self->select(a | true ", 22, types);

assertCompletion(completionResult, 11, "", "", 22, 0, "and ", "or ", "implies ");
assertCompletion(completionResult, 13, "", "", 22, 0, "and ", "or ", "implies ", ")", ", ");
assertNoVariableCompletionProposal(completionResult);
assertNoVariableDeclarationCompletionProposal(completionResult);
assertNoFeatureCompletionProposal(completionResult);
Expand Down Expand Up @@ -1414,6 +1422,14 @@ public void dynamicEOperation() {
assertCompletion(completionResult, 1, "dynamicEOper", "", 5, 12, "dynamicEOperation()");
}

@Test
public void enumLiteralInSelectWithMissingClosingParenthesisAfterCall() {
final ICompletionResult completionResult = engine.getCompletion(
"self.toString()->select(s | s = anydsl::Color::black", 52, variableTypes);

assertCompletion(completionResult, 13, "", "", 52, 0, ")", ", ");
}

public static void assertCompletion(ICompletionResult completionResult, int size, String prefix,
String suffix, int replacementOffset, int replacementLength, String... proposalStrings) {
final List<ICompletionProposal> proposals = completionResult.getProposals(new BasicFilter(
Expand Down

0 comments on commit 3e89f61

Please sign in to comment.