feat: add MentionFileInChatAction

This commit is contained in:
vldf 2025-08-19 17:33:45 +03:00
parent d135140fb9
commit 7fb5935e37
4 changed files with 71 additions and 0 deletions

View file

@ -78,4 +78,5 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
exitEditMode: [undefined, void];
focusEdit: [undefined, void];
generateRule: [undefined, void];
mentionFile: [{ fullFilePath: string; shortFilePath: string }, void];
};

View file

@ -0,0 +1,41 @@
package com.github.continuedev.continueintellijextension.actions.menu.file
import com.github.continuedev.continueintellijextension.actions.getContinuePluginService
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.vfs.VirtualFile
class MentionFileInChatAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val continuePluginService = getContinuePluginService(e.project) ?: return
val virtualFile = e.getFile() ?: return
val params = mapOf(
"fullFilePath" to virtualFile.url,
"shortFilePath" to virtualFile.name,
)
continuePluginService.sendToWebview("mentionFile", params)
}
override fun update(e: AnActionEvent) {
val file = e.getFile()
val files = e.getFiles()
val isAvailable = file != null && !file.isDirectory && files.size == 1
e.presentation.isVisible = isAvailable
}
private fun AnActionEvent.getFile(): VirtualFile? {
return this.getData(CommonDataKeys.VIRTUAL_FILE)
}
private fun AnActionEvent.getFiles(): Array<out VirtualFile> {
return this.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY).orEmpty()
}
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
}

View file

@ -181,5 +181,13 @@
<add-to-group group-id="EditorPopupMenu"/>
<override-text place="GoToAction" text="Continue: Add Highlighted Code to Context and Clear Chat"/>
</action>
<group id="ContinueProjectViewPopUpMenuGroup" popup="true" text="Continue">
<action id="com.github.continuedev.continueintellijextension.actions.menu.file.MentionFileInChatAction"
class="com.github.continuedev.continueintellijextension.actions.menu.file.MentionFileInChatAction"
text="Mention File in the Chat">
</action>
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
</group>
</actions>
</idea-plugin>

View file

@ -198,4 +198,25 @@ export function useMainEditorWebviewListeners({
},
[editor, activeContextProviders, isInEdit, useCurrentFileAsContext],
);
useWebviewListener(
"mentionFile",
async (data) => {
if (!editor) return;
editor
.chain()
.insertContent({
type: "mention",
attrs: {
id: data.fullFilePath,
query: data.fullFilePath,
itemType: "file",
label: data.shortFilePath,
},
})
.insertContent(" ")
.run();
},
[editor],
);
}