From 18a5eb2fde38f5a01c7c4b3df2d5f6f25d6f68a4 Mon Sep 17 00:00:00 2001 From: Ihnat Bautovich Date: Sun, 20 Sep 2020 21:37:47 +0200 Subject: [PATCH] #138 Switch to modern Rider plugin architecture (from components to service) to avoid exception on plugin start-up. --- .../CHANGELOG.md | 6 +-- .../build.gradle | 20 +++++--- .../gradle.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../src/dotnet/SdkVersion.props | 2 +- .../action/RunPluginAction.kt | 4 +- .../component/SaveDocumentListener.kt | 48 ------------------- .../component/ShowNotificationComponent.kt | 2 +- .../component/StartUpProjectComponent.kt | 30 ------------ .../services/SaveDocumentListener.kt | 34 +++++++++++++ .../rider/main/resources/META-INF/plugin.xml | 35 +++++++------- 11 files changed, 75 insertions(+), 110 deletions(-) delete mode 100644 Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/SaveDocumentListener.kt delete mode 100644 Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/StartUpProjectComponent.kt create mode 100644 Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/services/SaveDocumentListener.kt diff --git a/Extension/Xamarin.Forms.HotReload.Extension.Rider/CHANGELOG.md b/Extension/Xamarin.Forms.HotReload.Extension.Rider/CHANGELOG.md index 6be96bf..3e2c7d7 100644 --- a/Extension/Xamarin.Forms.HotReload.Extension.Rider/CHANGELOG.md +++ b/Extension/Xamarin.Forms.HotReload.Extension.Rider/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog -## 1.4.3 -- Support for 2020.x version -- Open end `until` version \ No newline at end of file +## 1.4.4 +- Switch to up-to-date Rider plugin architecture +- Fix bug, related to plugin start-up initialization \ No newline at end of file diff --git a/Extension/Xamarin.Forms.HotReload.Extension.Rider/build.gradle b/Extension/Xamarin.Forms.HotReload.Extension.Rider/build.gradle index ea9ddcf..c41c302 100644 --- a/Extension/Xamarin.Forms.HotReload.Extension.Rider/build.gradle +++ b/Extension/Xamarin.Forms.HotReload.Extension.Rider/build.gradle @@ -7,20 +7,21 @@ buildscript { } dependencies { - classpath("com.jetbrains.rd:rd-gen:0.193.119") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31") + classpath("com.jetbrains.rd:rd-gen:0.201.40") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72") + classpath("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.72") } } plugins { id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.3.41' + id 'org.jetbrains.kotlin.jvm' version '1.3.72' id 'org.jetbrains.intellij' version '0.4.21' } ext { repoRoot = projectDir - pluginVersion = '1.4.3' + pluginVersion = '1.4.4' // https://www.jetbrains.com/intellij-repository/snapshots - link to repo of RD snapshots ProductVersion = "${productVersion}-SNAPSHOT" isWindows = Os.isFamily(Os.FAMILY_WINDOWS) @@ -31,13 +32,14 @@ ext { } repositories { + maven { url 'https://jetbrains.com/intellij-repository/snapshots' } maven { url 'https://cache-redirector.jetbrains.com/intellij-repository/snapshots' } maven { url 'https://cache-redirector.jetbrains.com/maven-central' } flatDir { dirs rdLibDirectory.absolutePath } } wrapper { - gradleVersion = '4.9' + gradleVersion = '5.3' distributionType = Wrapper.DistributionType.ALL distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-all.zip" } @@ -86,7 +88,7 @@ def riderSdkPackageVersion = { task compileDotNet { def riderSdkVersionPropsPath = new File(dotNetDir, "SdkVersion.props") - def version = "2019.3.0-*" + def version = "2020.1.0-*" // ToDo: Better to use in future def version = riderSdkPackageVersion() riderSdkVersionPropsPath.text = '' @@ -100,7 +102,11 @@ task compileDotNet { exec { boolean isUnix = Os.isFamily(Os.FAMILY_UNIX) if (isUnix) { - environment "FrameworkPathOverride", "/usr/lib/mono/4.5" + if (Os.isFamily(Os.FAMILY_MAC)) { + environment "FrameworkPathOverride", "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5" + } else { + environment "FrameworkPathOverride", "/usr/lib/mono/4.5" + } } executable "dotnet" diff --git a/Extension/Xamarin.Forms.HotReload.Extension.Rider/gradle.properties b/Extension/Xamarin.Forms.HotReload.Extension.Rider/gradle.properties index 7b07ece..ded622c 100644 --- a/Extension/Xamarin.Forms.HotReload.Extension.Rider/gradle.properties +++ b/Extension/Xamarin.Forms.HotReload.Extension.Rider/gradle.properties @@ -1,4 +1,4 @@ # Properties for the build. Override on the command line with -Pprop=value # E.g. -PBuildConfiguration=Release # Note that these values are strings! -productVersion=2020.1 \ No newline at end of file +productVersion=2020.2 \ No newline at end of file diff --git a/Extension/Xamarin.Forms.HotReload.Extension.Rider/gradle/wrapper/gradle-wrapper.properties b/Extension/Xamarin.Forms.HotReload.Extension.Rider/gradle/wrapper/gradle-wrapper.properties index 2d05ecd..1b939d2 100644 --- a/Extension/Xamarin.Forms.HotReload.Extension.Rider/gradle/wrapper/gradle-wrapper.properties +++ b/Extension/Xamarin.Forms.HotReload.Extension.Rider/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Wed Jun 12 19:43:55 MSK 2019 -distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/dotnet/SdkVersion.props b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/dotnet/SdkVersion.props index 79ea99c..0f4c351 100644 --- a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/dotnet/SdkVersion.props +++ b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/dotnet/SdkVersion.props @@ -1,5 +1,5 @@ - 2019.3.0-* + 2020.1.0-* diff --git a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/action/RunPluginAction.kt b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/action/RunPluginAction.kt index 9ddcffc..3963b16 100644 --- a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/action/RunPluginAction.kt +++ b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/action/RunPluginAction.kt @@ -9,7 +9,9 @@ import com.jetbrains.rider.projectView.solution import hotreload.extension.rider.icons.HotReloadIcons import javax.swing.Icon -class RunPluginAction(icon: Icon) : AnAction("Enable HotReload", "", icon) { +class RunPluginAction(icon: Icon) : AnAction("Enable HotReload", null, icon) { + + constructor(): this(HotReloadIcons.IconOff) override fun actionPerformed(e: AnActionEvent) { val project = e.project ?: return diff --git a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/SaveDocumentListener.kt b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/SaveDocumentListener.kt deleted file mode 100644 index 93818ba..0000000 --- a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/SaveDocumentListener.kt +++ /dev/null @@ -1,48 +0,0 @@ -package hotreload.extension.rider.component - -import com.intellij.application.subscribe -import com.intellij.ide.actions.SaveAllAction -import com.intellij.ide.actions.SaveDocumentAction -import com.intellij.openapi.Disposable -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.DataContext -import com.intellij.openapi.actionSystem.ex.AnActionListener -import com.intellij.openapi.components.ProjectComponent -import com.intellij.openapi.editor.EditorFactory -import com.intellij.openapi.editor.event.DocumentEvent -import com.intellij.openapi.editor.event.DocumentListener -import com.intellij.openapi.project.Project -import com.jetbrains.rd.util.reactive.hasTrueValue -import com.jetbrains.rider.model.SavedDocument -import com.jetbrains.rider.model.hotReloadPluginModel -import com.jetbrains.rider.projectView.solution -import com.jetbrains.rider.util.idea.PsiFile - -class SaveDocumentListener(project: Project) : ProjectComponent, Disposable { - init { - AnActionListener.TOPIC.subscribe(this, FileListenerImpl(project)) - } - - override fun dispose() { - } - - class FileListenerImpl(val project: Project) : AnActionListener { - override fun afterActionPerformed(action: AnAction, dataContext: DataContext, event: AnActionEvent) { - super.afterActionPerformed(action, dataContext, event) - - if (action is SaveDocumentAction || action is SaveAllAction) { - val psiFile = event.dataContext.PsiFile ?: return - val filePath = psiFile.containingFile.viewProvider.virtualFile.canonicalPath - val content = psiFile.containingFile.textToCharArray() - - val document = SavedDocument(filePath.toString(), content) - val model = project.solution.hotReloadPluginModel - if (model.isEnabled.hasTrueValue) { - model.reload.fire(document) - } - } - } - } -} - diff --git a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/ShowNotificationComponent.kt b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/ShowNotificationComponent.kt index d08c997..ebbda7d 100644 --- a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/ShowNotificationComponent.kt +++ b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/ShowNotificationComponent.kt @@ -23,7 +23,7 @@ class ShowNotificationComponent(project: Project) : LifetimedProjectComponent(pr } } - private fun showNotification(messageInfo: MessageInfo){ + private fun showNotification(messageInfo: MessageInfo) { val yamlNotification = Notification(notificationGroupId.displayId, messageInfo.title, messageInfo.message, NotificationType.INFORMATION) Notifications.Bus.notify(yamlNotification, project) } diff --git a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/StartUpProjectComponent.kt b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/StartUpProjectComponent.kt deleted file mode 100644 index 5557f56..0000000 --- a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/component/StartUpProjectComponent.kt +++ /dev/null @@ -1,30 +0,0 @@ -package hotreload.extension.rider.component - -import com.intellij.openapi.Disposable -import com.intellij.openapi.actionSystem.ActionManager -import com.intellij.openapi.actionSystem.DefaultActionGroup -import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl -import com.intellij.openapi.components.ProjectComponent -import hotreload.extension.rider.action.RunPluginAction -import hotreload.extension.rider.icons.HotReloadIcons - - -class StartUpProjectComponent: Disposable { - override fun dispose() { - val actionManager = ActionManager.getInstance() - actionManager.unregisterAction("HotReloadAction") } - - init { - val actionManager = ActionManager.getInstance() - val hotReloadAction = RunPluginAction(HotReloadIcons.IconOff) - actionManager.registerAction("HotReloadAction", hotReloadAction) - - // Gets an instance of the WindowMenu action group. - val toolbar = actionManager.getAction("NavBarToolBar") as DefaultActionGroup - - // Adds a separator and a new menu command to the WindowMenu group on the main menu. - toolbar.addSeparator() - toolbar.add(hotReloadAction) - ActionToolbarImpl.updateAllToolbarsImmediately() - } -} \ No newline at end of file diff --git a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/services/SaveDocumentListener.kt b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/services/SaveDocumentListener.kt new file mode 100644 index 0000000..92b1601 --- /dev/null +++ b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/kotlin/hotreload.extension.rider/services/SaveDocumentListener.kt @@ -0,0 +1,34 @@ +package hotreload.extension.rider.services + +import com.intellij.ide.actions.SaveAllAction +import com.intellij.ide.actions.SaveDocumentAction +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.DataContext +import com.intellij.openapi.actionSystem.ex.AnActionListener +import com.intellij.openapi.project.Project +import com.jetbrains.rd.util.reactive.hasTrueValue +import com.jetbrains.rider.model.SavedDocument +import com.jetbrains.rider.model.hotReloadPluginModel +import com.jetbrains.rider.projectView.solution +import com.jetbrains.rider.util.idea.PsiFile + +class SaveDocumentListener(val project: Project) : AnActionListener { + + override fun afterActionPerformed(action: AnAction, dataContext: DataContext, event: AnActionEvent) { + super.afterActionPerformed(action, dataContext, event) + + if (action is SaveDocumentAction || action is SaveAllAction) { + val psiFile = event.dataContext.PsiFile ?: return + val filePath = psiFile.containingFile.viewProvider.virtualFile.canonicalPath + val content = psiFile.containingFile.textToCharArray() + + val document = SavedDocument(filePath.toString(), content) + val model = project.solution.hotReloadPluginModel + if (model.isEnabled.hasTrueValue) { + model.reload.fire(document) + } + } + } +} + diff --git a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/resources/META-INF/plugin.xml b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/resources/META-INF/plugin.xml index 7969721..3c33fca 100644 --- a/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/resources/META-INF/plugin.xml +++ b/Extension/Xamarin.Forms.HotReload.Extension.Rider/src/rider/main/resources/META-INF/plugin.xml @@ -1,26 +1,27 @@ - hotreloadplugin-rider - Hot Reload - _PLACEHOLDER_ - Ignat Bavtovich - com.intellij.modules.rider + hotreloadplugin-rider + Hot Reload + _PLACEHOLDER_ + Ignat Bavtovich + com.intellij.modules.rider - - Plugin helps to integrate Xamarin HotReload project with Rider and easily apply new changes in your code without - any configuration - + + Plugin helps to integrate Xamarin HotReload project with Rider and easily apply new changes in your code without + any configuration + - - - hotreload.extension.rider.component.StartUpProjectComponent - - - - hotreload.extension.rider.component.SaveDocumentListener - hotreload.extension.rider.component.ShowNotificationComponent + + + + + + + +