JS: add notification for incompatible abi version for Kotlin/JavaScript libraries
This commit is contained in:
@@ -36,6 +36,7 @@ import com.intellij.psi.search.ProjectScope;
|
|||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import com.intellij.util.indexing.FileBasedIndex;
|
import com.intellij.util.indexing.FileBasedIndex;
|
||||||
import com.intellij.util.indexing.ID;
|
import com.intellij.util.indexing.ID;
|
||||||
|
import com.intellij.util.indexing.ScalarIndexExtension;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.idea.JetPluginUtil;
|
import org.jetbrains.kotlin.idea.JetPluginUtil;
|
||||||
@@ -62,33 +63,15 @@ public class KotlinRuntimeLibraryUtil {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Collection<VirtualFile> getLibraryRootsWithAbiIncompatibleKotlinClasses(@NotNull Project project) {
|
public static Collection<VirtualFile> getLibraryRootsWithAbiIncompatibleKotlinClasses(@NotNull Project project) {
|
||||||
ID<Integer, Void> id = KotlinAbiVersionIndex.INSTANCE.getName();
|
return getLibraryRootsWithAbiIncompatibleVersion(project, KotlinAbiVersionIndex.INSTANCE$);
|
||||||
Collection<Integer> abiVersions = FileBasedIndex.getInstance().getAllKeys(id, project);
|
|
||||||
Set<Integer> badAbiVersions = Sets.newHashSet(Collections2.filter(abiVersions, new Predicate<Integer>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(Integer abiVersion) {
|
|
||||||
return !AbiVersionUtil.isAbiVersionCompatible(abiVersion);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
Set<VirtualFile> badRoots = Sets.newHashSet();
|
|
||||||
ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project);
|
|
||||||
|
|
||||||
for (Integer version : badAbiVersions) {
|
|
||||||
Collection<VirtualFile> indexedFiles = FileBasedIndex.getInstance().getContainingFiles(
|
|
||||||
id, version, ProjectScope.getLibrariesScope(project));
|
|
||||||
|
|
||||||
for (VirtualFile indexedFile : indexedFiles) {
|
|
||||||
VirtualFile libraryRoot = fileIndex.getClassRootForFile(indexedFile);
|
|
||||||
assert libraryRoot != null : "Only library roots were requested, " +
|
|
||||||
"and only class files should be indexed with KotlinAbiVersionIndex key. " +
|
|
||||||
"File: " + indexedFile.getPath();
|
|
||||||
badRoots.add(getLocalFile(libraryRoot));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return badRoots;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Collection<VirtualFile> getLibraryRootsWithAbiIncompatibleForKotlinJs(@NotNull Project project) {
|
||||||
|
return getLibraryRootsWithAbiIncompatibleVersion(project, KotlinJavaScriptAbiVersionIndex.INSTANCE$);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void addJdkAnnotations(@NotNull Sdk sdk) {
|
public static void addJdkAnnotations(@NotNull Sdk sdk) {
|
||||||
addAnnotations(sdk, PathUtil.getKotlinPathsForIdeaPlugin().getJdkAnnotationsPath());
|
addAnnotations(sdk, PathUtil.getKotlinPathsForIdeaPlugin().getJdkAnnotationsPath());
|
||||||
}
|
}
|
||||||
@@ -300,4 +283,36 @@ public class KotlinRuntimeLibraryUtil {
|
|||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static Collection<VirtualFile> getLibraryRootsWithAbiIncompatibleVersion(
|
||||||
|
@NotNull Project project,
|
||||||
|
@NotNull ScalarIndexExtension<Integer> index
|
||||||
|
) {
|
||||||
|
ID<Integer, Void> id = index.getName();
|
||||||
|
Collection<Integer> abiVersions = FileBasedIndex.getInstance().getAllKeys(id, project);
|
||||||
|
Set<Integer> badAbiVersions = Sets.newHashSet(Collections2.filter(abiVersions, new Predicate<Integer>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(Integer abiVersion) {
|
||||||
|
return !AbiVersionUtil.isAbiVersionCompatible(abiVersion);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
Set<VirtualFile> badRoots = Sets.newHashSet();
|
||||||
|
ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project);
|
||||||
|
|
||||||
|
for (Integer version : badAbiVersions) {
|
||||||
|
Collection<VirtualFile> indexedFiles = FileBasedIndex.getInstance().getContainingFiles(
|
||||||
|
id, version, ProjectScope.getLibrariesScope(project));
|
||||||
|
|
||||||
|
for (VirtualFile indexedFile : indexedFiles) {
|
||||||
|
VirtualFile libraryRoot = fileIndex.getClassRootForFile(indexedFile);
|
||||||
|
assert libraryRoot != null : "Only library roots were requested, " +
|
||||||
|
"and only class files should be indexed with KotlinAbiVersionIndex key. " +
|
||||||
|
"File: " + indexedFile.getPath();
|
||||||
|
badRoots.add(getLocalFile(libraryRoot));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return badRoots;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ class KotlinUpdatePluginComponent : ApplicationComponent {
|
|||||||
|
|
||||||
// Force update indices for files under config directory
|
// Force update indices for files under config directory
|
||||||
val fileBasedIndex = FileBasedIndex.getInstance()
|
val fileBasedIndex = FileBasedIndex.getInstance()
|
||||||
fileBasedIndex.requestRebuild(KotlinAbiVersionIndex.INSTANCE.getName())
|
fileBasedIndex.requestRebuild(KotlinAbiVersionIndex.getName())
|
||||||
|
fileBasedIndex.requestRebuild(KotlinJavaScriptAbiVersionIndex.getName())
|
||||||
fileBasedIndex.requestRebuild(KotlinClassFileIndex.KEY)
|
fileBasedIndex.requestRebuild(KotlinClassFileIndex.KEY)
|
||||||
fileBasedIndex.requestRebuild(KotlinJavaScriptMetaFileIndex.KEY)
|
fileBasedIndex.requestRebuild(KotlinJavaScriptMetaFileIndex.KEY)
|
||||||
|
|
||||||
|
|||||||
+12
-5
@@ -51,6 +51,7 @@ import org.jetbrains.kotlin.idea.JetFileType;
|
|||||||
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils;
|
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils;
|
||||||
import org.jetbrains.kotlin.idea.configuration.KotlinJavaModuleConfigurator;
|
import org.jetbrains.kotlin.idea.configuration.KotlinJavaModuleConfigurator;
|
||||||
import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator;
|
import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator;
|
||||||
|
import org.jetbrains.kotlin.idea.framework.JSLibraryStdPresentationProvider;
|
||||||
import org.jetbrains.kotlin.idea.framework.JavaRuntimePresentationProvider;
|
import org.jetbrains.kotlin.idea.framework.JavaRuntimePresentationProvider;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -85,7 +86,7 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static EditorNotificationPanel checkAndCreate(@NotNull Project project) {
|
public static EditorNotificationPanel checkAndCreate(@NotNull Project project) {
|
||||||
Collection<VirtualFile> badRoots = KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleKotlinClasses(project);
|
Collection<VirtualFile> badRoots = collectBadRoots(project);
|
||||||
if (!badRoots.isEmpty()) {
|
if (!badRoots.isEmpty()) {
|
||||||
return new UnsupportedAbiVersionNotificationPanelProvider(project).doCreate(badRoots);
|
return new UnsupportedAbiVersionNotificationPanelProvider(project).doCreate(badRoots);
|
||||||
}
|
}
|
||||||
@@ -101,8 +102,9 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi
|
|||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable Library library) {
|
public boolean apply(@Nullable Library library) {
|
||||||
assert library != null : "library should be non null";
|
assert library != null : "library should be non null";
|
||||||
VirtualFile runtimeJar = JavaRuntimePresentationProvider.getRuntimeJar(library);
|
VirtualFile runtimeJar = KotlinRuntimeLibraryUtil.getLocalJar(JavaRuntimePresentationProvider.getRuntimeJar(library));
|
||||||
return badRoots.contains(KotlinRuntimeLibraryUtil.getLocalJar(runtimeJar));
|
VirtualFile jsLibJar = KotlinRuntimeLibraryUtil.getLocalJar(JSLibraryStdPresentationProvider.getJsStdLibJar(library));
|
||||||
|
return badRoots.contains(runtimeJar) || badRoots.contains(jsLibJar);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -161,8 +163,7 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi
|
|||||||
DumbService.getInstance(project).tryRunReadActionInSmartMode(new Computable<Object>() {
|
DumbService.getInstance(project).tryRunReadActionInSmartMode(new Computable<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public Object compute() {
|
public Object compute() {
|
||||||
Collection<VirtualFile> badRoots =
|
Collection<VirtualFile> badRoots = collectBadRoots(project);
|
||||||
KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleKotlinClasses(project);
|
|
||||||
assert !badRoots.isEmpty() : "This action should only be called when bad roots are present";
|
assert !badRoots.isEmpty() : "This action should only be called when bad roots are present";
|
||||||
|
|
||||||
LibraryRootsPopupModel listPopupModel = new LibraryRootsPopupModel("Unsupported format", project, badRoots);
|
LibraryRootsPopupModel listPopupModel = new LibraryRootsPopupModel("Unsupported format", project, badRoots);
|
||||||
@@ -272,4 +273,10 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static Collection<VirtualFile> collectBadRoots(@NotNull Project project) {
|
||||||
|
Collection<VirtualFile> badRoots = KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleKotlinClasses(project);
|
||||||
|
badRoots.addAll(KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleForKotlinJs(project));
|
||||||
|
return badRoots;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user