Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [Ai] add comment function will delete selecetd code #1044

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/plugins/codegeex/codegeex/copilotapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "copilotapi.h"
#include "src/common/supportfile/language.h"

Check warning on line 5 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "src/common/supportfile/language.h" not found.

Check warning on line 5 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "src/common/supportfile/language.h" not found.
#include "src/services/editor/editorservice.h"

Check warning on line 6 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "src/services/editor/editorservice.h" not found.

Check warning on line 6 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "src/services/editor/editorservice.h" not found.
#include "src/services/project/projectservice.h"

Check warning on line 7 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "src/services/project/projectservice.h" not found.

Check warning on line 7 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "src/services/project/projectservice.h" not found.
#include "services/window/windowservice.h"

Check warning on line 8 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "services/window/windowservice.h" not found.

Check warning on line 8 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "services/window/windowservice.h" not found.

#include <QNetworkAccessManager>

Check warning on line 10 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QNetworkAccessManager> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 10 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QNetworkAccessManager> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QNetworkRequest>

Check warning on line 11 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QNetworkRequest> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 11 in src/plugins/codegeex/codegeex/copilotapi.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QNetworkRequest> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QNetworkReply>

#include <QJsonObject>
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 @@
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
Loading