feat: add MentionRepoMapInChatAction.kt
This commit is contained in:
parent
b40cf38e34
commit
cbc7ada3a1
6 changed files with 51 additions and 19 deletions
8
core/index.d.ts
vendored
8
core/index.d.ts
vendored
|
|
@ -1865,12 +1865,12 @@ export interface CompiledMessagesResult {
|
|||
contextPercentage: number;
|
||||
}
|
||||
|
||||
export interface MentionFilesOrDirectoriesPayload {
|
||||
data: MentionFileOrDirectoryPayload[];
|
||||
export interface AddChatMentionsPayload {
|
||||
data: AddChatMentionPayload[];
|
||||
}
|
||||
|
||||
interface MentionFileOrDirectoryPayload {
|
||||
type: "file" | "folder";
|
||||
interface AddChatMentionPayload {
|
||||
type: "file" | "folder" | "repo-map";
|
||||
fullPath: string;
|
||||
name: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ import { ToWebviewFromIdeOrCoreProtocol } from "./webview";
|
|||
|
||||
import {
|
||||
AcceptOrRejectDiffPayload,
|
||||
AddChatMentionsPayload,
|
||||
ApplyState,
|
||||
ApplyToFilePayload,
|
||||
HighlightedCodePayload,
|
||||
MentionFilesOrDirectoriesPayload,
|
||||
MessageContent,
|
||||
RangeInFileWithContents,
|
||||
SetCodeToEditPayload,
|
||||
|
|
@ -79,5 +79,5 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
|||
exitEditMode: [undefined, void];
|
||||
focusEdit: [undefined, void];
|
||||
generateRule: [undefined, void];
|
||||
mentionFilesOrDirectories: [MentionFilesOrDirectoriesPayload, void];
|
||||
addChatMention: [AddChatMentionsPayload, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package com.github.continuedev.continueintellijextension.actions.menu.file
|
||||
|
||||
import com.github.continuedev.continueintellijextension.actions.getContinuePluginService
|
||||
import com.github.continuedev.continueintellijextension.actions.getFiles
|
||||
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 MentionFilesOrFoldersInChatAction : AnAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
|
|
@ -25,7 +24,7 @@ class MentionFilesOrFoldersInChatAction : AnAction() {
|
|||
"data" to requestData
|
||||
)
|
||||
|
||||
continuePluginService.sendToWebview("mentionFilesOrDirectories", requestParams)
|
||||
continuePluginService.sendToWebview("addChatMention", requestParams)
|
||||
}
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
|
|
@ -36,14 +35,5 @@ class MentionFilesOrFoldersInChatAction : AnAction() {
|
|||
e.presentation.isVisible = isAvailable
|
||||
}
|
||||
|
||||
private fun AnActionEvent.getFiles(): Array<out VirtualFile> {
|
||||
val multipleFiles = this.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)
|
||||
if (multipleFiles != null) {
|
||||
return multipleFiles
|
||||
}
|
||||
|
||||
return this.getData(CommonDataKeys.VIRTUAL_FILE)?.let { arrayOf(it) } ?: emptyArray()
|
||||
}
|
||||
|
||||
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package com.github.continuedev.continueintellijextension.actions.menu.file
|
||||
|
||||
import com.github.continuedev.continueintellijextension.actions.getContinuePluginService
|
||||
import com.github.continuedev.continueintellijextension.actions.getFiles
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
|
||||
class MentionRepoMapInChatAction : AnAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val continuePluginService = getContinuePluginService(e.project) ?: return
|
||||
val selectedFiles = e.getFiles()
|
||||
|
||||
val requestData = selectedFiles.map { vFile ->
|
||||
mapOf(
|
||||
"type" to "repo-map",
|
||||
"fullPath" to vFile.url,
|
||||
"name" to vFile.name,
|
||||
)
|
||||
}
|
||||
val requestParams = mapOf(
|
||||
"data" to requestData
|
||||
)
|
||||
|
||||
continuePluginService.sendToWebview("addChatMention", requestParams)
|
||||
}
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
val files = e.getFiles()
|
||||
|
||||
// only directories can be used
|
||||
val isAvailable = files.isNotEmpty() && files.all { file -> file.isDirectory }
|
||||
|
||||
e.presentation.isVisible = isAvailable
|
||||
}
|
||||
|
||||
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
|
||||
}
|
||||
|
|
@ -186,6 +186,10 @@
|
|||
class="com.github.continuedev.continueintellijextension.actions.menu.file.MentionFilesOrFoldersInChatAction"
|
||||
text="Mention in the Chat">
|
||||
</action>
|
||||
<action id="com.github.continuedev.continueintellijextension.actions.menu.file.MentionRepoMapInChatAction"
|
||||
class="com.github.continuedev.continueintellijextension.actions.menu.file.MentionRepoMapInChatAction"
|
||||
text="Mention in the Chat as a Repo Map">
|
||||
</action>
|
||||
|
||||
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
|
||||
</group>
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ export function useMainEditorWebviewListeners({
|
|||
);
|
||||
|
||||
useWebviewListener(
|
||||
"mentionFilesOrDirectories",
|
||||
"addChatMention",
|
||||
async (data) => {
|
||||
if (!editor) return;
|
||||
let chain = editor.chain();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue