Skip to content

Commit

Permalink
Merge pull request #801 from JetBrains/241.ra/fix-issues
Browse files Browse the repository at this point in the history
Fix different issues
  • Loading branch information
rafaelldi committed Mar 20, 2024
2 parents a8b6462 + 3ddcf99 commit 20d30ee
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 140 deletions.
2 changes: 1 addition & 1 deletion BuildPlugin
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tc_open "Initializing build script"
IJ_VERSION_MINOR=
IJ_VERSION_LATEST=$IJ_VERSION_MAJOR.$IJ_VERSION_MINOR \
&& [[ -z $IJ_VERSION_MINOR ]] && IJ_VERSION_LATEST=$IJ_VERSION_MAJOR
IJ_SCALA_VERSION_LATEST=2024.1.6
IJ_SCALA_VERSION_LATEST=2024.1.11

while getopts ":hqvBC:e:" option; do
case $option in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ org.gradle.jvmargs='-Duser.language=en'
sources=false

#https://www.jetbrains.com/intellij-repository/snapshots
intellij_version=IC-241.14024-EAP-CANDIDATE-SNAPSHOT
rider_version=RD-2024.1-EAP6-SNAPSHOT
intellij_version=IC-241.14494-EAP-CANDIDATE-SNAPSHOT
rider_version=RD-2024.1-EAP9-SNAPSHOT
#rider_version=RD-2023.3
build_common_code_with=rider
intellij_plugin_name=azure-toolkit-for-intellij
rider_plugin_name=azure-toolkit-for-rider
rider_backend_build_configuration=Debug

#https://plugins.jetbrains.com/plugin/1347-scala/versions/stable
dep_plugins=org.intellij.scala:2024.1.6
dep_plugins=org.intellij.scala:2024.1.11
applicationinsights.key=57cc111a-36a8-44b3-b044-25d293b8b77c

updateVersionRange=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Application;
using JetBrains.Application.Parts;
using JetBrains.ProjectModel;
using JetBrains.ProjectModel.Properties;
using JetBrains.ReSharper.Feature.Services.LiveTemplates.Scope;
Expand All @@ -35,7 +36,7 @@ public class InAzureFunctionsCSharpProject : InAzureFunctionsProject
public override string PresentableShortName => "Azure Functions (C#) projects";
}

[ShellComponent]
[ShellComponent(Instantiation.DemandAnyThreadSafe)]
public class AzureCSharpProjectScopeProvider : AzureProjectScopeProvider
{
public AzureCSharpProjectScopeProvider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Application;
using JetBrains.Application.Parts;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Feature.Services.LiveTemplates.Scope;

Expand All @@ -35,7 +36,7 @@ public class InAzureFunctionsFSharpProject : InAzureFunctionsProject
public override string PresentableShortName => "Azure Functions (F#) projects";
}

[ShellComponent]
[ShellComponent(Instantiation.DemandAnyThreadSafe)]
public class AzureFSharpScopeProvider : AzureCSharpProjectScopeProvider
{
public AzureFSharpScopeProvider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Application;
using JetBrains.Application.Parts;
using JetBrains.Application.UI.Icons.CommonThemedIcons;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Azure.Project.FunctionApp;
Expand All @@ -39,7 +40,7 @@ public class InAzureFunctionsProject : InAnyProject
public override string PresentableShortName => "Azure Functions projects";
}

[ShellComponent]
[ShellComponent(Instantiation.DemandAnyThreadSafe)]
public class AzureProjectScopeProvider : ScopeProvider
{
static AzureProjectScopeProvider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,34 @@ class WebAppContextPublishProvider : RiderContextPublishProvider {
override val name: String
get() = message("context_menu.publish.web_app.publish_to_azure")

override fun getConfigurationForNode(project: Project,
entity: ProjectModelEntity): Pair<RunConfiguration, ConfigurationFactory> {
override fun getConfigurationForNode(
project: Project,
entity: ProjectModelEntity
): Pair<RunConfiguration, ConfigurationFactory> {

val projectData = RiderContextPublishProvider.getProjectDataRecursive(project, entity)
?: error("Unexpected project node type. Cannot get project data for entity ${entity.url}")

val factory = ConfigurationTypeUtil.findConfigurationType(RiderWebAppConfigurationType::class.java).configurationFactories.single()
val configuration = RiderWebAppConfiguration(project, factory, String.format(RUN_CONFIG_PROJECT_NAME, projectData.value.projectName))
val configurationName = projectData?.value?.projectName ?: entity.name
val configuration = RiderWebAppConfiguration(project, factory, String.format(RUN_CONFIG_PROJECT_NAME, configurationName))

configuration.model.webAppModel.publishableProject = projectData.value
if (projectData != null) {
configuration.model.webAppModel.publishableProject = projectData.value
} else {
configuration.model.webAppModel.publishableProject = project.solution.publishableProjectsModel.publishableProjects.entries.first {
isProjectPublishable(it.value)
}.value
}

return Pair(configuration, factory)
}

private fun isProjectPublishable(projectData: PublishableProjectModel?) =
projectData != null && (projectData.isWeb && (projectData.isDotNetCore || SystemInfo.isWindows))
private fun isProjectPublishable(projectData: PublishableProjectModel) =
projectData.isWeb && (projectData.isDotNetCore || SystemInfo.isWindows)

override fun isAvailable(project: Project, entity: ProjectModelEntity): Boolean {
val projectData = RiderContextPublishProvider.getProjectData(project, entity)
return isProjectPublishable(projectData?.value)
return projectData != null && isProjectPublishable(projectData.value)
}

override fun solutionHasAnyPublishableProjects(project: Project): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,157 +20,59 @@
* SOFTWARE.
*/

@file:Suppress("UnstableApiUsage")

package org.jetbrains.plugins.azure.functions

import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.fileEditor.impl.LoadTextUtil
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.EditorNotificationPanel
import com.intellij.ui.EditorNotificationProvider
import com.intellij.ui.EditorNotifications
import com.intellij.platform.backend.workspace.WorkspaceModel
import com.jetbrains.rd.util.firstOrNull
import com.jetbrains.rdclient.util.idea.pumpMessages
import com.jetbrains.rider.nuget.RiderNuGetFacade
import com.jetbrains.rider.nuget.RiderNuGetHost
import com.jetbrains.rider.projectView.workspace.ProjectModelEntity
import com.jetbrains.rider.projectView.workspace.containingProjectEntity
import com.jetbrains.rider.projectView.workspace.getId
import com.jetbrains.rider.projectView.workspace.getProjectModelEntities
import com.microsoft.intellij.configuration.AzureRiderSettings
import org.jetbrains.plugins.azure.RiderAzureBundle
import java.time.Duration
import java.util.function.Function

class AzureCoreToolsMissingNupkgNotificationProvider : EditorNotificationProvider {

companion object {

private val waitForInstallDuration = Duration.ofSeconds(30)

private fun hasKnownFileSuffix(file: VirtualFile): Boolean =
file.extension.equals("cs", true) ||
file.extension.equals("vb", true) ||
file.extension.equals("fs", true)

private val markerToTriggerMap = mapOf(
// Default worker
"Microsoft.Azure.WebJobs" to mapOf(
"BlobTrigger" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.Storage.Blobs", "5.2.1")),
"QueueTrigger" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.Storage.Queues", "5.2.0")),
"CosmosDBTrigger" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.CosmosDB", "4.4.0")),
"OrchestrationTrigger" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.DurableTask", "2.13.0")),
"EventGridTrigger" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.EventGrid", "3.3.1")),
"EventHubTrigger" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.EventHubs", "6.0.2")),
"IoTHubTrigger" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.EventHubs", "6.0.2")),
"ServiceBusTrigger" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.ServiceBus", "5.13.4")),
"SqlTrigger" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.Sql", "3.0.461")),
"DaprPublish" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.Dapr", "0.17.0-preview01")),
"DaprInvoke" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.Dapr", "0.17.0-preview01")),
"DaprState" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.Dapr", "0.17.0-preview01")),
"DaprServiceInvocationTrigger" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.Dapr", "0.17.0-preview01")),
"DaprTopicTrigger" to listOf(PackageDependency("Microsoft.Azure.WebJobs.Extensions.Dapr", "0.17.0-preview01")),
),

// Isolated worker
"Microsoft.Azure.Functions.Worker" to mapOf(
"BlobTrigger" to listOf(PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs", "6.2.0")),
"QueueTrigger" to listOf(PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues", "5.2.0")),
"CosmosDBTrigger" to listOf(PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.CosmosDB", "4.4.2")),
"EventGridTrigger" to listOf(PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.EventGrid", "3.4.0")),
"EventHubTrigger" to listOf(PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.EventHubs", "6.0.1")),
"HttpTrigger" to listOf(PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.Http", "3.1.0")),
"ServiceBusTrigger" to listOf(PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.ServiceBus", "5.14.1")),
"TimerTrigger" to listOf(PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.Timer", "4.3.0")),
"SqlTrigger" to listOf(PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.Sql", "3.0.461")),

"DaprPublish" to listOf(
PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.Dapr", "0.17.0-preview01"),
PackageDependency("CloudNative.CloudEvents", "2.7.1")),
"DaprInvoke" to listOf(
PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.Dapr", "0.17.0-preview01"),
PackageDependency("CloudNative.CloudEvents", "2.7.1")),
"DaprState" to listOf(
PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.Dapr", "0.17.0-preview01"),
PackageDependency("CloudNative.CloudEvents", "2.7.1")),
"DaprServiceInvocationTrigger" to listOf(
PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.Dapr", "0.17.0-preview01"),
PackageDependency("CloudNative.CloudEvents", "2.7.1")),
"DaprTopicTrigger" to listOf(
PackageDependency("Microsoft.Azure.Functions.Worker.Extensions.Dapr", "0.17.0-preview01"),
PackageDependency("CloudNative.CloudEvents", "2.7.1")),
)
)
file.extension.equals("cs", true) ||
file.extension.equals("vb", true) ||
file.extension.equals("fs", true)
}

private data class PackageDependency(val id: String, val version: String)

override fun collectNotificationData(project: Project, file: VirtualFile): Function<FileEditor, EditorNotificationPanel?>? {
if (PropertiesComponent.getInstance(project).getBoolean(AzureRiderSettings.DISMISS_NOTIFICATION_AZURE_FUNCTIONS_MISSING_NUPKG)) return null

if (!hasKnownFileSuffix(file)) return null

val fileContent = LoadTextUtil.loadText(file, 4096)

// Check for known marker words
val knownMarker = markerToTriggerMap.filter { fileContent.contains(it.key, true) }.firstOrNull() ?: return null

// Determine project(s) to install into
val installableProjects = WorkspaceModel.getInstance(project)
.getProjectModelEntities(file, project)
.mapNotNull { it.containingProjectEntity() }

if (installableProjects.isEmpty()) return null

// For every known trigger name, verify required dependencies are installed
val riderNuGetFacade = RiderNuGetHost.getInstance(project).facade
val service = FunctionMissingNugetPackageService.getInstance(project)
val missingPackages = service.getMissingPackages(file)
if (missingPackages == null) {
service.checkForMissingPackages(file)
return null
}

for ((triggerName, dependencies) in knownMarker.value) {
for (dependency in dependencies) {
if (fileContent.contains(triggerName, true)) {
for (installableProject in installableProjects) {
if (!riderNuGetFacade.isInstalled(installableProject, dependency.id)) {
return Function { _: FileEditor ->
createNotificationPanel(
file,
riderNuGetFacade,
dependency,
installableProject,
project
)
}
}
}
}
for (missingPackage in missingPackages) {
return Function { _: FileEditor ->
createNotificationPanel(file, missingPackage, project)
}
}

return null
}

private fun createNotificationPanel(
file: VirtualFile,
riderNuGetFacade: RiderNuGetFacade,
dependency: PackageDependency,
installableProject: ProjectModelEntity,
project: Project
file: VirtualFile,
dependency: FunctionMissingNugetPackageService.InstallableDependency,
project: Project
): EditorNotificationPanel {
val panel = EditorNotificationPanel()
.text(RiderAzureBundle.message("notification.function_app.missing_nupkg.title", dependency.id))
.text(RiderAzureBundle.message("notification.function_app.missing_nupkg.title", dependency.dependency.id))

panel.createActionLabel(RiderAzureBundle.message("notification.function_app.missing_nupkg.action.install"), {
// Install, wait, and refresh editor notifications
riderNuGetFacade.installForProject(installableProject.name, dependency.id, dependency.version)

pumpMessages(waitForInstallDuration) {
riderNuGetFacade.isInstalled(installableProject, dependency.id)
}

EditorNotifications.getInstance(project).updateNotifications(file)
val service = FunctionMissingNugetPackageService.getInstance(project)
service.installPackage(file, dependency)
}, true)

panel.createActionLabel(RiderAzureBundle.message("notification.function_app.missing_nupkg.action.dismiss"), {
Expand All @@ -184,9 +86,4 @@ class AzureCoreToolsMissingNupkgNotificationProvider : EditorNotificationProvide
PropertiesComponent.getInstance(project).setValue(AzureRiderSettings.DISMISS_NOTIFICATION_AZURE_FUNCTIONS_MISSING_NUPKG, true)
EditorNotifications.getInstance(project).updateNotifications(file)
}

private fun RiderNuGetFacade.isInstalled(installableProject: ProjectModelEntity, dependencyId: String) = this.host.nuGetProjectModel
.projects[installableProject.getId(project)]
?.explicitPackages?.any { it.id.equals(dependencyId, ignoreCase = true) }
?: false
}
Loading

0 comments on commit 20d30ee

Please sign in to comment.