Skip to content

Commit 7fb5935

Browse files
committed
feat: add MentionFileInChatAction
1 parent d135140 commit 7fb5935

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

core/protocol/ideWebview.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,5 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
7878
exitEditMode: [undefined, void];
7979
focusEdit: [undefined, void];
8080
generateRule: [undefined, void];
81+
mentionFile: [{ fullFilePath: string; shortFilePath: string }, void];
8182
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.github.continuedev.continueintellijextension.actions.menu.file
2+
3+
import com.github.continuedev.continueintellijextension.actions.getContinuePluginService
4+
import com.intellij.openapi.actionSystem.ActionUpdateThread
5+
import com.intellij.openapi.actionSystem.AnAction
6+
import com.intellij.openapi.actionSystem.AnActionEvent
7+
import com.intellij.openapi.actionSystem.CommonDataKeys
8+
import com.intellij.openapi.vfs.VirtualFile
9+
10+
class MentionFileInChatAction : AnAction() {
11+
override fun actionPerformed(e: AnActionEvent) {
12+
val continuePluginService = getContinuePluginService(e.project) ?: return
13+
val virtualFile = e.getFile() ?: return
14+
15+
val params = mapOf(
16+
"fullFilePath" to virtualFile.url,
17+
"shortFilePath" to virtualFile.name,
18+
)
19+
20+
continuePluginService.sendToWebview("mentionFile", params)
21+
}
22+
23+
override fun update(e: AnActionEvent) {
24+
val file = e.getFile()
25+
val files = e.getFiles()
26+
27+
val isAvailable = file != null && !file.isDirectory && files.size == 1
28+
29+
e.presentation.isVisible = isAvailable
30+
}
31+
32+
private fun AnActionEvent.getFile(): VirtualFile? {
33+
return this.getData(CommonDataKeys.VIRTUAL_FILE)
34+
}
35+
36+
private fun AnActionEvent.getFiles(): Array<out VirtualFile> {
37+
return this.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY).orEmpty()
38+
}
39+
40+
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
41+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,13 @@
181181
<add-to-group group-id="EditorPopupMenu"/>
182182
<override-text place="GoToAction" text="Continue: Add Highlighted Code to Context and Clear Chat"/>
183183
</action>
184+
<group id="ContinueProjectViewPopUpMenuGroup" popup="true" text="Continue">
185+
<action id="com.github.continuedev.continueintellijextension.actions.menu.file.MentionFileInChatAction"
186+
class="com.github.continuedev.continueintellijextension.actions.menu.file.MentionFileInChatAction"
187+
text="Mention File in the Chat">
188+
</action>
189+
190+
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
191+
</group>
184192
</actions>
185193
</idea-plugin>

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,25 @@ export function useMainEditorWebviewListeners({
198198
},
199199
[editor, activeContextProviders, isInEdit, useCurrentFileAsContext],
200200
);
201+
202+
useWebviewListener(
203+
"mentionFile",
204+
async (data) => {
205+
if (!editor) return;
206+
editor
207+
.chain()
208+
.insertContent({
209+
type: "mention",
210+
attrs: {
211+
id: data.fullFilePath,
212+
query: data.fullFilePath,
213+
itemType: "file",
214+
label: data.shortFilePath,
215+
},
216+
})
217+
.insertContent(" ")
218+
.run();
219+
},
220+
[editor],
221+
);
201222
}

0 commit comments

Comments
 (0)