From 587c01abf099b4af0ac13d07188ca620b1c374c4 Mon Sep 17 00:00:00 2001 From: Lu Zhen Date: Tue, 12 Dec 2023 20:58:06 +0800 Subject: [PATCH] fix: code generation display issue Log: Change-Id: I23c64bf94e4a2546fb9c1f1ef381500e677725eb --- src/plugins/codegeex/copilot.cpp | 7 ++++++- src/plugins/codegeex/copilot.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/codegeex/copilot.cpp b/src/plugins/codegeex/copilot.cpp index 43c718af4..a20986e2f 100644 --- a/src/plugins/codegeex/copilot.cpp +++ b/src/plugins/codegeex/copilot.cpp @@ -36,7 +36,7 @@ Copilot::Copilot(QObject *parent) case CopilotApi::multilingual_code_generate: mutexResponse.lock(); generateResponse = response; - if (editorService->showTips && !response.isEmpty()) { + if (editorService->showTips && responseValid(response)) { editorService->showTips(generateResponse); } mutexResponse.unlock(); @@ -76,6 +76,11 @@ QString Copilot::apiKey() const return {}; } +bool Copilot::responseValid(const QString &response) +{ + return !(response.isEmpty() || response.startsWith("\n\n\n") || response.startsWith("\n ")); +} + Copilot *Copilot::instance() { static Copilot ins; diff --git a/src/plugins/codegeex/copilot.h b/src/plugins/codegeex/copilot.h index 3957f67c9..7056a66bc 100644 --- a/src/plugins/codegeex/copilot.h +++ b/src/plugins/codegeex/copilot.h @@ -43,6 +43,7 @@ public slots: explicit Copilot(QObject *parent = nullptr); QString selectedText() const; QString apiKey() const; + bool responseValid(const QString &response); CodeGeeX::CopilotApi copilotApi; dpfservice::EditorService *editorService = nullptr;