Skip to content
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 @@ -5,7 +5,8 @@

package com.magento.idea.magento2plugin.actions.generation.generator;

import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
Expand Down Expand Up @@ -68,7 +69,7 @@ public PhpFileGenerator(
public PsiFile generate(final @NotNull String actionName) {
file = getFile();

final PhpClass phpClass = ReadAction.compute(() ->
final PhpClass phpClass = ApplicationManager.getApplication().runReadAction((Computable<PhpClass>) () ->
GetPhpClassByFQN.getInstance(project).execute(file.getClassFqn())
);

Expand All @@ -78,7 +79,7 @@ public PsiFile generate(final @NotNull String actionName) {
return phpClass.getContainingFile();
}

final PsiDirectory moduleDirectory = ReadAction.compute(() ->
final PsiDirectory moduleDirectory = ApplicationManager.getApplication().runReadAction((Computable<PsiDirectory>) () ->
moduleIndex.getModuleDirectoryByModuleName(file.getModuleName())
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
package com.magento.idea.magento2plugin.actions.generation.generator.util;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.PsiDirectory;
import com.magento.idea.magento2plugin.actions.generation.generator.data.ModuleDirectoriesData;
import com.magento.idea.magento2plugin.magento.packages.File;
Expand Down Expand Up @@ -64,7 +64,9 @@ public PsiDirectory findOrCreateSubdirectory(
final @NotNull PsiDirectory parent,
final @NotNull String subdirName
) {
final PsiDirectory sub = ReadAction.compute(() -> parent.findSubdirectory(subdirName));
final PsiDirectory sub = ApplicationManager.getApplication().runReadAction(
(Computable<PsiDirectory>) () -> parent.findSubdirectory(subdirName)
);
return sub == null ? createSubdirectoryOnEdt(parent, subdirName) : sub;
}

Expand All @@ -85,7 +87,9 @@ public PsiDirectory findOrCreateSubdirectories(

for (final String directory : Arrays.asList(directories)) {
if (lastDirectory == null) {
final PsiDirectory subDir = ReadAction.compute(() -> parent.findSubdirectory(directory));
final PsiDirectory subDir = ApplicationManager.getApplication().runReadAction(
(Computable<PsiDirectory>) () -> parent.findSubdirectory(directory)
);

if (subDir == null) {
lastDirectory = createSubdirectoryOnEdt(parent, directory);
Expand All @@ -94,8 +98,9 @@ public PsiDirectory findOrCreateSubdirectories(
}
} else {
final PsiDirectory currentDirectory = lastDirectory;
final PsiDirectory subDir = ReadAction.compute(() ->
currentDirectory.findSubdirectory(directory));
final PsiDirectory subDir = ApplicationManager.getApplication().runReadAction(
(Computable<PsiDirectory>) () -> currentDirectory.findSubdirectory(directory)
);

if (subDir == null) {
final PsiDirectory finalLastDirectory = lastDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ public boolean shouldHighlightErrorElement(final @NotNull PsiErrorElement elemen
}

@Override
public boolean accept(final @NotNull HighlightInfo highlightInfo, final PsiFile file) {
if (!highlightInfo.isFromInjection() || !HighlightSeverity.ERROR.equals(highlightInfo.getSeverity())) {
public boolean accept(final @NotNull HighlightInfo highlightInfo, final @Nullable PsiFile file) {
if (!HighlightSeverity.ERROR.equals(highlightInfo.getSeverity())) {
return true;
}
if (file == null) {
return true;
}
final PsiLanguageInjectionHost host = findInjectedJsonHost(file, highlightInfo.getStartOffset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

package com.magento.idea.magento2plugin.indexes;

import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
Expand Down Expand Up @@ -81,7 +82,7 @@ private List<String> getNames(
final ID<String, String> indexKey,
final boolean withinProject
) {
return ReadAction.compute(() -> {
return ApplicationManager.getApplication().runReadAction((Computable<List<String>>) () -> {
final Set<String> names = new LinkedHashSet<>();
final FileBasedIndex index = FileBasedIndex.getInstance();
final Collection<String> allNames = index.getAllKeys(indexKey, project);
Expand Down Expand Up @@ -122,7 +123,7 @@ private List<String> getNames(
* @return PsiDirectory
*/
public @Nullable PsiDirectory getModuleDirectoryByModuleName(final String moduleName) {
return ReadAction.compute(() -> {
return ApplicationManager.getApplication().runReadAction((Computable<PsiDirectory>) () -> {
final VirtualFile moduleDirectory = getModuleDirectoryVirtualFileByModuleName(moduleName);
if (moduleDirectory == null) {
return null;
Expand All @@ -140,7 +141,7 @@ private List<String> getNames(
* @return VirtualFile
*/
public @Nullable VirtualFile getModuleDirectoryVirtualFileByModuleName(final String moduleName) {
return ReadAction.compute(() -> {
return ApplicationManager.getApplication().runReadAction((Computable<VirtualFile>) () -> {
if (moduleName == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
import com.intellij.icons.AllIcons;
import com.intellij.lang.ASTNode;
import com.intellij.lang.javascript.JavaScriptFileType;
import com.intellij.lang.javascript.psi.JSExpression;
import com.intellij.lang.javascript.psi.JSFile;
Expand Down Expand Up @@ -497,10 +496,10 @@ private int getFirstCodeOffset(final @NotNull String text) {
if (!isFunctionProperty(property)) {
continue;
}
final ASTNode nameIdentifier = property.findNameIdentifier();
final PsiElement nameIdentifier = property.getNameIdentifier();

if (nameIdentifier != null) {
result.add(new MixinOverride(property.getName(), nameIdentifier.getPsi()));
result.add(new MixinOverride(property.getName(), nameIdentifier));
}
}
}
Expand Down Expand Up @@ -532,10 +531,10 @@ private int getFirstCodeOffset(final @NotNull String text) {
if (!isFunctionProperty(property)) {
continue;
}
final ASTNode nameIdentifier = property.findNameIdentifier();
final PsiElement nameIdentifier = property.getNameIdentifier();

if (nameIdentifier != null) {
result.add(nameIdentifier.getPsi());
result.add(nameIdentifier);
}
}

Expand All @@ -556,10 +555,10 @@ private int getFirstCodeOffset(final @NotNull String text) {
if (!isFunctionProperty(property)) {
continue;
}
final ASTNode nameIdentifier = property.findNameIdentifier();
final PsiElement nameIdentifier = property.getNameIdentifier();

if (nameIdentifier != null) {
result.add(nameIdentifier.getPsi());
result.add(nameIdentifier);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder;
import com.intellij.ide.highlighter.HtmlFileType;
import com.intellij.ide.highlighter.XmlFileType;
import com.intellij.lang.ASTNode;
import com.intellij.lang.javascript.JavaScriptFileType;
import com.intellij.lang.javascript.psi.JSFile;
import com.intellij.lang.javascript.psi.JSProperty;
Expand Down Expand Up @@ -160,8 +159,6 @@ private void addXmlComponentLineMarker(
.create(JavaScriptFileType.INSTANCE.getIcon())
.setTargets(preparedTargets)
.setNamer(LineMarkerTargetPresentationUtil::getPresentableTargetName)
.setTargetRenderer(LineMarkerTargetPresentationUtil.TARGET_RENDERER)
.setCellRenderer(LineMarkerTargetPresentationUtil.CELL_RENDERER)
.setTooltipText(MAGENTO_UI_COMPONENT_TOOLTIP_TEXT)
.createLineMarkerInfo(
anchor,
Expand Down Expand Up @@ -197,8 +194,6 @@ private void addXmlTemplateLineMarker(
.create(HtmlFileType.INSTANCE.getIcon())
.setTargets(preparedTargets)
.setNamer(LineMarkerTargetPresentationUtil::getPresentableTargetName)
.setTargetRenderer(LineMarkerTargetPresentationUtil.TARGET_RENDERER)
.setCellRenderer(LineMarkerTargetPresentationUtil.CELL_RENDERER)
.setTooltipText(MAGENTO_TEMPLATE_TOOLTIP_TEXT)
.createLineMarkerInfo(
anchor,
Expand Down Expand Up @@ -244,8 +239,6 @@ private void addLayoutTemplateLineMarker(
.create(HtmlFileType.INSTANCE.getIcon())
.setTargets(LineMarkerTargetPresentationUtil.prepareTargets(targets))
.setNamer(LineMarkerTargetPresentationUtil::getPresentableTargetName)
.setTargetRenderer(LineMarkerTargetPresentationUtil.TARGET_RENDERER)
.setCellRenderer(LineMarkerTargetPresentationUtil.CELL_RENDERER)
.setTooltipText(TEMPLATE_TOOLTIP_TEXT)
.createLineMarkerInfo(anchor));
}
Expand Down Expand Up @@ -276,8 +269,6 @@ private void addLayoutDisplayAreaLineMarker(
.create(HtmlFileType.INSTANCE.getIcon())
.setTargets(preparedTargets)
.setNamer(LineMarkerTargetPresentationUtil::getPresentableTargetName)
.setTargetRenderer(LineMarkerTargetPresentationUtil.TARGET_RENDERER)
.setCellRenderer(LineMarkerTargetPresentationUtil.CELL_RENDERER)
.setTooltipText(REGION_TEMPLATE_TOOLTIP_TEXT)
.createLineMarkerInfo(
anchor,
Expand Down Expand Up @@ -333,8 +324,6 @@ private void addGetRegionLineMarkers(
.create(HtmlFileType.INSTANCE.getIcon())
.setTargets(preparedTargets)
.setNamer(LineMarkerTargetPresentationUtil::getPresentableTargetName)
.setTargetRenderer(LineMarkerTargetPresentationUtil.TARGET_RENDERER)
.setCellRenderer(LineMarkerTargetPresentationUtil.CELL_RENDERER)
.setTooltipText(REGION_DISPLAY_AREA_TOOLTIP_TEXT)
.createLineMarkerInfo(
anchor,
Expand Down Expand Up @@ -375,8 +364,6 @@ private boolean addLegacyGetRegionLineMarker(
.create(HtmlFileType.INSTANCE.getIcon())
.setTargets(preparedChildTemplates)
.setNamer(LineMarkerTargetPresentationUtil::getPresentableTargetName)
.setTargetRenderer(LineMarkerTargetPresentationUtil.TARGET_RENDERER)
.setCellRenderer(LineMarkerTargetPresentationUtil.CELL_RENDERER)
.setTooltipText(REGION_CHILD_TEMPLATE_TOOLTIP_TEXT)
.createLineMarkerInfo(
anchor,
Expand All @@ -393,8 +380,6 @@ private boolean addLegacyGetRegionLineMarker(
.create(JavaScriptFileType.INSTANCE.getIcon())
.setTargets(preparedComponentTargets)
.setNamer(LineMarkerTargetPresentationUtil::getPresentableTargetName)
.setTargetRenderer(LineMarkerTargetPresentationUtil.TARGET_RENDERER)
.setCellRenderer(LineMarkerTargetPresentationUtil.CELL_RENDERER)
.setTooltipText(REGION_COMPONENT_TOOLTIP_TEXT)
.createLineMarkerInfo(
anchor,
Expand Down Expand Up @@ -425,16 +410,14 @@ private void addDisplayAreaLineMarkers(
if (targets.isEmpty()) {
continue;
}
final ASTNode nameIdentifier = property.findNameIdentifier();
final PsiElement anchor = nameIdentifier == null ? property : nameIdentifier.getPsi();
final PsiElement nameIdentifier = property.getNameIdentifier();
final PsiElement anchor = nameIdentifier == null ? property : nameIdentifier;
final List<PsiElement> preparedTargets = LineMarkerTargetPresentationUtil.prepareTargets(targets);

collection.add(NavigationGutterIconBuilder
.create(HtmlFileType.INSTANCE.getIcon())
.setTargets(preparedTargets)
.setNamer(LineMarkerTargetPresentationUtil::getPresentableTargetName)
.setTargetRenderer(LineMarkerTargetPresentationUtil.TARGET_RENDERER)
.setCellRenderer(LineMarkerTargetPresentationUtil.CELL_RENDERER)
.setTooltipText(REGION_TEMPLATE_TOOLTIP_TEXT)
.createLineMarkerInfo(
anchor,
Expand Down Expand Up @@ -495,8 +478,6 @@ private void addDisplayAreaLineMarkers(
: XmlFileType.INSTANCE.getIcon())
.setTargets(preparedTargets)
.setNamer(LineMarkerTargetPresentationUtil::getPresentableTargetName)
.setTargetRenderer(LineMarkerTargetPresentationUtil.TARGET_RENDERER)
.setCellRenderer(LineMarkerTargetPresentationUtil.CELL_RENDERER)
.setTooltipText(tooltip)
.createLineMarkerInfo(
anchor,
Expand Down Expand Up @@ -525,8 +506,6 @@ private void addDisplayAreaLineMarkers(
: XmlFileType.INSTANCE.getIcon())
.setTargets(preparedTargets)
.setNamer(LineMarkerTargetPresentationUtil::getPresentableTargetName)
.setTargetRenderer(LineMarkerTargetPresentationUtil.TARGET_RENDERER)
.setCellRenderer(LineMarkerTargetPresentationUtil.CELL_RENDERER)
.setTooltipText(tooltip)
.createLineMarkerInfo(
anchor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
import com.intellij.codeInsight.navigation.NavigationUtil;
import com.intellij.codeInsight.navigation.PsiTargetNavigator;
import com.intellij.codeInsight.navigation.impl.PsiTargetPresentationRenderer;
import com.intellij.ide.util.PsiElementListCellRenderer;
import com.intellij.openapi.util.Iconable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Iconable;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.platform.backend.presentation.TargetPresentation;
Expand All @@ -23,49 +21,10 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class LineMarkerTargetPresentationUtil {
static final Supplier<PsiTargetPresentationRenderer<PsiElement>> TARGET_RENDERER =
() -> new PsiTargetPresentationRenderer<>() {
@Override
public String getElementText(final PsiElement element) {
return getPresentableTargetName(element);
}

@Override
public String getContainerText(final PsiElement element) {
return null;
}
};

static final PsiElementListCellRenderer<PsiElement> CELL_RENDERER = new PsiElementListCellRenderer<>() {
@Override
public String getElementText(final PsiElement element) {
return getPresentableTargetName(element);
}

@Override
protected String getContainerText(final PsiElement element, final String name) {
return null;
}

@Override
protected int getIconFlags() {
return Iconable.ICON_FLAG_VISIBILITY;
}

@Override
public Comparator<PsiElement> getComparator() {
return Comparator
.comparingInt(LineMarkerTargetPresentationUtil::getPriority)
.thenComparing(LineMarkerTargetPresentationUtil::getPresentableTargetName)
.thenComparing(LineMarkerTargetPresentationUtil::getStableKey);
}
};

private LineMarkerTargetPresentationUtil() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ private void reindexFromForm() {
NotificationType.INFORMATION
);
} catch (final ConfigurationException exception) {
Messages.showErrorDialog(project, exception.getMessage(), "Magento Reindex");
final String message = exception.getLocalizedMessage();
Messages.showErrorDialog(
project,
message == null ? "Invalid Magento settings." : message,
"Magento Reindex"
);
}
}

Expand All @@ -174,7 +179,7 @@ private void installMagentoSkill(final Skill skill) {
);
} catch (final IOException | IllegalStateException exception) {
final String errorMessage = StringUtil.notNullize(
exception.getMessage(),
exception.getLocalizedMessage(),
exception.getClass().getSimpleName()
);
MagentoNotificationUtil.notifyGlobally(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.RootsChangeRescanningInfo;
import com.intellij.openapi.roots.AdditionalLibraryRootsProvider;
import com.intellij.openapi.roots.SyntheticLibrary;
import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
Expand Down Expand Up @@ -49,11 +50,15 @@
}

public static void refreshRoots(final @NotNull Project project) {
WriteAction.run(() -> ProjectRootManagerEx.getInstanceEx(project).makeRootsChange(
() -> { },
false,
true
));
WriteAction.run(() -> {
try (AutoCloseable ignored = ProjectRootManagerEx

Check warning on line 54 in src/main/java/com/magento/idea/magento2plugin/project/indexing/MagentoAdditionalLibraryRootsProvider.java

View workflow job for this annotation

GitHub Actions / static-tests

Empty 'try' block

Empty `try` block
.getInstanceEx(project)
.withRootsChange(RootsChangeRescanningInfo.TOTAL_RESCAN)) {

Check warning on line 56 in src/main/java/com/magento/idea/magento2plugin/project/indexing/MagentoAdditionalLibraryRootsProvider.java

View workflow job for this annotation

GitHub Actions / static-tests

Unstable API Usage

'withRootsChange(com.intellij.openapi.project.@org.jetbrains.annotations.NotNull RootsChangeRescanningInfo)' is marked unstable with @ApiStatus.Internal
// The roots are provided from settings; closing this scope publishes the refresh.
} catch (final Exception exception) {
throw new IllegalStateException("Unable to refresh Magento index roots.", exception);
}
});
}

private @NotNull Collection<VirtualFile> getMagentoIndexRoots(final @NotNull Project project) {
Expand Down
Loading
Loading