Skip to content

Commit

Permalink
feat: [inline chat] Adapt the inline chat interface
Browse files Browse the repository at this point in the history
as title

Log: Interface adaptation
  • Loading branch information
Kakueeen authored and deepin-mozart committed Oct 28, 2024
1 parent 3b6f1ff commit 28707cd
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 63 deletions.
8 changes: 5 additions & 3 deletions src/plugins/codeeditor/gui/private/texteditor_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,11 @@ void TextEditorPrivate::updateCacheInfo(int pos, int added)
q->lineIndexFromPosition(pos, &line, &index);
editor.lineChanged(fileName, line, added);
if (lineWidgetContainer->isVisible()) {
if (showAtLine > line) {
showAtLine += added;
showAtLine = qMax(showAtLine, 1);
if (showAtLine > line && q->lines() != 1) {
if (added != q->lines() - 1) {
showAtLine += added;
showAtLine = qMax(showAtLine, 1);
}
updateLineWidgetPosition();
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/codeeditor/gui/tabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ QString TabWidget::rangeText(const QString &fileName, const dpfservice::Edit::Ra
int endPos = range.end.column == -1
? editor->SendScintilla(TextEditor::SCI_GETLINEENDPOSITION, range.end.line)
: editor->positionFromLineIndex(range.end.line, range.end.column);
if (startPos == -1 || endPos == -1)
return {};

return editor->text(startPos, endPos);
}

Expand Down Expand Up @@ -615,6 +618,7 @@ bool TabWidget::replaceRange(const QString &fileName, const dpfservice::Edit::Ra
auto lineText = editor->text(range.end.line);
indexTo = lineText.length();
}

editor->replaceRange(range.start.line, range.start.column == -1 ? 0 : range.start.column,
range.end.line, indexTo, newText);
return true;
Expand Down
18 changes: 13 additions & 5 deletions src/plugins/codegeex/codegeex/copilotapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void CopilotApi::postGenerate(const QString &url, const QString &prefix, const Q
{
if (completionReply)
completionReply->close();
QtConcurrent::run([prefix, suffix, type, url, this](){
QtConcurrent::run([prefix, suffix, type, url, this]() {
QByteArray body = assembleGenerateBody(prefix, suffix, type);
emit asyncGenerateMessages(url, body);
});
Expand Down Expand Up @@ -74,7 +74,7 @@ void CopilotApi::postInlineChat(const QString &url,
{
QByteArray body = assembleInlineChatBody(prompt, info, locale);
QNetworkReply *reply = postMessage(url, CodeGeeXManager::instance()->getSessionId(), body);
reply->setProperty("responseType", CopilotApi::receiving_by_stream);
reply->setProperty("responseType", CopilotApi::inline_chat);

processResponse(reply);
}
Expand Down Expand Up @@ -260,10 +260,8 @@ QByteArray CopilotApi::assembleCommandBody(const QString &code, const QString &l

void CopilotApi::processResponse(QNetworkReply *reply)
{
connect(this, &CopilotApi::requestStop, this, [=]() { reply->close(); });
if (reply->property("responseType") == CopilotApi::receiving_by_stream) {
connect(this, &CopilotApi::requestStop, this, [=]() {
reply->close();
});
connect(reply, &QNetworkReply::readyRead, this, [=]() {
slotReadReplyStream(reply);
});
Expand Down Expand Up @@ -326,6 +324,9 @@ void CopilotApi::slotReadReply(QNetworkReply *reply)
} else if (type == CopilotApi::multilingual_code_comment) {
code = jsonObject.value("text").toString();
emit response(CopilotApi::multilingual_code_comment, code, "");
} else if (type == CopilotApi::inline_chat) {
code = jsonObject.value("text").toString();
emit response(CopilotApi::inline_chat, code, "");
}
}
}
Expand Down Expand Up @@ -380,6 +381,13 @@ void CopilotApi::setModel(languageModel model)
}
}

languageModel CopilotApi::model() const
{
if (chatModel == chatModelLite)
return Lite;
return Pro;
}

QPair<QString, QString> CopilotApi::getCurrentFileInfo()
{
auto &ctx = dpfInstance.serviceContext();
Expand Down
1 change: 1 addition & 0 deletions src/plugins/codegeex/codegeex/copilotapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class CopilotApi : public QObject

CopilotApi(QObject *parent = nullptr);
void setModel(languageModel model);
languageModel model() const;

void postGenerate(const QString &url, const QString &prefix, const QString &suffix, GenerateType type);

Expand Down
10 changes: 10 additions & 0 deletions src/plugins/codegeex/copilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ void Copilot::setLocale(const QString &locale)
this->locale = locale;
}

QString Copilot::getLocale() const
{
return locale;
}

void Copilot::setCommitsLocale(const QString &locale)
{
this->commitsLocale = locale;
Expand All @@ -182,6 +187,11 @@ void Copilot::setCurrentModel(CodeGeeX::languageModel model)
copilotApi.setModel(model);
}

languageModel Copilot::getCurrentModel() const
{
return copilotApi.model();
}

void Copilot::handleSelectionChanged(const QString &fileName, int lineFrom, int indexFrom, int lineTo, int indexTo)
{
QMetaObject::invokeMethod(this, [=] {
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 @@ -33,8 +33,10 @@ class Copilot : public QObject
void setGenerateCodeEnabled(bool enabled);
bool getGenerateCodeEnabled() const;
void setLocale(const QString &locale);
QString getLocale() const;
void setCommitsLocale(const QString &locale);
void setCurrentModel(CodeGeeX::languageModel model);
CodeGeeX::languageModel getCurrentModel() const;
void handleSelectionChanged(const QString &fileName, int lineFrom, int indexFrom,
int lineTo, int indexTo);

Expand Down
Loading

0 comments on commit 28707cd

Please sign in to comment.