Skip to content

Commit

Permalink
Fixed #135 For iterator index variable is not proposed by the complet…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
ylussaud committed Feb 14, 2024
1 parent 237b2bc commit dca827f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.eclipse.acceleo.aql.completion.proposals.templates.AcceleoCodeTemplateCompletionProposalsProvider;
import org.eclipse.acceleo.aql.completion.proposals.templates.AcceleoCodeTemplates;
import org.eclipse.acceleo.aql.parser.AcceleoParser;
import org.eclipse.acceleo.aql.validation.AcceleoValidator;
import org.eclipse.acceleo.aql.validation.IAcceleoValidationResult;
import org.eclipse.acceleo.query.parser.AstCompletor;
import org.eclipse.acceleo.query.runtime.ICompletionProposal;
Expand Down Expand Up @@ -577,6 +578,10 @@ private Map<String, Set<IType>> getVariables(AcceleoASTNode scope) {
} else if (currentScope instanceof ForStatement) {
final ForStatement forStatement = (ForStatement)currentScope;
res.put(forStatement.getBinding().getName(), getPossibleTypes(forStatement.getBinding()));
final Set<IType> possibleIndexTypes = new LinkedHashSet<>();
possibleIndexTypes.add(new ClassType(queryEnvironment, Integer.class));
res.put(forStatement.getBinding().getName() + AcceleoValidator.INDEX_SUFFIX,
possibleIndexTypes);
}

if (currentScope.eContainer() instanceof AcceleoASTNode) {
Expand Down Expand Up @@ -615,7 +620,7 @@ private LinkedHashSet<IType> getPossibleTypes(Variable variable) {
* the {@link Variable}
* @return the {@link Set} of possible {@link IType} for the given {@link Variable}
*/
private LinkedHashSet<IType> getPossibleTypes(Binding binding) {
private Set<IType> getPossibleTypes(Binding binding) {
final LinkedHashSet<IType> res;

if (binding.getInitExpression() != null) {
Expand Down Expand Up @@ -653,8 +658,10 @@ public List<AcceleoCompletionProposal> caseErrorBinding(ErrorBinding errorBindin
.getMissingAffectationSymbole() + SPACE, AcceleoPackage.Literals.BINDING));
} else if (errorBinding.getInitExpression().getAst()
.getAst() instanceof org.eclipse.acceleo.query.ast.Error) {
res.addAll(this.getAqlCompletionProposals(getVariables(errorBinding), acceleoValidationResult
.getValidationResult(errorBinding.getInitExpression().getAst())));
final AcceleoASTNode context = (AcceleoASTNode)errorBinding.eContainer()
.eContainer();
res.addAll(this.getAqlCompletionProposals(getVariables(context), acceleoValidationResult.getValidationResult(errorBinding
.getInitExpression().getAst())));
}

return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ myParam
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
myVariable
* Description:
Variable myVariable
* Text:
myVariable
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
ecore::EAnnotation
* Description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ myVariable
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
myVariableIndex
* Description:
Variable myVariableIndex
* Text:
myVariableIndex
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
ecore::EAnnotation
* Description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ myParam
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
myVariable
* Description:
Variable myVariable
* Text:
myVariable
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
ecore::EAnnotation
* Description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ myVariable3
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
myVariable3Index
* Description:
Variable myVariable3Index
* Text:
myVariable3Index
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
myVariable4
* Description:
Expand All @@ -43,6 +52,15 @@ myVariable4
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
myVariable4Index
* Description:
Variable myVariable4Index
* Text:
myVariable4Index
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
ecore::EAnnotation
* Description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ myVariable
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
myVariableIndex
* Description:
Variable myVariableIndex
* Text:
myVariableIndex
* Type (optional):
http://www.eclipse.org/acceleo/4.0#//Expression

* Label:
ecore::EAnnotation
* Description:
Expand Down

0 comments on commit dca827f

Please sign in to comment.