Skip to content

Commit

Permalink
Merge changes from Haehnchen#1357
Browse files Browse the repository at this point in the history
(Overwrite XML injection with plain text for Console output methods)
  • Loading branch information
King2500 committed Aug 6, 2019
1 parent e9ca3d3 commit c257b50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,29 @@ public class ParameterLanguageInjector implements MultiHostInjector {
new MethodParameterSignature("\\Psr\\Log\\Test\\TestLogger", "hasDebugThatMatches", 0),
};

private static final MethodParameterSignature[] RESET_INJECTION_SIGNATURES = {
new MethodParameterSignature("\\Symfony\\Component\\Console\\Output\\OutputInterface", "write", 0),
new MethodParameterSignature("\\Symfony\\Component\\Console\\Output\\OutputInterface", "writeln", 0),
new MethodParameterSignature("\\Symfony\\Component\\Console\\Formatter\\OutputFormatter", "escape", 0),
new MethodParameterSignature("\\Symfony\\Component\\Console\\Formatter\\OutputFormatter", "escapeTrailingBackslash", 0),
new MethodParameterSignature("\\Symfony\\Component\\Console\\Formatter\\OutputFormatterInterface", "format", 0),
};

private final MethodLanguageInjection[] LANGUAGE_INJECTIONS = {
new MethodLanguageInjection(LANGUAGE_ID_CSS, "@media all { ", " }", CSS_SELECTOR_SIGNATURES),
new MethodLanguageInjection(LANGUAGE_ID_XPATH, null, null, XPATH_SIGNATURES),
new MethodLanguageInjection(LANGUAGE_ID_JSON, null, null, JSON_SIGNATURES),
new MethodLanguageInjection(LANGUAGE_ID_DQL, null, null, DQL_SIGNATURES),
new MethodLanguageInjection(LANGUAGE_ID_PHPREGEXP, null, null, PHPREGEXP_SIGNATURES),
new MethodLanguageInjection(LANGUAGE_ID_TEXT, null, null, RESET_INJECTION_SIGNATURES),
};

public static final String LANGUAGE_ID_CSS = "CSS";
public static final String LANGUAGE_ID_XPATH = "XPath";
public static final String LANGUAGE_ID_JSON = "JSON";
public static final String LANGUAGE_ID_DQL = "DQL";
public static final String LANGUAGE_ID_PHPREGEXP = "PhpRegExp";
public static final String LANGUAGE_ID_TEXT = "TEXT";

private static final String DQL_VARIABLE_NAME = "dql";

Expand Down Expand Up @@ -138,6 +148,10 @@ public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull
MethodMatcher.CallToSignature callToSignature = new MethodMatcher.CallToSignature(signature.getClassName(), signature.getMethodName());
MethodMatcher.MethodMatchParameter matchParameter = MethodMatcher.getMatchedSignatureWithDepth(psiNearestParameter, new MethodMatcher.CallToSignature[]{callToSignature}, signature.getParameterIndex());
if (matchParameter != null) {
// Only "overwrite" language injection to "TEXT" when XML-like characters in literal
if (LANGUAGE_ID_TEXT.equals(language.getID()) && !expr.getContents().contains("<")) {
return;
}
injectLanguage(registrar, expr, language, languageInjection);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
<codeInsight.parameterNameHints language="XML" implementationClass="fr.adrienbrault.idea.symfony2plugin.dic.ServiceArgumentParameterHintsProvider"/>
<codeInsight.parameterNameHints language="yaml" implementationClass="fr.adrienbrault.idea.symfony2plugin.dic.ServiceArgumentParameterHintsProvider"/>

<multiHostInjector implementation="fr.adrienbrault.idea.symfony2plugin.lang.ParameterLanguageInjector"/>
<multiHostInjector implementation="fr.adrienbrault.idea.symfony2plugin.lang.ParameterLanguageInjector" order="first"/>

<localInspection groupPath="Symfony" shortName="PhpRouteMissingInspection" displayName="Route Missing"
groupName="Route"
Expand Down

0 comments on commit c257b50

Please sign in to comment.