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

provide checkbox to allow disable cost intensive parameter type provider resolving #2357

Merged
merged 1 commit into from
Apr 27, 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 @@ -59,6 +59,7 @@ public class Settings implements PersistentStateComponent<Settings> {
public boolean codeFoldingTwigTemplate = true;
public boolean codeFoldingTwigConstant = true;
public boolean featureTwigIcon = true;
public boolean featureTypeProvider = true;

public boolean twigBundleNamespaceSupport = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<rowspec value="center:max(d;4px):noGrow"/>
<rowspec value="top:4dlu:noGrow"/>
<rowspec value="center:max(d;4px):noGrow"/>
<rowspec value="top:4dlu:noGrow"/>
<rowspec value="center:max(d;4px):noGrow"/>
<colspec value="fill:max(d;4px):noGrow"/>
<colspec value="left:4dlu:noGrow"/>
<colspec value="fill:d:grow"/>
Expand Down Expand Up @@ -207,7 +209,7 @@
</component>
<component id="58414" class="javax.swing.JLabel" binding="directoryToAppLabel">
<constraints>
<grid row="28" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="30" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties>
Expand All @@ -216,7 +218,7 @@
</component>
<component id="c6525" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="directoryToApp">
<constraints>
<grid row="28" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="30" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
<forms defaultalign-horz="false"/>
Expand All @@ -225,7 +227,7 @@
</component>
<component id="b7268" class="javax.swing.JButton" binding="directoryToAppReset">
<constraints>
<grid row="28" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="30" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties>
Expand All @@ -234,13 +236,23 @@
</component>
<component id="4cd0" class="javax.swing.JLabel">
<constraints>
<grid row="26" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="28" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties>
<text value="Legacy Features"/>
</properties>
</component>
<component id="3c3bc" class="javax.swing.JCheckBox" binding="featureTypeProvider">
<constraints>
<grid row="26" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<forms/>
</constraints>
<properties>
<text value="Type Provider"/>
<toolTipText value="Resolve return type via parameter eg &quot;ContainerInterface::get, EntityManager::find&quot;"/>
</properties>
</component>
</children>
</grid>
<component id="2ef99" class="javax.swing.JCheckBox" binding="pluginEnabled">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class SettingsForm implements Configurable {
private JCheckBox enableSchedulerCheckBox;
private JCheckBox featureTwigIcon;
private JButton buttonAutoConfigure;
private JCheckBox featureTypeProvider;

public SettingsForm(@NotNull final Project project) {
this.project = project;
Expand Down Expand Up @@ -135,6 +136,7 @@ public boolean isModified() {
|| !codeFoldingTwigTemplate.isSelected() == getSettings().codeFoldingTwigTemplate
|| !codeFoldingTwigConstant.isSelected() == getSettings().codeFoldingTwigConstant
|| !featureTwigIcon.isSelected() == getSettings().featureTwigIcon
|| !featureTypeProvider.isSelected() == getSettings().featureTypeProvider

|| !directoryToApp.getText().equals(getSettings().directoryToApp)
|| !directoryToWeb.getText().equals(getSettings().directoryToWeb)
Expand All @@ -156,6 +158,7 @@ public void apply() throws ConfigurationException {
getSettings().codeFoldingTwigTemplate = codeFoldingTwigTemplate.isSelected();
getSettings().codeFoldingTwigConstant = codeFoldingTwigConstant.isSelected();
getSettings().featureTwigIcon = featureTwigIcon.isSelected();
getSettings().featureTypeProvider = featureTypeProvider.isSelected();

getSettings().directoryToApp = directoryToApp.getText();
getSettings().directoryToWeb = directoryToWeb.getText();
Expand Down Expand Up @@ -188,6 +191,7 @@ private void updateUIFromSettings() {
codeFoldingTwigTemplate.setSelected(getSettings().codeFoldingTwigTemplate);
codeFoldingTwigConstant.setSelected(getSettings().codeFoldingTwigConstant);
featureTwigIcon.setSelected(getSettings().featureTwigIcon);
featureTypeProvider.setSelected(getSettings().featureTypeProvider);

directoryToApp.setText(getSettings().directoryToApp);
directoryToWeb.setText(getSettings().directoryToWeb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public char getKey() {
@Nullable
@Override
public PhpType getType(PsiElement e) {
if (!Settings.getInstance(e.getProject()).pluginEnabled || !(e instanceof MethodReference methodReference)) {
if (!(e instanceof MethodReference methodReference)) {
return null;
}

Project project = e.getProject();
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ public char getKey() {
@Nullable
@Override
public PhpType getType(PsiElement e) {
if (!Settings.getInstance(e.getProject()).pluginEnabled) {
// container calls are only on "get" methods
if(!(e instanceof MethodReference methodReference)) {
return null;
}

Project project = e.getProject();
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
return null;
}

// container calls are only on "get" methods
if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "get")) {
if(!PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "get")) {
return null;
}

String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter(methodReference, TRIM_KEY);
return signature == null ? null : new PhpType().add("#" + this.getKey() + signature);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ public char getKey() {
@Nullable
@Override
public PhpType getType(PsiElement e) {
if (!(e instanceof MethodReference methodRef) || !Settings.getInstance(e.getProject()).pluginEnabled) {
if (!(e instanceof MethodReference methodRef)) {
return null;
}

Project project = e.getProject();
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,27 @@ public char getKey() {
@Nullable
@Override
public PhpType getType(PsiElement e) {
if (!Settings.getInstance(e.getProject()).pluginEnabled) {
if(!(e instanceof MethodReference methodReference)) {
return null;
}

if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "find")) {
Project project = e.getProject();
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
return null;
}

String refSignature = ((MethodReference)e).getSignature();
if(!PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "find")) {
return null;
}

String refSignature = methodReference.getSignature();
if(StringUtil.isEmpty(refSignature)) {
return null;
}

// we need the param key on getBySignature(), since we are already in the resolved method there attach it to signature
// param can have dotted values split with \
PsiElement[] parameters = ((MethodReference)e).getParameters();
PsiElement[] parameters = methodReference.getParameters();
if (parameters.length >= 2) {
String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
if(signature != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public char getKey() {
@Nullable
@Override
public PhpType getType(PsiElement e) {
if (!(e instanceof MethodReference methodRef) || !Settings.getInstance(e.getProject()).pluginEnabled) {
if (!(e instanceof MethodReference methodRef)) {
return null;
}

Project project = e.getProject();
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,20 @@ public char getKey() {
@Nullable
@Override
public PhpType getType(PsiElement e) {
if (!Settings.getInstance(e.getProject()).pluginEnabled) {
if(!(e instanceof MethodReference methodReference)) {
return null;
}

if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "getRepository")) {
Project project = e.getProject();
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
return null;
}

if(!PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "getRepository")) {
return null;
}

String refSignature = ((MethodReference)e).getSignature();
String refSignature = methodReference.getSignature();
if(StringUtil.isEmpty(refSignature)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,26 @@ public char getKey() {
@Nullable
@Override
public PhpType getType(PsiElement e) {
if (!Settings.getInstance(e.getProject()).pluginEnabled) {
if(!(e instanceof MethodReference methodReference)) {
return null;
}

Project project = e.getProject();
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
return null;
}

// container calls are only on "get" methods
if(!(e instanceof MethodReference) || !"dispatch".equals(((MethodReference) e).getName())) {
if(!"dispatch".equals(methodReference.getName())) {
return null;
}

PsiElement[] parameters = ((MethodReference) e).getParameters();
PsiElement[] parameters = methodReference.getParameters();
if(parameters.length < 2) {
return null;
}

String refSignature = ((MethodReference) e).getSignature();
String refSignature = methodReference.getSignature();
if(StringUtils.isBlank(refSignature)) {
return null;
}
Expand Down
Loading