diff --git a/LLMClientInterface.cpp b/LLMClientInterface.cpp index dd2d3a7..686f4cc 100644 --- a/LLMClientInterface.cpp +++ b/LLMClientInterface.cpp @@ -91,6 +91,27 @@ void LLMClientInterface::handleCancelRequest(const QJsonObject &request) } } +bool LLMClientInterface::processSingleLineCompletion(QNetworkReply *reply, + const QJsonObject &request, + const QString &accumulatedCompletion) +{ + int newlinePos = accumulatedCompletion.indexOf('\n'); + + if (newlinePos != -1) { + QString singleLineCompletion = accumulatedCompletion.left(newlinePos).trimmed(); + singleLineCompletion = removeStopWords(singleLineCompletion); + + QJsonObject position = request["params"].toObject()["doc"].toObject()["position"].toObject(); + + sendCompletionToClient(singleLineCompletion, request, position, true); + m_accumulatedResponses.remove(reply); + reply->abort(); + + return true; + } + return false; +} + QString LLMClientInterface::сontextBefore(TextEditor::TextEditorWidget *widget, int lineNumber, int cursorPosition) @@ -175,9 +196,7 @@ void LLMClientInterface::handleShutdown(const QJsonObject &request) emit messageReceived(LanguageServerProtocol::JsonRpcMessage(response)); } -void LLMClientInterface::handleTextDocumentDidOpen(const QJsonObject &request) -{ -} +void LLMClientInterface::handleTextDocumentDidOpen(const QJsonObject &request) {} void LLMClientInterface::handleInitialized(const QJsonObject &request) { @@ -207,6 +226,11 @@ void LLMClientInterface::handleLLMResponse(QNetworkReply *reply, const QJsonObje QJsonObject position = request["params"].toObject()["doc"].toObject()["position"].toObject(); + if (!settings().multiLineCompletion() + && processSingleLineCompletion(reply, request, accumulatedResponse)) { + return; + } + if (isComplete || reply->isFinished()) { if (isComplete) { auto cleanedCompletion = removeStopWords(accumulatedResponse); @@ -353,8 +377,6 @@ QString LLMClientInterface::removeStopWords(const QString &completion) return filteredCompletion; } -void LLMClientInterface::parseCurrentMessage() -{ -} +void LLMClientInterface::parseCurrentMessage() {} } // namespace QodeAssist diff --git a/LLMClientInterface.hpp b/LLMClientInterface.hpp index b0a11a0..6fef777 100644 --- a/LLMClientInterface.hpp +++ b/LLMClientInterface.hpp @@ -69,6 +69,9 @@ class LLMClientInterface : public LanguageClient::BaseClientInterface void handleInitialized(const QJsonObject &request); void handleExit(const QJsonObject &request); void handleCancelRequest(const QJsonObject &request); + bool processSingleLineCompletion(QNetworkReply *reply, + const QJsonObject &request, + const QString &accumulatedCompletion); QString сontextBefore(TextEditor::TextEditorWidget *widget, int lineNumber, int cursorPosition); QString сontextAfter(TextEditor::TextEditorWidget *widget, int lineNumber, int cursorPosition); diff --git a/QodeAssistConstants.hpp b/QodeAssistConstants.hpp index 3254c4f..3478190 100644 --- a/QodeAssistConstants.hpp +++ b/QodeAssistConstants.hpp @@ -53,6 +53,7 @@ const char START_SUGGESTION_TIMER[] = "QodeAssist.startSuggestionTimer"; const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold"; const char OLLAMA_LIVETIME[] = "QodeAssist.ollamaLivetime"; const char SPECIFIC_INSTRUCTIONS[] = "QodeAssist.specificInstractions"; +const char MULTILINE_COMPLETION[] = "QodeAssist.multilineCompletion"; const char QODE_ASSIST_GENERAL_OPTIONS_ID[] = "QodeAssist.GeneralOptions"; const char QODE_ASSIST_GENERAL_OPTIONS_CATEGORY[] = "QodeAssist.Category"; diff --git a/QodeAssistSettings.cpp b/QodeAssistSettings.cpp index 9fd5437..77b3b59 100644 --- a/QodeAssistSettings.cpp +++ b/QodeAssistSettings.cpp @@ -166,6 +166,9 @@ QodeAssistSettings::QodeAssistSettings() "CRITICAL: Please provide minimal the best possible code completion suggestions.\n"); resetToDefaults.m_buttonText = Tr::tr("Reset to Defaults"); + multiLineCompletion.setSettingsKey(Constants::MULTILINE_COMPLETION); + multiLineCompletion.setDefaultValue(true); + multiLineCompletion.setLabelText(Tr::tr("Enable Multiline Completion")); const auto &manager = LLMProvidersManager::instance(); if (!manager.getProviderNames().isEmpty()) { @@ -203,6 +206,7 @@ QodeAssistSettings::QodeAssistSettings() return Column{Group{title(Tr::tr("General Settings")), Form{Column{enableQodeAssist, enableAutoComplete, + multiLineCompletion, enableLogging, Row{Stretch{1}, resetToDefaults}}}}, Group{title(Tr::tr("LLM Providers")), diff --git a/QodeAssistSettings.hpp b/QodeAssistSettings.hpp index b512234..32cba11 100644 --- a/QodeAssistSettings.hpp +++ b/QodeAssistSettings.hpp @@ -96,6 +96,7 @@ class QodeAssistSettings : public Utils::AspectContainer Utils::StringAspect ollamaLivetime{this}; Utils::StringAspect specificInstractions{this}; + Utils::BoolAspect multiLineCompletion{this}; ButtonAspect resetToDefaults{this};