Skip to content

Commit

Permalink
refactor(compiler): rename InsCommand to ShireCommand
Browse files Browse the repository at this point in the history
Renamed InsCommand interface to ShireCommand for clarity and consistency.
  • Loading branch information
phodal committed May 31, 2024
1 parent 840667a commit 8266b93
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.phodal.shirelang.compiler

import com.phodal.shirelang.agenttool.browse.BrowseTool
import com.phodal.shirelang.compiler.exec.InsCommand
import com.phodal.shirelang.compiler.exec.ShireCommand
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.project.Project

class BrowseInsCommand(val myProject: Project, private val prop: String) : InsCommand {
override suspend fun execute(): String? {
class BrowseShireCommand(val myProject: Project, private val prop: String) : ShireCommand {
override suspend fun doExecute(): String? {
var body: String? = null
runInEdt {
val parse = BrowseTool.parse(prop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,84 +161,82 @@ class ShireCompiler(
}

private fun processingCommand(commandNode: BuiltinCommand, prop: String, used: ShireUsed, fallbackText: String) {
val command: InsCommand = when (commandNode) {
val command: ShireCommand = when (commandNode) {
BuiltinCommand.FILE -> {
FileInsCommand(myProject, prop)
FileShireCommand(myProject, prop)
}

BuiltinCommand.REV -> {
RevInsCommand(myProject, prop)
RevShireCommand(myProject, prop)
}

BuiltinCommand.SYMBOL -> {
result.isLocalCommand = true
SymbolInsCommand(myProject, prop)
SymbolShireCommand(myProject, prop)
}

BuiltinCommand.WRITE -> {
result.isLocalCommand = true
val devInCode: CodeBlockElement? = lookupNextCode(used)
if (devInCode == null) {
PrintInsCommand("/" + commandNode.commandName + ":" + prop)
PrintShireCommand("/" + commandNode.commandName + ":" + prop)
} else {
WriteInsCommand(myProject, prop, devInCode.text, used)
WriteShireCommand(myProject, prop, devInCode.text, used)
}
}

BuiltinCommand.PATCH -> {
result.isLocalCommand = true
val devInCode: CodeBlockElement? = lookupNextCode(used)
if (devInCode == null) {
PrintInsCommand("/" + commandNode.commandName + ":" + prop)
PrintShireCommand("/" + commandNode.commandName + ":" + prop)
} else {
PatchInsCommand(myProject, prop, devInCode.text)
PatchShireCommand(myProject, prop, devInCode.text)
}
}

BuiltinCommand.COMMIT -> {
result.isLocalCommand = true
val devInCode: CodeBlockElement? = lookupNextCode(used)
if (devInCode == null) {
PrintInsCommand("/" + commandNode.commandName + ":" + prop)
PrintShireCommand("/" + commandNode.commandName + ":" + prop)
} else {
CommitInsCommand(myProject, devInCode.text)
CommitShireCommand(myProject, devInCode.text)
}
}

BuiltinCommand.RUN -> {
result.isLocalCommand = true
RunInsCommand(myProject, prop)
RunShireCommand(myProject, prop)
}

BuiltinCommand.FILE_FUNC -> {
result.isLocalCommand = true
FileFuncInsCommand(myProject, prop)
FileFuncShireCommand(myProject, prop)
}

BuiltinCommand.SHELL -> {
result.isLocalCommand = true
ShellInsCommand(myProject, prop)
ShellShireCommand(myProject, prop)
}

BuiltinCommand.BROWSE -> {
result.isLocalCommand = true
BrowseInsCommand(myProject, prop)
BrowseShireCommand(myProject, prop)
}

BuiltinCommand.Refactor -> {
result.isLocalCommand = true
val nextTextSegment = lookupNextTextSegment(used)
RefactorInsCommand(myProject, prop, nextTextSegment)
}

else -> {
PrintInsCommand("/" + commandNode.commandName + ":" + prop)
RefactorShireCommand(myProject, prop, nextTextSegment)
}
}

val execResult = runBlocking { command.execute() }
val execResult = runBlocking {
command.doExecute()
}

val isSucceed = execResult?.contains("$SHIRE_ERROR") == false
val isSucceed = execResult?.contains(SHIRE_ERROR) == false
val result = if (isSucceed) {
val hasReadCodeBlock = commandNode in listOf(
BuiltinCommand.WRITE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.phodal.shirelang.compiler.exec
import com.intellij.openapi.project.Project
import com.phodal.shirelang.utils.Code

class CommitInsCommand(val myProject: Project, val code: String) : InsCommand {
override suspend fun execute(): String {
class CommitShireCommand(val myProject: Project, val code: String) : ShireCommand {
override suspend fun doExecute(): String {
val commitMsg = Code.parse(code).text

// val changeListManager = ChangeListManager.getInstance(myProject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.intellij.openapi.vfs.VirtualFile
import com.phodal.shirelang.completion.dataprovider.FileFunc
import com.phodal.shirelang.utils.canBeAdded

class FileFuncInsCommand(val myProject: Project, val prop: String) : InsCommand {
override suspend fun execute(): String? {
class FileFuncShireCommand(val myProject: Project, val prop: String) : ShireCommand {
override suspend fun doExecute(): String? {
val (functionName, args) = parseRegex(prop)
?: return """$SHIRE_ERROR: file-func is not in the format @file-func:<functionName>(<arg1>, <arg2>, ...)
|Example: @file-func:regex(".*\.kt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import com.phodal.shirelang.utils.lookupFile
* @param prop the property string containing the file name and optional line range
*
*/
class FileInsCommand(private val myProject: Project, private val prop: String) : InsCommand {
private val logger = logger<FileInsCommand>()
class FileShireCommand(private val myProject: Project, private val prop: String) : ShireCommand {
private val logger = logger<FileShireCommand>()
private val output = StringBuilder()

override suspend fun execute(): String? {
override suspend fun doExecute(): String? {
val range: LineInfo? = LineInfo.fromString(prop)

// prop name can be src/file.name#L1-L2
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import com.intellij.openapi.vcs.changes.patch.ApplyPatchDefaultExecutor
import com.intellij.openapi.vcs.changes.patch.MatchPatchPaths
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.containers.MultiMap
import com.phodal.shirelang.compiler.exec.InsCommand

class PatchInsCommand(val myProject: Project, val prop: String, val codeContent: String) : InsCommand {
override suspend fun execute(): String? {
class PatchShireCommand(val myProject: Project, val prop: String, val codeContent: String) : ShireCommand {
override suspend fun doExecute(): String? {
FileDocumentManager.getInstance().saveAllDocuments()

val shelfExecutor = ApplyPatchDefaultExecutor(myProject)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.phodal.shirelang.compiler.exec

class PrintShireCommand(private val value: String) : ShireCommand {
override suspend fun doExecute(): String {
return value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ import com.phodal.shirelang.psi.ShireFile
*
* This class is designed to be used within a refactoring tool or plugin that provides built-in refactoring commands.
* It demonstrates how to handle different refactoring scenarios*/
class RefactorInsCommand(val myProject: Project, private val argument: String, private val textSegment: String) :
InsCommand {
override suspend fun execute(): String? {
class RefactorShireCommand(val myProject: Project, private val argument: String, private val textSegment: String) :
ShireCommand {
override suspend fun doExecute(): String? {
var currentEditFile: PsiFile? = null
val editor = FileEditorManager.getInstance(myProject).selectedTextEditor
if (editor != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package com.phodal.shirelang.compiler.exec

import com.intellij.openapi.project.Project


/**
* RevAutoCommand is used to execute a command that retrieves the committed change list for a given revision using Git.
*
* @param myProject the Project instance associated with the command
* @param revision the Git revision for which the committed change list is to be retrieved
*
*/
class RevInsCommand(private val myProject: Project, private val revision: String) : InsCommand {
override suspend fun execute(): String? {
class RevShireCommand(private val myProject: Project, private val revision: String) : ShireCommand {
override suspend fun doExecute(): String? {
throw NotImplementedError()

// val repository = GitRepositoryManager.getInstance(myProject).repositories.firstOrNull() ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import com.phodal.shirelang.utils.lookupFile
* @property argument The name of the file to find and run tests for.
*
*/
class RunInsCommand(val myProject: Project, private val argument: String) : InsCommand {
override suspend fun execute(): String? {
class RunShireCommand(val myProject: Project, private val argument: String) : ShireCommand {
override suspend fun doExecute(): String? {
val virtualFile = myProject.lookupFile(argument.trim()) ?: return "$SHIRE_ERROR: File not found: $argument"
try {
// val psiFile: PsiFile =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import com.phodal.shirelang.utils.lookupFile
* @param myProject The current project context.
* @param argument The path to the file within the project whose content should be executed as a shell command.
*/
class ShellInsCommand(val myProject: Project, private val argument: String) : InsCommand {
override suspend fun execute(): String? {
class ShellShireCommand(val myProject: Project, private val argument: String) : ShireCommand {
override suspend fun doExecute(): String? {
val virtualFile = myProject.lookupFile(argument.trim()) ?: return "$SHIRE_ERROR: File not found: $argument"
val psiFile = PsiManager.getInstance(myProject).findFile(virtualFile) as? ShFile
// val settings: RunnerAndConfigurationSettings? = ShellRunService().createRunSettings(myProject, virtualFile, psiFile)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.phodal.shirelang.compiler.exec

interface ShireCommand {
suspend fun doExecute(): String?
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import com.phodal.shirelang.compiler.error.SHIRE_ERROR
import com.intellij.openapi.project.Project
import com.phodal.shirelang.provider.ShireSymbolProvider

class SymbolInsCommand(val myProject: Project, val prop: String) :
InsCommand {
override suspend fun execute(): String {
class SymbolShireCommand(val myProject: Project, val prop: String) :
ShireCommand {
override suspend fun doExecute(): String {
val result = ShireSymbolProvider.all().mapNotNull {
val found = it.resolveSymbol(myProject, prop)
if (found.isEmpty()) return@mapNotNull null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import com.phodal.shirelang.psi.ShireUsed
import com.phodal.shirelang.utils.Code
import com.phodal.shirelang.utils.lookupFile

class WriteInsCommand(val myProject: Project, val argument: String, val content: String, val used: ShireUsed) :
InsCommand {
class WriteShireCommand(val myProject: Project, val argument: String, val content: String, val used: ShireUsed) :
ShireCommand {
private val pathSeparator = "/"

override suspend fun execute(): String? {
override suspend fun doExecute(): String? {
val content = Code.parse(content).text

val range: LineInfo? = LineInfo.fromString(used.text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface AgentTool {

// extension point
companion object {
val EP_NAME = ExtensionPointName<AgentTool>("com.phodal.shireAgentTool")
val EP_NAME = ExtensionPointName<AgentTool>("shire.agentTool")

fun allTools(): List<AgentTool> {
return EP_NAME.extensionList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface ShireSymbolProvider {

companion object {
private val EP_NAME: ExtensionPointName<ShireSymbolProvider> =
ExtensionPointName("com.phodal.shireCompletionProvider")
ExtensionPointName("shire.symbolProvider")

fun all(): List<ShireSymbolProvider> {
return EP_NAME.extensionList
Expand Down
1 change: 0 additions & 1 deletion language/src/main/resources/com.phodal.shirelang.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
</extensionPoints>

<extensions defaultExtensionNs="com.intellij">
<!-- refs: https://github.com/JetBrains/intellij-sdk-code-samples/blob/main/simple_language_plugin/src/main/resources/META-INF/plugin.xml-->
<fileType name="ShireFile" implementationClass="com.phodal.shirelang.ShireFileType" fieldName="INSTANCE"
language="Shire" extensions="shire"/>

Expand Down

0 comments on commit 8266b93

Please sign in to comment.