Skip to content

Commit

Permalink
Fixed auto-complete (disabled in strings, more improvements)
Browse files Browse the repository at this point in the history
  • Loading branch information
mesour committed Feb 18, 2020
1 parent 1939fe2 commit 086f771
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 26 deletions.
Binary file modified latte-plugin.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<p>1.0.2</p>
<ul>
<li>added code style settings (settings for use tabs or spaces) (issue #46, #30)</li>
<li>added support for define variable in tag {default $foo}</li>
<li>added support for define variable in tag {default $foo = 123}</li>
<li>added class namespaces completion</li>
<li>added support for define variables by {php [$foo, $bar] = $arr}</li>
<li>implemented some performance improvements</li>
Expand All @@ -30,6 +30,7 @@
<li>fixed filters on variables (issue #47)</li>
<li>fixed wrong indent for elseifset (issue #42)</li>
<li>fixed multiple variable definitions in for/foreach cycles</li>
<li>fixed auto-complete (disabled in strings, more improvements)</li>
<li>increased minimum compatibility to 2018.3</li>
</ul>
<p>1.0.1</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ protected void addCompletions(@NotNull CompletionParameters parameters, Processi
return;
}

LatteMacro macro = LatteConfiguration.INSTANCE.getMacro(element.getProject(), macroClassic.getOpenTag().getMacroName());
if (macro == null || !macro.allowedModifiers) {
return;
if (!((LatteMacroModifier) element).isVariableModifier()) {
LatteMacro macro = LatteConfiguration.INSTANCE.getMacro(element.getProject(), macroClassic.getOpenTag().getMacroName());
if (macro == null || !macro.allowedModifiers) {
return;
}
}

Map<String, LatteModifier> customModifiers = LatteConfiguration.INSTANCE.getCustomModifiers(element.getProject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ protected void addCompletions(
} else if (element instanceof LattePhpProperty || (element instanceof LattePhpMethod && !((LattePhpMethod) element).isStatic())) {
attachPhpCompletions(result, (BaseLattePhpElement) element, false);

} else {
} else if (!(element instanceof LatteMacroModifier) && !(element instanceof LattePhpString)) {
classCompletionProvider.addCompletions(parameters, context, result);
namespaceCompletionProvider.addCompletions(parameters, context, result);

if (LatteUtil.matchParentMacroName(element, "varType") || LatteUtil.matchParentMacroName(element, "var")) {
attachVarTypes(result);
}

if (!(element instanceof LatteMacroModifier)) {
classCompletionProvider.addCompletions(parameters, context, result);
} else {
variableCompletionProvider.addCompletions(parameters, context, result);
functionCompletionProvider.addCompletions(parameters, context, result);
namespaceCompletionProvider.addCompletions(parameters, context, result);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/com/jantvrdik/intellij/latte/parser/LatteParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@ phpMethodDefinition ::= T_WHITESPACE? (T_PHP_DOUBLE_COLON | T_PHP_OBJECT_O
private
phpArgumentList ::= (T_PHP_LEFT_NORMAL_BRACE T_WHITESPACE? T_PHP_RIGHT_NORMAL_BRACE) | (T_PHP_LEFT_NORMAL_BRACE phpMethodArgs T_PHP_RIGHT_NORMAL_BRACE)

private
phpInBrackets ::= T_PHP_LEFT_NORMAL_BRACE T_WHITESPACE? phpArgument+ T_WHITESPACE? T_PHP_RIGHT_NORMAL_BRACE

phpMethodArgs ::= T_WHITESPACE? phpArgument+ ( T_WHITESPACE? "," T_WHITESPACE? phpArgument+ )* T_WHITESPACE?

phpString ::= phpSingleQuotedString | phpDoubleQuotedString | T_MACRO_ARGS_STRING

private
phpArgument ::= phpSingleQuotedString | phpDoubleQuotedString | T_MACRO_ARGS_STRING | T_MACRO_ARGS_NUMBER | phpArrayOfVariables | phpClass | phpDefinition
phpArgument ::= phpString | T_MACRO_ARGS_NUMBER | phpArrayOfVariables | phpClass | phpDefinition
| phpStatic | phpFunctionCall | phpInBrackets | phpVariable | T_PHP_CONTENT_TYPE | T_PHP_OBJECT_OPERATOR
| T_PHP_OPERATOR | T_PHP_DOUBLE_COLON | T_PHP_DOUBLE_ARROW | T_PHP_METHOD | T_PHP_TYPE | T_PHP_KEYWORD
| T_PHP_CLASS | T_PHP_AS | T_PHP_CAST | T_PHP_EXPRESSION | T_PHP_LEFT_BRACKET | T_PHP_RIGHT_BRACKET | T_PHP_NULL
Expand Down
17 changes: 2 additions & 15 deletions src/com/jantvrdik/intellij/latte/psi/impl/LattePsiImplUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,8 @@ public static String getModifierName(@NotNull LatteMacroModifier element) {
}

public static boolean isVariableModifier(@NotNull LatteMacroModifier element) {
PsiElement prevElement = PsiTreeUtil.skipWhitespacesBackward(element);
PsiElement nextElement = PsiTreeUtil.skipWhitespacesForward(element);
if (
prevElement != null && nextElement != null
&& prevElement.getNode().getElementType().equals(LatteTypes.T_PHP_OR_INCLUSIVE)
) {
LattePhpVariable prevVariable = PsiTreeUtil.getPrevSiblingOfType(prevElement, LattePhpVariable.class);
if (prevVariable != null) {
PsiElement beforeVariable = prevVariable.getPrevSibling();
if (beforeVariable != null && beforeVariable.getNode().getElementType().equals(LatteTypes.T_PHP_LEFT_NORMAL_BRACE)) {
return true;
}
}
}
return false;
LattePhpInBrackets variableModifier = PsiTreeUtil.getParentOfType(element, LattePhpInBrackets.class);
return variableModifier != null;
}

@Nullable
Expand Down

0 comments on commit 086f771

Please sign in to comment.