Skip to content

Commit

Permalink
fix: [Ai] add comment function will delete selecetd code
Browse files Browse the repository at this point in the history
  • Loading branch information
LiHua000 authored and deepin-mozart committed Jan 7, 2025
1 parent 99d5914 commit 55fabff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/plugins/codegeex/codegeex/copilotapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "src/common/supportfile/language.h"
#include "src/services/editor/editorservice.h"
#include "src/services/project/projectservice.h"
#include "services/window/windowservice.h"

#include <QNetworkAccessManager>
#include <QNetworkRequest>
Expand All @@ -20,6 +21,12 @@

using namespace dpfservice;

void sendNotify(uint type, const QString &name, const QString &msg)
{
auto windowSrv = dpfGetService(WindowService);
windowSrv->notify(type, name, msg, {});
}

namespace CodeGeeX {
CopilotApi::CopilotApi(QObject *parent)
: QObject(parent), manager(new QNetworkAccessManager(this))
Expand Down Expand Up @@ -252,6 +259,7 @@ void CopilotApi::slotReadReply(QNetworkReply *reply)
qCritical() << "Error:" << reply->errorString() << reply->error();
if (reply->error() != QNetworkReply::OperationCanceledError) {
auto type = reply->property("responseType").value<CopilotApi::ResponseType>();
sendNotify(2, "AI" ,reply->errorString());
emit response(type, "", "");
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/codegeex/copilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Copilot::Copilot(QObject *parent)
connect(&copilotApi, &CopilotApi::response, [this](CopilotApi::ResponseType responseType, const QString &response, const QString &dstLang) {
switch (responseType) {
case CopilotApi::multilingual_code_comment:
replaceSelectedText(response);
if (!response.isEmpty())
replaceSelectedText(response);
break;
case CopilotApi::inline_completions:
if (!responseValid(response))
Expand Down

0 comments on commit 55fabff

Please sign in to comment.