Skip to content

Commit

Permalink
feat(core): add cURL execution support and HTTP handler extension point
Browse files Browse the repository at this point in the history
#11

Add the ability to execute cURL commands within the application and provide an extension point for custom HTTP handlers. This includes changes to the ThreadProcessor to handle cURL script execution, introduction of the HttpHandler interface with an extension point for dynamic handler registration, and a new CUrlHttpHandler class to handle cURL-specific requests.
  • Loading branch information
phodal committed Aug 25, 2024
1 parent c5afe33 commit 2717014
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.phodal.shirecore.provider.http

import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.project.Project

interface HttpHandler {
fun isApplicable(type: HttpHandlerType): Boolean

fun execute(project: Project, content: String) : String?

companion object {
private val EP_NAME: ExtensionPointName<HttpHandler> =
ExtensionPointName("com.phodal.shireHttpHandler")

fun provide(type: HttpHandlerType): HttpHandler? {
return EP_NAME.extensionList.find { it.isApplicable(type) }
}
}
}

enum class HttpHandlerType(val id: String) {
CURL("cURL"),
}
4 changes: 4 additions & 0 deletions core/src/main/resources/com.phodal.shirecore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
<extensionPoint qualifiedName="com.phodal.shireTerminalExecutor"
interface="com.phodal.shirecore.provider.action.TerminalLocationExecutor"
dynamic="true"/>

<extensionPoint qualifiedName="com.phodal.shireHttpHandler"
interface="com.phodal.shirecore.provider.http.HttpHandler"
dynamic="true"/>
</extensionPoints>

<extensions defaultExtensionNs="JavaScript.JsonSchema">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
package com.phodal.shirelang.compiler.hobbit.execute

import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.readText
import com.intellij.psi.PsiManager
import com.phodal.shirecore.provider.http.HttpHandler
import com.phodal.shirecore.provider.http.HttpHandlerType
import com.phodal.shirecore.provider.shire.FileRunService
import com.phodal.shirelang.utils.lookupFile

object ThreadProcessor {
fun execute(myProject: Project, fileName: String): Any {
val lookupFile = myProject.lookupFile(fileName) ?: return "File not found: $fileName"
fun execute(myProject: Project, fileName: String): String {
val file = myProject.lookupFile(fileName) ?: return "File not found: $fileName"

// todo: waiting for execute
val content = file.readText()

// todo: waiting for execute
// if ends with .cURL.sh, try call cURL service
if (file.name.lowercase().endsWith(".curl.sh")) {
// call cURL service
val execute = HttpHandler.provide(HttpHandlerType.CURL)?.execute(myProject, content)
if (execute != null) {
return execute
}
}

// lookup bash execute in async
val psiFile = PsiManager.getInstance(myProject).findFile(file) ?: return "File not found: $fileName"

return lookupFile
return FileRunService.provider(myProject, file)?.runFile(myProject, file, psiFile) ?: "No run service found"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package com.phodal.shire.httpclient.handler

import com.intellij.openapi.project.Project
import com.phodal.shire.httpclient.converter.CUrlConverter
import com.phodal.shirecore.provider.http.HttpHandler
import com.phodal.shirecore.provider.http.HttpHandlerType
import okhttp3.OkHttpClient

class CUrlHttpHandler : HttpHandler {
override fun isApplicable(type: HttpHandlerType): Boolean = type == HttpHandlerType.CURL

override fun execute(project: Project, content: String): String? {
val client = OkHttpClient()
val request = CUrlConverter.convert(project, content)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@

<extensions defaultExtensionNs="com.phodal">
<shireFileRunService implementation="com.phodal.shire.httpclient.HttpClientFileRunService"/>

<shireHttpHandler implementation="com.phodal.shire.httpclient.handler.CUrlHttpHandler"/>
</extensions>
</idea-plugin>

0 comments on commit 2717014

Please sign in to comment.