Skip to content

Commit

Permalink
feat: change inlay complete code trigger: use shortcut key instead of…
Browse files Browse the repository at this point in the history
… automatic
  • Loading branch information
jialiu-github committed Mar 20, 2024
1 parent 30b9757 commit 581e56d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 7 deletions.
30 changes: 30 additions & 0 deletions src/233/main/resources/META-INF/autodev-core.xml
Expand Up @@ -29,6 +29,14 @@

<applicationService serviceImplementation="cc.unitmesh.devti.settings.AutoDevSettingsState"/>

<applicationService
serviceInterface="cc.unitmesh.devti.editor.inlay.LLMInlayManager"
serviceImplementation="cc.unitmesh.devti.editor.inlay.LLMInlayManagerImpl"/>

<typedHandler order="first, before completionAutoPopup"
implementation="cc.unitmesh.devti.editor.inlay.TypeOverHandler"/>


<statusBarWidgetFactory id="AIAssistant"
implementation="cc.unitmesh.devti.statusbar.AutoDevStatusBarWidgetFactory"/>

Expand Down Expand Up @@ -173,6 +181,11 @@
</applicationListeners>

<extensions defaultExtensionNs="cc.unitmesh">
<autoDevIntention>
<className>cc.unitmesh.devti.intentions.action.CodeCompletionInlayIntention</className>
<bundleName>messages.AutoDevBundle</bundleName>
<categoryKey>intention.category.llm</categoryKey>
</autoDevIntention>
<autoDevIntention>
<className>cc.unitmesh.devti.intentions.action.NewChatWithCodeBaseIntention</className>
<bundleName>messages.AutoDevBundle</bundleName>
Expand All @@ -198,6 +211,23 @@
</extensions>

<actions>
<action id="llm.applyInlays"
class="cc.unitmesh.devti.actions.LLMApplyInlaysAction">
<keyboard-shortcut first-keystroke="TAB" keymap="$default"/>
<override-text place="MainMenu" text="Apply Completions to Editor"/>
<override-text place="EditorPopup" text="Accept"/>
</action>

<action id="cc.unitmesh.devti.inlayCompleteCode"
class="cc.unitmesh.devti.actions.InlayCompleteCodeAction"
text="Inlay Complete Code"
description="Inlay complete code!"
>
<keyboard-shortcut keymap="$default" first-keystroke="control PERIOD"/>

<add-to-group group-id="ShowIntentionsGroup" relative-to-action="ShowIntentionActions" anchor="after"/>
</action>

<group id="AutoDevIntentionsActionGroup" class="cc.unitmesh.devti.intentions.IntentionsActionGroup"
icon="cc.unitmesh.devti.AutoDevIcons.AI_COPILOT" searchable="false">

Expand Down
@@ -0,0 +1,27 @@
package cc.unitmesh.devti.actions

import cc.unitmesh.devti.editor.inlay.LLMInlayManager
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.command.CommandProcessor

/**
* A quick insight action is an action that can be triggered by a user,
* user can input custom text to call with LLM.
*/
class InlayCompleteCodeAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val dataContext = e.dataContext
val editor = dataContext.getData(CommonDataKeys.EDITOR) ?: return
val project = dataContext.getData(CommonDataKeys.PROJECT) ?: return
if (project.isDisposed) return;

val commandProcessor = CommandProcessor.getInstance()
if (commandProcessor.isUndoTransparentActionInProgress) return

val llmInlayManager = LLMInlayManager.getInstance()
llmInlayManager.editorModified(editor)
}
}

Expand Up @@ -6,6 +6,7 @@ import com.intellij.openapi.editor.event.*
import com.intellij.openapi.editor.ex.util.EditorUtil
import com.intellij.openapi.util.Disposer

@Deprecated("This listener is for automatic code completion triggering. Due to incomplete user interaction logic and massive development workload, it will be replaced by shortcut key triggering which implement by InlayCodeAction")
class AutoDevEditorListener : EditorFactoryListener {
override fun editorCreated(event: EditorFactoryEvent) {
val editor = event.editor
Expand Down
Expand Up @@ -2,12 +2,12 @@ package cc.unitmesh.devti.intentions.action

import cc.unitmesh.devti.AutoDevBundle
import cc.unitmesh.devti.editor.inlay.LLMInlayManager
import cc.unitmesh.devti.intentions.action.base.AbstractChatIntention
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile

class CodeCompletionInlayIntention : AbstractChatIntention() {
class CodeCompletionInlayIntention : ChatBaseIntention() {
override fun priority(): Int = 980
override fun getText(): String = AutoDevBundle.message("intentions.chat.inlay.complete.name")
override fun getFamilyName(): String = AutoDevBundle.message("intentions.chat.inlay.complete.family.name")
Expand Down
@@ -1,19 +1,18 @@
package com.intellij.temporary.inlay.presentation

import com.intellij.codeInsight.codeVision.CodeVisionEntry
import com.intellij.temporary.inlay.presentation.PresentationUtil.fontMetrics
import com.intellij.temporary.inlay.presentation.PresentationUtil.getFont
import com.intellij.temporary.inlay.presentation.PresentationUtil.getThemeInfoProvider
import com.intellij.codeInsight.codeVision.ui.model.RangeCodeVisionModel
import com.intellij.codeInsight.codeVision.ui.renderers.painters.ICodeVisionEntryBasePainter
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.temporary.inlay.presentation.PresentationUtil.fontMetrics
import com.intellij.temporary.inlay.presentation.PresentationUtil.getFont
import com.intellij.temporary.inlay.presentation.PresentationUtil.getThemeInfoProvider
import com.intellij.ui.paint.EffectPainter2D
import com.intellij.util.ui.GraphicsUtil
import java.awt.*
import java.awt.geom.Rectangle2D
import javax.swing.Icon
import javax.swing.text.StyleConstants
import kotlin.math.ceil

Expand All @@ -27,7 +26,7 @@ class LLMTextInlayPainter : ICodeVisionEntryBasePainter<String> {
point: Point,
state: RangeCodeVisionModel.InlayState,
hovered: Boolean,
// hoveredEntry: CodeVisionEntry?
hoveredEntry: CodeVisionEntry?
) {
renderCodeBlock(
editor,
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/messages/AutoDevBundle.properties
Expand Up @@ -144,3 +144,7 @@ autoarkui.name=AutoArkUi
autoarkui.generate=Auto Generate ArkUI
autoarkui.generate.clarify=Clarify Requirements
autoarkui.generate.design=Design Page

# Inlay
intentions.chat.inlay.complete.name = Inlay Complete Code
intentions.chat.inlay.complete.family.name = Inlay Complete code

0 comments on commit 581e56d

Please sign in to comment.