Skip to content

Commit

Permalink
Fix refactoring in Java and Kotlin code which was broken since 0.41.9 (
Browse files Browse the repository at this point in the history
  • Loading branch information
ahus1 committed Apr 3, 2024
1 parent 4831cba commit a2403b7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ This document provides a high-level view of the changes introduced by release.
[[releasenotes]]
== Release notes

=== 0.41.13

- Fix refactoring in Java and Kotlin code which was broken since 0.41.9 (#1533)

=== 0.41.12

- Fix Kroki diagram rendering in preview which broke in release 0.41.10 (#1585)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.asciidoc.intellij.indexer;

import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiPackage;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.UseScopeEnlarger;
import org.asciidoc.intellij.psi.AsciiDocSearchScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class AsciiDocJavaScopeEnlarger extends UseScopeEnlarger {
@Nullable
@Override
public SearchScope getAdditionalUseScope(@NotNull PsiElement element) {
// Any Java class or package can be referenced from an AsciiDoc element within the same project.
// See org.asciidoc.intellij.psi.AsciiDocJavaReference for the code. Both have the com.intellij.psi.search.GlobalSearchScope, as otherwise this might break refactorings
// as previously reported in https://github.com/asciidoctor/asciidoctor-intellij-plugin/issues/1591
if (element instanceof PsiClass || element instanceof PsiPackage) {
return new AsciiDocSearchScope(element.getProject()).restrictedByAsciiDocFileType();
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.asciidoc.intellij.indexer;

import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.UseScopeEnlarger;
import org.asciidoc.intellij.AsciiDocLanguage;
import org.asciidoc.intellij.psi.AsciiDocSearchScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -11,16 +14,10 @@ public class AsciiDocScopeEnlarger extends UseScopeEnlarger {
@Nullable
@Override
public SearchScope getAdditionalUseScope(@NotNull PsiElement element) {
// not restricting to GlobalSearchScope breaks refactorings like extract-variable
// Leads to EDT problems with EAP 2024.1.
// Allowing via SlowOperations.allowSlowOperations() as a workaround in
// https://github.com/asciidoctor/asciidoctor-intellij-plugin/issues/1533
// doesn't work as expected. The original cause for this check as described in https://github.com/asciidoctor/asciidoctor-intellij-plugin/issues/466
// seems no longer present - therefore removing the check
// if (element.getUseScope() instanceof GlobalSearchScope) {
// any element can be referenced from an AsciiDoc element within the same project (directory, file, image, or an ID in an AsciiDoc file)
return new AsciiDocSearchScope(element.getProject()).restrictedByAsciiDocFileType();
// }
// return null;
if (element.getLanguage() == AsciiDocLanguage.INSTANCE || element instanceof PsiFile || element instanceof PsiDirectory) {
return new AsciiDocSearchScope(element.getProject()).restrictedByAsciiDocFileType();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<psi.referenceContributor language="AsciiDoc" implementation="org.asciidoc.intellij.findUsages.AsciiDocJavaReferenceContributor"/>
<lang.findUsagesProvider language="AsciiDoc" implementationClass="org.asciidoc.intellij.findUsages.AsciiDocFindJavaProvider"/>
<referencesSearch implementation="org.asciidoc.intellij.findUsages.AsciiDocJavaReferencesSearch"/>
<useScopeEnlarger implementation="org.asciidoc.intellij.indexer.AsciiDocJavaScopeEnlarger" />
</extensions>
<extensions defaultExtensionNs="org.asciidoc.intellij">
<asciidocRunner implementation="org.asciidoc.intellij.commandRunner.AsciiDocRunnerForJava" />
Expand Down

0 comments on commit a2403b7

Please sign in to comment.