refactor: Move all processing logic to CodeHandler::processText() (#107)

This will become useful once more processing modes are available
This commit is contained in:
Povilas Kanapickas 2025-03-06 19:49:28 +02:00 committed by GitHub
parent 5536de146c
commit 521261e0a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 7 deletions

View File

@ -22,8 +22,12 @@
namespace QodeAssist { namespace QodeAssist {
QString CodeHandler::processText(QString text) QString CodeHandler::processText(QString text, bool smartProcess)
{ {
if (!smartProcess) {
return text;
}
QString result; QString result;
QStringList lines = text.split('\n'); QStringList lines = text.split('\n');
bool inCodeBlock = false; bool inCodeBlock = false;

View File

@ -28,7 +28,7 @@ namespace QodeAssist {
class CodeHandler class CodeHandler
{ {
public: public:
static QString processText(QString text); static QString processText(QString text, bool smartProcess = true);
static QString detectLanguage(const QString &line); static QString detectLanguage(const QString &line);

View File

@ -293,11 +293,9 @@ void LLMClientInterface::sendCompletionToClient(
LOG_MESSAGE(QString("Completions before filter: \n%1").arg(completion)); LOG_MESSAGE(QString("Completions before filter: \n%1").arg(completion));
QString processedCompletion bool smartProcess = promptTemplate->type() == LLMCore::TemplateType::Chat
= promptTemplate->type() == LLMCore::TemplateType::Chat && Settings::codeCompletionSettings().smartProcessInstuctText();
&& Settings::codeCompletionSettings().smartProcessInstuctText() QString processedCompletion = CodeHandler::processText(completion, smartProcess);
? CodeHandler::processText(completion)
: completion;
completionItem[LanguageServerProtocol::textKey] = processedCompletion; completionItem[LanguageServerProtocol::textKey] = processedCompletion;
QJsonObject range; QJsonObject range;

View File

@ -33,6 +33,15 @@ class CodeHandlerTest : public QObject, public testing::Test
Q_OBJECT Q_OBJECT
}; };
TEST_F(CodeHandlerTest, testProcessTextNoProcessWithCodeBlock)
{
QString input = "This is a comment\n"
"```python\nprint('Hello, world!')\n```\n"
"Another comment";
EXPECT_EQ(CodeHandler::processText(input, false), input);
}
TEST_F(CodeHandlerTest, testProcessTextWithCodeBlock) TEST_F(CodeHandlerTest, testProcessTextWithCodeBlock)
{ {
QString input = "This is a comment\n" QString input = "This is a comment\n"