Skip to content

Commit cbc7ada

Browse files
committed
feat: add MentionRepoMapInChatAction.kt
1 parent b40cf38 commit cbc7ada

File tree

6 files changed

+51
-19
lines changed

6 files changed

+51
-19
lines changed

core/index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,12 +1865,12 @@ export interface CompiledMessagesResult {
18651865
contextPercentage: number;
18661866
}
18671867

1868-
export interface MentionFilesOrDirectoriesPayload {
1869-
data: MentionFileOrDirectoryPayload[];
1868+
export interface AddChatMentionsPayload {
1869+
data: AddChatMentionPayload[];
18701870
}
18711871

1872-
interface MentionFileOrDirectoryPayload {
1873-
type: "file" | "folder";
1872+
interface AddChatMentionPayload {
1873+
type: "file" | "folder" | "repo-map";
18741874
fullPath: string;
18751875
name: string;
18761876
}

core/protocol/ideWebview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { ToWebviewFromIdeOrCoreProtocol } from "./webview";
33

44
import {
55
AcceptOrRejectDiffPayload,
6+
AddChatMentionsPayload,
67
ApplyState,
78
ApplyToFilePayload,
89
HighlightedCodePayload,
9-
MentionFilesOrDirectoriesPayload,
1010
MessageContent,
1111
RangeInFileWithContents,
1212
SetCodeToEditPayload,
@@ -79,5 +79,5 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
7979
exitEditMode: [undefined, void];
8080
focusEdit: [undefined, void];
8181
generateRule: [undefined, void];
82-
mentionFilesOrDirectories: [MentionFilesOrDirectoriesPayload, void];
82+
addChatMention: [AddChatMentionsPayload, void];
8383
};

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/menu/file/MentionFilesOrFoldersInChatAction.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.github.continuedev.continueintellijextension.actions.menu.file
22

33
import com.github.continuedev.continueintellijextension.actions.getContinuePluginService
4+
import com.github.continuedev.continueintellijextension.actions.getFiles
45
import com.intellij.openapi.actionSystem.ActionUpdateThread
56
import com.intellij.openapi.actionSystem.AnAction
67
import com.intellij.openapi.actionSystem.AnActionEvent
7-
import com.intellij.openapi.actionSystem.CommonDataKeys
8-
import com.intellij.openapi.vfs.VirtualFile
98

109
class MentionFilesOrFoldersInChatAction : AnAction() {
1110
override fun actionPerformed(e: AnActionEvent) {
@@ -25,7 +24,7 @@ class MentionFilesOrFoldersInChatAction : AnAction() {
2524
"data" to requestData
2625
)
2726

28-
continuePluginService.sendToWebview("mentionFilesOrDirectories", requestParams)
27+
continuePluginService.sendToWebview("addChatMention", requestParams)
2928
}
3029

3130
override fun update(e: AnActionEvent) {
@@ -36,14 +35,5 @@ class MentionFilesOrFoldersInChatAction : AnAction() {
3635
e.presentation.isVisible = isAvailable
3736
}
3837

39-
private fun AnActionEvent.getFiles(): Array<out VirtualFile> {
40-
val multipleFiles = this.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)
41-
if (multipleFiles != null) {
42-
return multipleFiles
43-
}
44-
45-
return this.getData(CommonDataKeys.VIRTUAL_FILE)?.let { arrayOf(it) } ?: emptyArray()
46-
}
47-
4838
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
4939
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.github.continuedev.continueintellijextension.actions.menu.file
2+
3+
import com.github.continuedev.continueintellijextension.actions.getContinuePluginService
4+
import com.github.continuedev.continueintellijextension.actions.getFiles
5+
import com.intellij.openapi.actionSystem.ActionUpdateThread
6+
import com.intellij.openapi.actionSystem.AnAction
7+
import com.intellij.openapi.actionSystem.AnActionEvent
8+
9+
class MentionRepoMapInChatAction : AnAction() {
10+
override fun actionPerformed(e: AnActionEvent) {
11+
val continuePluginService = getContinuePluginService(e.project) ?: return
12+
val selectedFiles = e.getFiles()
13+
14+
val requestData = selectedFiles.map { vFile ->
15+
mapOf(
16+
"type" to "repo-map",
17+
"fullPath" to vFile.url,
18+
"name" to vFile.name,
19+
)
20+
}
21+
val requestParams = mapOf(
22+
"data" to requestData
23+
)
24+
25+
continuePluginService.sendToWebview("addChatMention", requestParams)
26+
}
27+
28+
override fun update(e: AnActionEvent) {
29+
val files = e.getFiles()
30+
31+
// only directories can be used
32+
val isAvailable = files.isNotEmpty() && files.all { file -> file.isDirectory }
33+
34+
e.presentation.isVisible = isAvailable
35+
}
36+
37+
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
38+
}

extensions/intellij/src/main/resources/META-INF/plugin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@
186186
class="com.github.continuedev.continueintellijextension.actions.menu.file.MentionFilesOrFoldersInChatAction"
187187
text="Mention in the Chat">
188188
</action>
189+
<action id="com.github.continuedev.continueintellijextension.actions.menu.file.MentionRepoMapInChatAction"
190+
class="com.github.continuedev.continueintellijextension.actions.menu.file.MentionRepoMapInChatAction"
191+
text="Mention in the Chat as a Repo Map">
192+
</action>
189193

190194
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
191195
</group>

gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export function useMainEditorWebviewListeners({
200200
);
201201

202202
useWebviewListener(
203-
"mentionFilesOrDirectories",
203+
"addChatMention",
204204
async (data) => {
205205
if (!editor) return;
206206
let chain = editor.chain();

0 commit comments

Comments
 (0)