mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-13 07:02:34 +00:00
feat: add apply and diff actions for toolwindow code editor
This commit is contained in:
parent
10e48cdb43
commit
4898c8580c
15 changed files with 303 additions and 59 deletions
|
|
@ -118,6 +118,13 @@ public class ChatToolWindowTabPanel implements Disposable {
|
|||
}
|
||||
|
||||
public void sendMessage(Message message, ConversationType conversationType) {
|
||||
sendMessage(message, conversationType, null);
|
||||
}
|
||||
|
||||
public void sendMessage(
|
||||
Message message,
|
||||
ConversationType conversationType,
|
||||
@Nullable String highlightedText) {
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
var referencedFiles = project.getUserData(CodeGPTKeys.SELECTED_FILES);
|
||||
var chatToolWindowPanel = project.getService(ChatToolWindowContentManager.class)
|
||||
|
|
@ -138,7 +145,8 @@ public class ChatToolWindowTabPanel implements Disposable {
|
|||
|
||||
var userMessagePanel = new UserMessagePanel(project, message, this);
|
||||
var attachedFilePath = CodeGPTKeys.IMAGE_ATTACHMENT_FILE_PATH.get(project);
|
||||
var callParameters = getCallParameters(conversationType, message, attachedFilePath);
|
||||
var callParameters =
|
||||
getCallParameters(conversationType, message, highlightedText, attachedFilePath);
|
||||
if (callParameters.getImageData() != null) {
|
||||
message.setImageFilePath(attachedFilePath);
|
||||
chatToolWindowPanel.ifPresent(panel -> panel.clearNotifications(project));
|
||||
|
|
@ -148,7 +156,7 @@ public class ChatToolWindowTabPanel implements Disposable {
|
|||
var messagePanel = toolWindowScrollablePanel.addMessage(message.getId());
|
||||
messagePanel.add(userMessagePanel);
|
||||
|
||||
var responsePanel = createResponsePanel(message, conversationType);
|
||||
var responsePanel = createResponsePanel(callParameters, conversationType);
|
||||
messagePanel.add(responsePanel);
|
||||
call(callParameters, responsePanel);
|
||||
});
|
||||
|
|
@ -157,8 +165,10 @@ public class ChatToolWindowTabPanel implements Disposable {
|
|||
private CallParameters getCallParameters(
|
||||
ConversationType conversationType,
|
||||
Message message,
|
||||
@Nullable String highlightedText,
|
||||
@Nullable String attachedFilePath) {
|
||||
var callParameters = new CallParameters(conversation, conversationType, message, false);
|
||||
var callParameters = new CallParameters(conversation, conversationType, message,
|
||||
highlightedText, false);
|
||||
if (attachedFilePath != null && !attachedFilePath.isEmpty()) {
|
||||
try {
|
||||
callParameters.setImageData(Files.readAllBytes(Path.of(attachedFilePath)));
|
||||
|
|
@ -170,12 +180,20 @@ public class ChatToolWindowTabPanel implements Disposable {
|
|||
return callParameters;
|
||||
}
|
||||
|
||||
private ResponsePanel createResponsePanel(Message message, ConversationType conversationType) {
|
||||
private ResponsePanel createResponsePanel(
|
||||
CallParameters callParameters,
|
||||
ConversationType conversationType) {
|
||||
var message = callParameters.getMessage();
|
||||
return new ResponsePanel()
|
||||
.withReloadAction(() -> reloadMessage(message, conversation, conversationType))
|
||||
.withDeleteAction(() -> removeMessage(message.getId(), conversation))
|
||||
.addContent(
|
||||
new ChatMessageResponseBody(project, true, false, message.isWebSearchIncluded(),
|
||||
new ChatMessageResponseBody(
|
||||
project,
|
||||
callParameters.getHighlightedText(),
|
||||
true,
|
||||
false,
|
||||
message.isWebSearchIncluded(),
|
||||
message.getDocumentationDetails() != null, this));
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +214,8 @@ public class ChatToolWindowTabPanel implements Disposable {
|
|||
if (responsePanel != null) {
|
||||
message.setResponse("");
|
||||
conversationService.saveMessage(conversation, message);
|
||||
call(new CallParameters(conversation, conversationType, message, true), responsePanel);
|
||||
call(new CallParameters(conversation, conversationType, message, null, true),
|
||||
responsePanel);
|
||||
}
|
||||
|
||||
totalTokensPanel.updateConversationTokens(conversation);
|
||||
|
|
@ -250,12 +269,14 @@ public class ChatToolWindowTabPanel implements Disposable {
|
|||
private Unit handleSubmit(String text, List<AppliedActionInlay> appliedInlayActions) {
|
||||
var message = new Message(text);
|
||||
var editor = EditorUtil.getSelectedEditor(project);
|
||||
String highlightedText = null;
|
||||
if (editor != null) {
|
||||
var selectionModel = editor.getSelectionModel();
|
||||
var selectedText = selectionModel.getSelectedText();
|
||||
if (selectedText != null && !selectedText.isEmpty()) {
|
||||
var fileExtension = FileUtil.getFileExtension(editor.getVirtualFile().getName());
|
||||
message = new Message(text + format("%n```%s%n%s%n```", fileExtension, selectedText));
|
||||
highlightedText = selectedText;
|
||||
selectionModel.removeSelection();
|
||||
}
|
||||
}
|
||||
|
|
@ -280,7 +301,7 @@ public class ChatToolWindowTabPanel implements Disposable {
|
|||
CodeGPTKeys.ADDED_PERSONA.set(project, null);
|
||||
}
|
||||
|
||||
sendMessage(message, ConversationType.DEFAULT);
|
||||
sendMessage(message, ConversationType.DEFAULT, highlightedText);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue