generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add cURL execution support and HTTP handler extension point
#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
Showing
6 changed files
with
52 additions
and
12 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
core/src/main/kotlin/com/phodal/shirecore/provider/http/HttpHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 19 additions & 5 deletions
24
shirelang/src/main/kotlin/com/phodal/shirelang/compiler/hobbit/execute/ThreadProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
toolsets/httpclient/src/main/kotlin/com/phodal/shire/httpclient/handler/HttpHandler.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters