Skip to content

Fix read thread access of bundle files lookup rendering #2439

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

Merged
merged 1 commit into from
Jun 9, 2025
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 @@ -16,6 +16,12 @@ public class SymfonyBundle {
@NotNull
final private PhpClass phpClass;

@NotNull
final private String phpClassName;

@NotNull
private final String phpClassNameNamespaceName;

@NotNull
public PhpClass getPhpClass() {
return this.phpClass;
Expand All @@ -28,11 +34,14 @@ public String getNamespaceName() {

@NotNull
public String getName() {
return this.phpClass.getName();
return this.phpClassName;
}

public SymfonyBundle(@NotNull PhpClass phpClass) {
this.phpClass = phpClass;

this.phpClassName = this.phpClass.getName();
this.phpClassNameNamespaceName = this.phpClass.getNamespaceName();
}

@Nullable
Expand All @@ -41,12 +50,7 @@ public PsiDirectory getDirectory() {
return null;
}

PsiDirectory bundleDirectory = this.phpClass.getContainingFile().getContainingDirectory();
if(null == bundleDirectory) {
return null;
}

return bundleDirectory;
return this.phpClass.getContainingFile().getContainingDirectory();
}

@Nullable
Expand Down Expand Up @@ -78,7 +82,7 @@ public String getRelativePath(@NotNull VirtualFile file) {
}

public boolean isInBundle(@NotNull PhpClass phpClass) {
return phpClass.getNamespaceName().startsWith(this.phpClass.getNamespaceName());
return phpClass.getNamespaceName().startsWith(this.phpClassNameNamespaceName);
}

public boolean isInBundle(@NotNull PsiFile psiFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
import com.intellij.codeInsight.lookup.LookupElementPresentation;
import com.intellij.util.IconUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author Daniel Espendiller <daniel@espendiller.net>
*/
public class SymfonyBundleFileLookupElement extends LookupElement {

private final @NotNull String bundleName;
private final BundleFile bundleFile;
private InsertHandler<LookupElement> insertHandler = null;
private final @Nullable String shortcutName;

public SymfonyBundleFileLookupElement(BundleFile bundleFile) {
this.bundleFile = bundleFile;
this.shortcutName = bundleFile.getShortcutPath();
this.bundleName = bundleFile.getSymfonyBundle().getName();
}

public SymfonyBundleFileLookupElement(BundleFile bundleFile, InsertHandler<LookupElement> insertHandler) {
Expand All @@ -27,23 +31,21 @@ public SymfonyBundleFileLookupElement(BundleFile bundleFile, InsertHandler<Looku
@NotNull
@Override
public String getLookupString() {
String shortcutName = this.bundleFile.getShortcutPath();
if(shortcutName == null) {
if (shortcutName == null) {
return "";
}

// we strip any control char, so only use the pathname
if(shortcutName.startsWith("@")) {
shortcutName = shortcutName.substring(1);
if (shortcutName.startsWith("@")) {
return shortcutName.substring(1);
}

return shortcutName;
}

@Override
public void handleInsert(InsertionContext context) {

if(this.insertHandler != null) {
public void handleInsert(@NotNull InsertionContext context) {
if (this.insertHandler != null) {
this.insertHandler.handleInsert(context, this);
return;
}
Expand All @@ -53,10 +55,8 @@ public void handleInsert(InsertionContext context) {

public void renderElement(LookupElementPresentation presentation) {
presentation.setItemText(getLookupString());
presentation.setTypeText(this.bundleFile.getSymfonyBundle().getName());
presentation.setTypeText(bundleName);
presentation.setTypeGrayed(true);
presentation.setIcon(IconUtil.getIcon(this.bundleFile.getVirtualFile(), 0, this.bundleFile.getProject()));

}

}