mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
refactor: Move all processing logic to CodeHandler::processText() (#107)
This will become useful once more processing modes are available
This commit is contained in:
parent
5536de146c
commit
521261e0a3
@ -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;
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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"
|
||||||
|
Loading…
Reference in New Issue
Block a user