Skip to content

Commit

Permalink
Merge pull request #7 from vitalibo/issue-6-ultimate
Browse files Browse the repository at this point in the history
Fix compatibility with IDEA/PyCharm Ultimate (#6)
  • Loading branch information
moqmar authored Jun 7, 2023
2 parents 3f43bd2 + 76c29b8 commit c78645f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<description><![CDATA[ Description will be added by gradle build]]></description>

<depends>com.intellij.modules.python-core-capable</depends>
<depends>com.intellij.modules.lang</depends>

<extensions defaultExtensionNs="com.intellij">
<fileType
Expand Down

0 comments on commit c78645f

Please sign in to comment.