Skip to content

Commit

Permalink
chore: optimize code generation
Browse files Browse the repository at this point in the history
use key event to trigger request and reduce delay time

Log:
Change-Id: I1a4133cb6fb2d205e51c6aa42f45cff0e7065644
  • Loading branch information
deepin-mozart committed Nov 16, 2023
1 parent a1ed3bb commit 25756e3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 0 additions & 4 deletions src/plugins/codeeditor/textedittabwidget/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ TextEdit::TextEdit(QWidget *parent)
Q_UNUSED(text)
Q_UNUSED(line)
emit this->fileChanged(this->file());
auto service = dpfGetService(EditorService);
if (service) {
emit service->fileChanged();
}
}, Qt::UniqueConnection);

QObject::connect(this, &ScintillaEditExtern::textDeleted, this,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/codeeditor/transceiver/codeeditorreceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CodeEditorReceiver::CodeEditorReceiver(QObject *parent)

dpf::EventHandler::Type CodeEditorReceiver::type()
{
return dpf::EventHandler::Type::Sync;
return dpf::EventHandler::Type::Async;
}

QStringList CodeEditorReceiver::topics()
Expand Down
14 changes: 10 additions & 4 deletions src/plugins/codegeex/copilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ Copilot::Copilot(QObject *parent)
}
break;
case CopilotApi::multilingual_code_generate:
mutexResponse.lock();
generateResponse = response;
if (editorService->showTips && !response.isEmpty()) {
editorService->showTips(response);
editorService->showTips(generateResponse);
}
mutexResponse.unlock();
break;
case CopilotApi::multilingual_code_translate:
emit translatedResult(response);
Expand All @@ -47,9 +49,6 @@ Copilot::Copilot(QObject *parent)
});

timer.setSingleShot(true);
connect(editorService, &EditorService::fileChanged, [this](){
timer.start(500);
});

connect(&timer, &QTimer::timeout, [this](){
generateCode();
Expand Down Expand Up @@ -116,10 +115,17 @@ void Copilot::insterText(const QString &text)

void Copilot::processKeyPressEvent(Qt::Key key)
{
mutexResponse.lock();
if (key == Qt::Key_Tab && !generateResponse.isEmpty()) {
insterText(generateResponse);
generateResponse = "";
}
mutexResponse.unlock();

// start generate code.
QMetaObject::invokeMethod(this, [this](){
timer.start(200);
});
}

void Copilot::addComment()
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/codegeex/copilot.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <QObject>
#include <QTimer>
#include <QMutex>

class QMenu;
namespace dpfservice {
Expand Down Expand Up @@ -47,6 +48,7 @@ public slots:
dpfservice::EditorService *editorService = nullptr;
QString generateResponse;
QTimer timer;
QMutex mutexResponse;
};

#endif // COPILOT_H
2 changes: 1 addition & 1 deletion src/plugins/codegeex/widgets/askpagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ AskPageWidget::AskPageWidget(QWidget *parent)
initConnection();

processTimer->setInterval(200);
placeHolderText = tr("Ask question here, press Enter to send...");
}

void AskPageWidget::setIntroPage()
Expand Down Expand Up @@ -111,6 +110,7 @@ void AskPageWidget::initInputWidget()

inputEdit = new DLineEdit(inputWidget);
inputEdit->setFixedHeight(50);
placeHolderText = tr("Ask question here, press Enter to send...");
inputEdit->setPlaceholderText(placeHolderText);
editLayout->addWidget(inputEdit);
}
Expand Down
4 changes: 0 additions & 4 deletions src/services/editor/editorservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class EditorService final : public dpf::PluginService,
DPF_INTERFACE(void, insertText, const QString &);
DPF_INTERFACE(void, showTips, const QString &tips);
DPF_INTERFACE(void, undo);


signals:
void fileChanged();
};

} // namespace dpfservice
Expand Down

0 comments on commit 25756e3

Please sign in to comment.