Skip to content

Commit

Permalink
feat(http-client): add support for creating HttpRequestRunConfiguration
Browse files Browse the repository at this point in the history
#198

Add logic to create and manage HttpRequestRunConfiguration instances in the IntellijHttpClientExecutor.kt file.
  • Loading branch information
phodal committed May 30, 2024
1 parent cbdc2bb commit 30efd49
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package cc.unitmesh.httpclient

import cc.unitmesh.devti.provider.http.HttpClientProvider
import com.intellij.execution.Executor
import com.intellij.execution.RunManager
import com.intellij.execution.RunnerAndConfigurationSettings
import com.intellij.execution.actions.ConfigurationContext
import com.intellij.httpClient.http.request.run.HttpRequestExecutorExtensionFactory
import com.intellij.httpClient.http.request.run.HttpRequestRunConfigurationExecutor
import com.intellij.httpClient.http.request.run.config.HttpRequestRunConfiguration
import com.intellij.httpClient.http.request.run.config.HttpRequestRunConfigurationType
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiFile
Expand All @@ -21,9 +23,20 @@ class IntellijHttpClientExecutor : HttpClientProvider {
?.firstOrNull()
?.configurationSettings ?: return

// runner.configuration?.apply {
// this as HttpRequestRunConfiguration
// }

val factory = HttpRequestRunConfigurationType.getInstance().configurationFactories[0]
val configuration = HttpRequestRunConfiguration(project, factory, "HttpRequest")

val runManager: RunManager = RunManager.getInstance(project)
runManager.setUniqueNameIfNeeded(configuration)
runManager.addConfiguration(runner)

runner.isTemporary = true

val selectedRunner = runManager.selectedConfiguration
if ((selectedRunner == null || selectedRunner.isTemporary) && runManager.shouldSetRunConfigurationFromContext()) {
runManager.selectedConfiguration = runner
}

val executor: Executor = HttpRequestExecutorExtensionFactory.getRunExtension().executor ?: return
HttpRequestRunConfigurationExecutor.getInstance().execute(
Expand Down

0 comments on commit 30efd49

Please sign in to comment.