Skip to content

Commit

Permalink
Update for 2023.2 support.
Browse files Browse the repository at this point in the history
Remove use of internal API.
  • Loading branch information
Layoric committed Aug 15, 2023
1 parent 27a3b66 commit e54f88d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
36 changes: 34 additions & 2 deletions src/main/java/net/servicestack/idea/AddPythonAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.util.PlatformUtils;
import com.jetbrains.python.PythonFileType;
import com.jetbrains.python.facet.PythonFacet;
import com.jetbrains.python.facet.PythonFacetSettings;
import net.servicestack.idea.common.INativeTypesHandler;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -44,13 +48,41 @@ public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabled(false);
}

if (!PlatformUtils.isPyCharm()) {
if (!isPythonModule(module)) { // Checking if this is a python project for example
e.getPresentation().setVisible(false);
}

super.update(e);
}

public boolean isPythonModule(Module module) {
if (module == null) {
return false;
}

// Retrieve the module's root manager
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);

// Retrieve the module's content roots
VirtualFile[] roots = moduleRootManager.getContentRoots();

// Iterate over each root file
for (VirtualFile rootFile : roots) {
VirtualFile[] children = rootFile.getChildren();

// Iterate over each child file
for (VirtualFile childFile : children) {
// Check if a child file is a Python file
if (childFile.getFileType() instanceof PythonFileType) {
return true;
}
}
}

// If no Python files are found, return false
return false;
}

static Module getModule(Project project) {
if (project == null)
return null;
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/net/servicestack/idea/AddServiceStackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.util.PlatformUtils;
import org.jetbrains.annotations.NotNull;

import java.io.File;
Expand Down Expand Up @@ -165,7 +166,7 @@ public void update(AnActionEvent e) {
return;
}

if (!(PlatformUtils.isIntelliJ() || isAndroidProject(module) || isDartProject(module))) {
if (!(isJavaProject(module) || isAndroidProject(module) || isDartProject(module))) {
e.getPresentation().setVisible(false);
return;
}
Expand All @@ -186,6 +187,19 @@ public void update(AnActionEvent e) {
super.update(e);
}

public boolean isJavaProject(Module module) {
if (module == null) {
return false;
}

LanguageLevelModuleExtensionImpl languageLevelExtension = LanguageLevelModuleExtensionImpl.getInstance(module);

// Check if language level is not null and it is at least JDK_1_3
return languageLevelExtension != null &&
languageLevelExtension.getLanguageLevel() != null &&
languageLevelExtension.getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_3);
}

static Module getModule(Project project) {
if (project == null)
return null;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/net/servicestack/idea/NativeTypeUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package net.servicestack.idea;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.module.Module;
import com.intellij.util.PlatformUtils;
import net.servicestack.idea.common.INativeTypesHandler;
import net.servicestack.idea.common.MjsNativeTypesHandler;
import net.servicestack.idea.common.TypeScriptConcreteNativeTypesHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.util.PlatformUtils;
import org.jetbrains.annotations.NotNull;

/**
Expand Down Expand Up @@ -44,11 +43,10 @@ public void update(@NotNull AnActionEvent e) {
if (module == null) {
e.getPresentation().setEnabled(false);
}

if (PlatformUtils.isDataGrip() || PlatformUtils.isAppCode() ||
PlatformUtils.isCidr() || PlatformUtils.isCLion()) {
e.getPresentation().setVisible(false);
}
// If the plugin is installed, make visible.
// since Typescript/web is common development
// to variable languages/platforms.
e.getPresentation().setVisible(true);

super.update(e);
}
Expand Down

0 comments on commit e54f88d

Please sign in to comment.