Skip to content

Commit 63466a9

Browse files
committed
Fix refactoring in Java and Kotlin code which was broken since 0.41.9 (#1591)
1 parent 4831cba commit 63466a9

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

Diff for: .idea/vcs.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: CHANGELOG.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ This document provides a high-level view of the changes introduced by release.
77
[[releasenotes]]
88
== Release notes
99

10+
=== 0.41.13
11+
12+
- Fix refactoring in Java and Kotlin code which was broken since 0.41.9 (#1591)
13+
1014
=== 0.41.12
1115

1216
- Fix Kroki diagram rendering in preview which broke in release 0.41.10 (#1585)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.asciidoc.intellij.indexer;
2+
3+
import com.intellij.psi.PsiClass;
4+
import com.intellij.psi.PsiElement;
5+
import com.intellij.psi.PsiPackage;
6+
import com.intellij.psi.search.SearchScope;
7+
import com.intellij.psi.search.UseScopeEnlarger;
8+
import org.asciidoc.intellij.psi.AsciiDocSearchScope;
9+
import org.jetbrains.annotations.NotNull;
10+
import org.jetbrains.annotations.Nullable;
11+
12+
public class AsciiDocJavaScopeEnlarger extends UseScopeEnlarger {
13+
@Nullable
14+
@Override
15+
public SearchScope getAdditionalUseScope(@NotNull PsiElement element) {
16+
// Any Java class or package can be referenced from an AsciiDoc element within the same project.
17+
// See org.asciidoc.intellij.psi.AsciiDocJavaReference for the code. Both have the com.intellij.psi.search.GlobalSearchScope, as otherwise this might break refactorings
18+
// as previously reported in https://github.com/asciidoctor/asciidoctor-intellij-plugin/issues/1591
19+
if (element instanceof PsiClass || element instanceof PsiPackage) {
20+
return new AsciiDocSearchScope(element.getProject()).restrictedByAsciiDocFileType();
21+
}
22+
return null;
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package org.asciidoc.intellij.indexer;
22

3+
import com.intellij.psi.PsiDirectory;
34
import com.intellij.psi.PsiElement;
5+
import com.intellij.psi.PsiFile;
46
import com.intellij.psi.search.SearchScope;
57
import com.intellij.psi.search.UseScopeEnlarger;
8+
import org.asciidoc.intellij.AsciiDocLanguage;
69
import org.asciidoc.intellij.psi.AsciiDocSearchScope;
710
import org.jetbrains.annotations.NotNull;
811
import org.jetbrains.annotations.Nullable;
@@ -11,16 +14,10 @@ public class AsciiDocScopeEnlarger extends UseScopeEnlarger {
1114
@Nullable
1215
@Override
1316
public SearchScope getAdditionalUseScope(@NotNull PsiElement element) {
14-
// not restricting to GlobalSearchScope breaks refactorings like extract-variable
15-
// Leads to EDT problems with EAP 2024.1.
16-
// Allowing via SlowOperations.allowSlowOperations() as a workaround in
17-
// https://github.com/asciidoctor/asciidoctor-intellij-plugin/issues/1533
18-
// doesn't work as expected. The original cause for this check as described in https://github.com/asciidoctor/asciidoctor-intellij-plugin/issues/466
19-
// seems no longer present - therefore removing the check
20-
// if (element.getUseScope() instanceof GlobalSearchScope) {
2117
// any element can be referenced from an AsciiDoc element within the same project (directory, file, image, or an ID in an AsciiDoc file)
22-
return new AsciiDocSearchScope(element.getProject()).restrictedByAsciiDocFileType();
23-
// }
24-
// return null;
18+
if (element.getLanguage() == AsciiDocLanguage.INSTANCE || element instanceof PsiFile || element instanceof PsiDirectory) {
19+
return new AsciiDocSearchScope(element.getProject()).restrictedByAsciiDocFileType();
20+
}
21+
return null;
2522
}
2623
}

Diff for: src/main/resources/META-INF/org.asciidoctor.intellij.asciidoc-java.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<psi.referenceContributor language="AsciiDoc" implementation="org.asciidoc.intellij.findUsages.AsciiDocJavaReferenceContributor"/>
55
<lang.findUsagesProvider language="AsciiDoc" implementationClass="org.asciidoc.intellij.findUsages.AsciiDocFindJavaProvider"/>
66
<referencesSearch implementation="org.asciidoc.intellij.findUsages.AsciiDocJavaReferencesSearch"/>
7+
<useScopeEnlarger implementation="org.asciidoc.intellij.indexer.AsciiDocJavaScopeEnlarger" />
78
</extensions>
89
<extensions defaultExtensionNs="org.asciidoc.intellij">
910
<asciidocRunner implementation="org.asciidoc.intellij.commandRunner.AsciiDocRunnerForJava" />

0 commit comments

Comments
 (0)