diff --git a/build.gradle b/build.gradle index 046ba2a..c7026fa 100644 --- a/build.gradle +++ b/build.gradle @@ -43,11 +43,10 @@ tasks { } patchPluginXml { - sinceBuild = '203' + sinceBuild = '213' pluginDescription = """Highlight .bb/.bbappend/.bbclass/.inc files in JetBrains IDEs to make working with BitBake-based projects (like anything based on Yocto Project) easier.""" - changeNotes = """First marketplace release, now with updated dependencies & without strict maximum version - limitation.""" + changeNotes = """Fix compatibility with IDEA/PyCharm Ultimate.""" } generateLexer { diff --git a/src/main/java/com/github/vitalibo/intellij/bitbake/BitBakeLanguageInjector.java b/src/main/java/com/github/vitalibo/intellij/bitbake/BitBakeLanguageInjector.java index fbe2686..07929af 100644 --- a/src/main/java/com/github/vitalibo/intellij/bitbake/BitBakeLanguageInjector.java +++ b/src/main/java/com/github/vitalibo/intellij/bitbake/BitBakeLanguageInjector.java @@ -3,9 +3,17 @@ import com.github.vitalibo.intellij.bitbake.psi.BitBakeNativePythonFunctionImpl; import com.github.vitalibo.intellij.bitbake.psi.BitBakePythonFunctionImpl; import com.github.vitalibo.intellij.bitbake.psi.impl.BitBakeBbBashFunctionImpl; +import com.intellij.ide.plugins.PluginManagerConfigurable; import com.intellij.lang.Language; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationAction; +import com.intellij.notification.NotificationType; import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.LanguageFileType; +import com.intellij.openapi.options.ShowSettingsUtil; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.util.TextRange; import com.intellij.psi.InjectedLanguagePlaces; import com.intellij.psi.LanguageInjector; @@ -17,19 +25,54 @@ public class BitBakeLanguageInjector implements LanguageInjector { @Override public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) { if (host instanceof BitBakeBbBashFunctionImpl) { - final Language language = ((LanguageFileType) FileTypeManager.getInstance().getFileTypeByExtension("sh")).getLanguage(); + + final FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension("sh"); + if (!(fileType instanceof LanguageFileType)) { + showRecommendedPluginNotification(host.getProject()); + return; + } + final Language language = ((LanguageFileType) fileType).getLanguage(); injectionPlacesRegistrar.addPlace(language, new TextRange(0, host.getText().length()), "\n", "\n"); - } - if (host instanceof BitBakeNativePythonFunctionImpl) { + } else if ((host instanceof BitBakeNativePythonFunctionImpl) || (host instanceof BitBakePythonFunctionImpl)) { + + final FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension("py"); + if (!(fileType instanceof LanguageFileType)) { + showRecommendedPluginNotification(host.getProject()); + return; + } final Language language = ((LanguageFileType) FileTypeManager.getInstance().getFileTypeByExtension("py")).getLanguage(); - injectionPlacesRegistrar.addPlace(language, new TextRange(0, host.getText().length()), "import oe\nimport bb\nimport os\n\n", "\n"); + if (host instanceof BitBakeNativePythonFunctionImpl) { + injectionPlacesRegistrar.addPlace(language, new TextRange(0, host.getText().length()), "import oe\nimport bb\nimport os\n\n", "\n"); + } else if (host instanceof BitBakePythonFunctionImpl) { + String text = host.getText(); + injectionPlacesRegistrar.addPlace(language, new TextRange(text.indexOf('{') + 2, text.lastIndexOf('}')), "import oe\nimport bb\nimport os\n\ndef name(d):", "\n"); + } } + } - if (host instanceof BitBakePythonFunctionImpl) { - final Language language = ((LanguageFileType) FileTypeManager.getInstance().getFileTypeByExtension("py")).getLanguage(); - String text = host.getText(); - injectionPlacesRegistrar.addPlace(language, new TextRange(text.indexOf('{') + 2, text.lastIndexOf('}')), "import oe\nimport bb\nimport os\n\ndef name(d):", "\n"); + private static boolean recommendedPluginNotificationShown = false; + + private static void showRecommendedPluginNotification(Project project) { + if (BitBakeLanguageInjector.recommendedPluginNotificationShown) { + return; } + BitBakeLanguageInjector.recommendedPluginNotificationShown = true; + final Notification notification = new Notification( + "com.github.vitalibo.intellij.bitbake", + "Recommended Syntax Highlighters", + "It is recommended to install the Python and Shell Script plugins for full syntax highlighting.", + NotificationType.INFORMATION + ); + notification.addAction(NotificationAction.createSimple("Visit Marketplace", () -> { + ShowSettingsUtil.getInstance().showSettingsDialog( + ProjectManager.getInstance().getDefaultProject(), + PluginManagerConfigurable.class, + c -> c.openMarketplaceTab( + "script /tag:\"Programming Language\" /organization:\"JetBrains s.r.o.\"" + ) + ); + })); + notification.notify(project); } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 241fb59..4434613 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -8,7 +8,7 @@ - com.intellij.modules.python-core-capable + com.intellij.modules.lang