Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy backend to the new version #739

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions PluginsAndFeatures/azure-toolkit-for-rider/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ bin/
# Jar dependencies generated in build
**/resources/spark/spark-tools-*.jar

# Rider Protocol generated files
*Generated.kt

# Rider Protocol and Inspections generated files
*Generated.cs

# Build results
[Dd]ebug/
[Rr]elease/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions PluginsAndFeatures/azure-toolkit-for-rider/ReSharper.Azure.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D7AED5E7-CF45-4740-A0D8-DA638A964069}"
ProjectSection(SolutionItems) = preProject
src\dotnet\Directory.Build.props = src\dotnet\Directory.Build.props
CHANGELOG.md = CHANGELOG.md
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Psi", "src\dotnet\ReSharper.Azure\Azure.Psi\Azure.Psi.csproj", "{90893DE8-F9A4-4970-BE08-0A5E3EB97E1E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Daemon", "src\dotnet\ReSharper.Azure\Azure.Daemon\Azure.Daemon.csproj", "{1E66ACB9-DE07-4961-AAD6-B87DB5B419E0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -23,5 +29,13 @@ Global
{89B4800D-245A-49F5-94C6-E45D239EFA84}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89B4800D-245A-49F5-94C6-E45D239EFA84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89B4800D-245A-49F5-94C6-E45D239EFA84}.Release|Any CPU.Build.0 = Release|Any CPU
{90893DE8-F9A4-4970-BE08-0A5E3EB97E1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90893DE8-F9A4-4970-BE08-0A5E3EB97E1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90893DE8-F9A4-4970-BE08-0A5E3EB97E1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90893DE8-F9A4-4970-BE08-0A5E3EB97E1E}.Release|Any CPU.Build.0 = Release|Any CPU
{1E66ACB9-DE07-4961-AAD6-B87DB5B419E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E66ACB9-DE07-4961-AAD6-B87DB5B419E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E66ACB9-DE07-4961-AAD6-B87DB5B419E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E66ACB9-DE07-4961-AAD6-B87DB5B419E0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies {
runtimeOnly(project(path = ":azure-intellij-plugin-appservice", configuration = "instrumentedJar"))
compileOnly(project(path = ":azure-intellij-resource-connector-lib"))
runtimeOnly(project(path = ":azure-intellij-resource-connector-lib", configuration = "instrumentedJar"))
compileOnly(project(path = ":azure-intellij-plugin-resharper-host"))
runtimeOnly(project(path = ":azure-intellij-plugin-resharper-host", configuration = "instrumentedJar"))
implementation("com.microsoft.azure:azure-toolkit-appservice-lib")
implementation("com.microsoft.azure:azure-toolkit-ide-appservice-lib")
implementation("com.microsoft.azure:azure-toolkit-ide-containerregistry-lib")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import com.microsoft.azure.toolkit.lib.common.utils.JsonUtils

private const val AZURE_FUNCTIONS_APP_SETTINGS = "Azure Functions App Settings"

// Known and supported list of tags from https://github.com/Azure/azure-functions-tooling-feed/blob/main/cli-feed-v4.json
val FUNCTIONS_CORE_TOOLS_KNOWN_SUPPORTED_VERSIONS = listOf("v2", "v3", "v4")

// Latest supported version by the Azure Toolkit for Rider
const val FUNCTIONS_CORE_TOOLS_LATEST_SUPPORTED_VERSION = "v4"

fun saveAppSettingsToSecurityStorage(key: String?, appSettings: Map<String, String>) {
if (key.isNullOrEmpty()) {
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2018-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
*/

package com.microsoft.azure.toolkit.intellij.legacy.function.codeInspection.msbuild

import com.intellij.codeInspection.*
import com.intellij.openapi.project.Project
import com.intellij.psi.XmlElementFactory
import com.intellij.psi.XmlElementVisitor
import com.intellij.psi.impl.source.tree.CompositeElement
import com.intellij.psi.xml.XmlChildRole
import com.intellij.psi.xml.XmlElementType
import com.intellij.psi.xml.XmlTag
import com.intellij.xml.util.XmlUtil
import com.microsoft.azure.toolkit.intellij.legacy.function.FUNCTIONS_CORE_TOOLS_KNOWN_SUPPORTED_VERSIONS

class AzureFunctionsVersionInspection : XmlSuppressableInspectionTool() {
companion object {
const val PROPERTY_AZURE_FUNCTIONS_VERSION = "AzureFunctionsVersion"
}

override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = object : XmlElementVisitor() {
override fun visitXmlTag(tag: XmlTag) {
val tagName = tag.name.lowercase()
if (tagName.equals(PROPERTY_AZURE_FUNCTIONS_VERSION, ignoreCase = true)) {
val child = XmlChildRole.START_TAG_END_FINDER.findChild(tag.node)
?: XmlChildRole.EMPTY_TAG_END_FINDER.findChild(tag.node)
if (child != null) {
val node = child.treeNext

val isVersionNotSpecified = node == null || node.elementType !== XmlElementType.XML_TEXT
val isVersionUnsupported = node != null &&
node.elementType === XmlElementType.XML_TEXT &&
FUNCTIONS_CORE_TOOLS_KNOWN_SUPPORTED_VERSIONS.none {
it.equals(node.text, ignoreCase = true)
}

if (isVersionNotSpecified || isVersionUnsupported) {
val versionQuickFixes = FUNCTIONS_CORE_TOOLS_KNOWN_SUPPORTED_VERSIONS.reversed()
.filterNot { it.contains('-') } // only show release versions
.map { SetVersionQuickFix(it) }
.toTypedArray<LocalQuickFix>()

holder.registerProblem(tag,
if (isVersionNotSpecified)
"Azure Functions version not specified"
else
"Unsupported Azure Functions version",
ProblemHighlightType.WARNING,
*versionQuickFixes)
}
}
}
}
}

private class SetVersionQuickFix(val version: String) : LocalQuickFix {
override fun getFamilyName() = "Set Azure Functions version '$version'"

override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
val tag = descriptor.psiElement as XmlTag

XmlUtil.expandTag(tag)

val newTag = XmlElementFactory.getInstance(tag.project)
.createTagFromText("<${tag.name}>$version</${tag.name}>")

val node = tag.node as? CompositeElement ?: return

node.replaceAllChildrenToChildrenOf(newTag.node)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2018-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
*/

package com.microsoft.azure.toolkit.intellij.legacy.function.completion.csharp

import com.jetbrains.rider.completion.ProtocolCompletionContributor

class TimerTriggerCompletionContributor : ProtocolCompletionContributor() {
/**
* Override default Rider behavior to terminate on first digit prefix.
*
* Please note, this is a global behavior. There is no option for now to handle this for a particular completion case.
* Please consider switching back if cause any issues in future.
*/
override fun shouldStopOnPrefix(prefix: String, isAutoPopup: Boolean): Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

package com.microsoft.azure.toolkit.intellij.legacy.function.coreTools

data class FunctionsCoreToolsInfo(val coreToolsPath: String, val coreToolsExecutable: String)
data class FunctionCoreToolsInfo(val coreToolsPath: String, val coreToolsExecutable: String)
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import com.microsoft.azure.toolkit.lib.appservice.utils.FunctionCliResolver
import java.io.File

@Service
class FunctionsCoreToolsInfoProvider {
class FunctionCoreToolsInfoProvider {
companion object {
fun getInstance(): FunctionsCoreToolsInfoProvider = service()
fun getInstance(): FunctionCoreToolsInfoProvider = service()

private val LOG = logger<FunctionsCoreToolsInfoProvider>()
private val LOG = logger<FunctionCoreToolsInfoProvider>()
}

suspend fun retrieveForVersion(
azureFunctionsVersion: String,
allowDownload: Boolean
): FunctionsCoreToolsInfo? {
): FunctionCoreToolsInfo? {
application.assertIsNonDispatchThread()

val coreToolsFromConfiguration = retrieveFromConfiguration(azureFunctionsVersion)
Expand All @@ -43,7 +43,7 @@ class FunctionsCoreToolsInfoProvider {
return null
}

private fun retrieveFromConfiguration(azureFunctionsVersion: String): FunctionsCoreToolsInfo? {
private fun retrieveFromConfiguration(azureFunctionsVersion: String): FunctionCoreToolsInfo? {
val settings = AzureFunctionSettings.getInstance()
val toolsPathEntries = settings.azureCoreToolsPathEntries
LOG.debug("Azure Core Tools path entries: ${toolsPathEntries.joinToString { "${it.functionsVersion}: ${it.coreToolsPath}" }}")
Expand Down Expand Up @@ -73,8 +73,8 @@ class FunctionsCoreToolsInfoProvider {
private suspend fun retrieveFromFeed(
azureFunctionsVersion: String,
allowDownload: Boolean
): FunctionsCoreToolsInfo? {
val coreToolsPathFromFeed = FunctionsCoreToolsManager.getInstance().demandCoreToolsPathForVersion(
): FunctionCoreToolsInfo? {
val coreToolsPathFromFeed = FunctionCoreToolsManager.getInstance().demandCoreToolsPathForVersion(
azureFunctionsVersion,
Registry.get("azure.function_app.core_tools.feed.url").asString(),
allowDownload
Expand All @@ -86,7 +86,7 @@ class FunctionsCoreToolsInfoProvider {
return null
}

private fun resolveFromPath(funcCoreToolsPath: File): FunctionsCoreToolsInfo? {
private fun resolveFromPath(funcCoreToolsPath: File): FunctionCoreToolsInfo? {
val patchedPath = patchCoreToolsPath(funcCoreToolsPath)

val executablePath = if (SystemInfo.isWindows) {
Expand All @@ -108,7 +108,7 @@ class FunctionsCoreToolsInfoProvider {
}
}

return FunctionsCoreToolsInfo(patchedPath.path, executablePath.path)
return FunctionCoreToolsInfo(patchedPath.path, executablePath.path)
}

private fun patchCoreToolsPath(funcCoreToolsPath: File): File {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import java.io.IOException
import java.net.UnknownHostException

@Service
class FunctionsCoreToolsManager {
class FunctionCoreToolsManager {
companion object {
fun getInstance(): FunctionsCoreToolsManager = service()
fun getInstance(): FunctionCoreToolsManager = service()

private val LOG = logger<FunctionsCoreToolsManager>()
private val LOG = logger<FunctionCoreToolsManager>()
}

private val releaseCache = concurrentMapOf<String, FunctionCoreToolsRelease>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2018-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
*/

package com.microsoft.azure.toolkit.intellij.legacy.function.coreTools

import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.jetbrains.rider.azure.model.AzureFunctionsVersionRequest
import com.jetbrains.rider.azure.model.functionAppDaemonModel
import com.jetbrains.rider.projectView.solution

@Service
class FunctionCoreToolsMsBuildService {
companion object {
fun getInstance(): FunctionCoreToolsMsBuildService = service()
}

suspend fun requestAzureFunctionsVersion(project: Project, projectFilePath: String) =
project.solution.functionAppDaemonModel.getAzureFunctionsVersion
.startSuspending(AzureFunctionsVersionRequest(projectFilePath))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2018-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
*/

package com.microsoft.azure.toolkit.intellij.legacy.function.daemon

import com.jetbrains.rider.model.RunnableProjectKind

object AzureRunnableProjectKinds {
val AzureFunctions = RunnableProjectKind("AzureFunctions")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2018-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
*/

@file:Suppress("UnstableApiUsage")

package com.microsoft.azure.toolkit.intellij.legacy.function.daemon

import com.intellij.execution.Executor
import com.intellij.execution.RunManager
import com.intellij.execution.RunnerAndConfigurationSettings
import com.intellij.execution.executors.DefaultDebugExecutor
import com.intellij.execution.executors.DefaultRunExecutor
import com.intellij.openapi.client.ClientProjectSession
import com.intellij.openapi.project.Project
import com.jetbrains.rd.protocol.SolutionExtListener
import com.jetbrains.rd.ui.bedsl.extensions.valueOrEmpty
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rider.azure.model.FunctionAppDaemonModel
import com.jetbrains.rider.model.RunnableProject
import com.jetbrains.rider.model.runnableProjectsModel
import com.jetbrains.rider.projectView.solution

class FunctionAppSolutionExtListener : SolutionExtListener<FunctionAppDaemonModel> {
override fun extensionCreated(lifetime: Lifetime, session: ClientProjectSession, model: FunctionAppDaemonModel) {
model.runFunctionApp.advise(lifetime) {
runConfiguration(
functionName = it.functionName,
runnableProject = getRunnableProject(session.project, it.projectFilePath),
executor = DefaultRunExecutor.getRunExecutorInstance(),
project = session.project
)
}
model.debugFunctionApp.advise(lifetime) {
runConfiguration(
functionName = it.functionName,
runnableProject = getRunnableProject(session.project, it.projectFilePath),
executor = DefaultDebugExecutor.getDebugExecutorInstance(),
project = session.project
)
}
model.triggerFunctionApp.advise(lifetime) {
// val triggerAction = TriggerAzureFunctionAction(functionName = triggerFunctionRequest.functionName)
//
// ActionUtil.invokeAction(
// triggerAction,
// SimpleDataContext.getProjectContext(project),
// ActionPlaces.EDITOR_GUTTER_POPUP,
// null,
// null
// )
}
}

private fun getRunnableProject(project: Project, expectedProjectPath: String): RunnableProject {
val runnableProjects = project.solution.runnableProjectsModel.projects.valueOrEmpty()
return runnableProjects.find { runnableProject ->
runnableProject.projectFilePath == expectedProjectPath && runnableProject.kind == AzureRunnableProjectKinds.AzureFunctions
}
?: throw IllegalStateException(
"Unable to find a project to run with path: '$expectedProjectPath', available project paths: " +
runnableProjects.joinToString(", ", "'", "'") { it.projectFilePath }
)
}

private fun runConfiguration(
functionName: String?,
runnableProject: RunnableProject,
executor: Executor,
project: Project
) {
val runManager = RunManager.getInstance(project)
val existingSettings = findExistingConfigurationSettings(functionName, runnableProject.projectFilePath)

}

private fun findExistingConfigurationSettings(
functionName: String?,
projectFilePath: String
): RunnerAndConfigurationSettings? {
return null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2018-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
*/

package com.microsoft.azure.toolkit.intellij.legacy.function.settings.templates

import com.intellij.openapi.options.Configurable
import com.jetbrains.rider.settings.simple.SimpleOptionsPage

class RiderAzureCSharpFileTemplatesOptionPage :
SimpleOptionsPage("Azure (C#)", "RiderAzureCSharpFileTemplatesSettings"), Configurable.NoScroll {
override fun getId() = pageId + "Id"
}
Loading