feat: allow to reference both directories and files at the same time
This commit is contained in:
parent
6e77df2ea7
commit
b40cf38e34
5 changed files with 53 additions and 35 deletions
10
core/index.d.ts
vendored
10
core/index.d.ts
vendored
|
|
@ -1865,6 +1865,16 @@ export interface CompiledMessagesResult {
|
|||
contextPercentage: number;
|
||||
}
|
||||
|
||||
export interface MentionFilesOrDirectoriesPayload {
|
||||
data: MentionFileOrDirectoryPayload[];
|
||||
}
|
||||
|
||||
interface MentionFileOrDirectoryPayload {
|
||||
type: "file" | "folder";
|
||||
fullPath: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface MessageOption {
|
||||
precompiled: boolean;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
ApplyState,
|
||||
ApplyToFilePayload,
|
||||
HighlightedCodePayload,
|
||||
MentionFilesOrDirectoriesPayload,
|
||||
MessageContent,
|
||||
RangeInFileWithContents,
|
||||
SetCodeToEditPayload,
|
||||
|
|
@ -78,8 +79,5 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
|||
exitEditMode: [undefined, void];
|
||||
focusEdit: [undefined, void];
|
||||
generateRule: [undefined, void];
|
||||
mentionFileOrDirectory: [
|
||||
{ type: "file" | "folder"; fullPath: string; name: string },
|
||||
void,
|
||||
];
|
||||
mentionFilesOrDirectories: [MentionFilesOrDirectoriesPayload, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,36 +7,42 @@ import com.intellij.openapi.actionSystem.AnActionEvent
|
|||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
|
||||
class MentionFileOrFolderInChatAction : AnAction() {
|
||||
class MentionFilesOrFoldersInChatAction : AnAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val continuePluginService = getContinuePluginService(e.project) ?: return
|
||||
val virtualFile = e.getFile() ?: return
|
||||
val selectedFiles = e.getFiles()
|
||||
|
||||
val type = if (virtualFile.isDirectory) "folder" else "file"
|
||||
val params = mapOf(
|
||||
"type" to type,
|
||||
"fullPath" to virtualFile.url,
|
||||
"name" to virtualFile.name,
|
||||
val requestData = selectedFiles.map { vFile ->
|
||||
val type = if (vFile.isDirectory) "folder" else "file"
|
||||
|
||||
mapOf(
|
||||
"type" to type,
|
||||
"fullPath" to vFile.url,
|
||||
"name" to vFile.name,
|
||||
)
|
||||
}
|
||||
val requestParams = mapOf(
|
||||
"data" to requestData
|
||||
)
|
||||
|
||||
continuePluginService.sendToWebview("mentionFileOrDirectory", params)
|
||||
continuePluginService.sendToWebview("mentionFilesOrDirectories", requestParams)
|
||||
}
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
val file = e.getFile()
|
||||
val files = e.getFiles()
|
||||
|
||||
val isAvailable = file != null && files.size == 1
|
||||
val isAvailable = files.isNotEmpty()
|
||||
|
||||
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()
|
||||
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
|
||||
|
|
@ -182,8 +182,8 @@
|
|||
<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.MentionFileOrFolderInChatAction"
|
||||
class="com.github.continuedev.continueintellijextension.actions.menu.file.MentionFileOrFolderInChatAction"
|
||||
<action id="com.github.continuedev.continueintellijextension.actions.menu.file.MentionFilesOrFoldersInChatAction"
|
||||
class="com.github.continuedev.continueintellijextension.actions.menu.file.MentionFilesOrFoldersInChatAction"
|
||||
text="Mention in the Chat">
|
||||
</action>
|
||||
|
||||
|
|
|
|||
|
|
@ -200,22 +200,26 @@ export function useMainEditorWebviewListeners({
|
|||
);
|
||||
|
||||
useWebviewListener(
|
||||
"mentionFileOrDirectory",
|
||||
"mentionFilesOrDirectories",
|
||||
async (data) => {
|
||||
if (!editor) return;
|
||||
editor
|
||||
.chain()
|
||||
.insertContent({
|
||||
type: "mention",
|
||||
attrs: {
|
||||
id: data.fullPath,
|
||||
query: data.fullPath,
|
||||
itemType: data.type,
|
||||
label: data.name,
|
||||
},
|
||||
})
|
||||
.insertContent(" ")
|
||||
.run();
|
||||
let chain = editor.chain();
|
||||
|
||||
for (let mention of data.data) {
|
||||
chain
|
||||
.insertContent({
|
||||
type: "mention",
|
||||
attrs: {
|
||||
id: mention.fullPath,
|
||||
query: mention.fullPath,
|
||||
itemType: mention.type,
|
||||
label: mention.name,
|
||||
},
|
||||
})
|
||||
.insertContent(" ");
|
||||
}
|
||||
|
||||
chain.run();
|
||||
},
|
||||
[editor],
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue