generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): add smart code insertion feature #24
Added a new feature to insert code at the current cursor position in the editor. This includes a new InsertCodeProcessor and an update to the CodeModifier interface to support smart code insertion. Also, the CodeModifier class has been moved to a new package. The return types of setup, execute, and finish methods in PostProcessor have been changed to Any.
- Loading branch information
Showing
6 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
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
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
33 changes: 33 additions & 0 deletions
33
core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/InsertCodeProcessor.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,33 @@ | ||
package com.phodal.shirecore.middleware.builtin | ||
|
||
import com.intellij.execution.ui.ConsoleView | ||
import com.intellij.openapi.project.Project | ||
import com.phodal.shirecore.provider.codeedit.CodeModifier | ||
import com.phodal.shirecore.middleware.BuiltinPostHandler | ||
import com.phodal.shirecore.middleware.PostCodeHandleContext | ||
import com.phodal.shirecore.middleware.PostProcessor | ||
|
||
class InsertCodeProcessor : PostProcessor { | ||
override val processorName: String = BuiltinPostHandler.InsertCode.handleName | ||
|
||
override fun isApplicable(context: PostCodeHandleContext): Boolean { | ||
return true | ||
} | ||
|
||
override fun execute(project: Project, context: PostCodeHandleContext, console: ConsoleView?): String { | ||
if (context.currentLanguage == null || context.currentFile == null) { | ||
console?.print("No found current language\n", com.intellij.execution.ui.ConsoleViewContentType.ERROR_OUTPUT) | ||
return "" | ||
} | ||
|
||
|
||
val codeModifier = CodeModifier.forLanguage(context.currentLanguage!!) | ||
if (codeModifier == null) { | ||
console?.print("No code modifier found\n", com.intellij.execution.ui.ConsoleViewContentType.ERROR_OUTPUT) | ||
return "" | ||
} | ||
|
||
codeModifier.smartInsert(context.currentFile!!.virtualFile!!, project, context.genText ?: "") | ||
return "" | ||
} | ||
} |
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
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
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