Add singleline completion

This commit is contained in:
Petr Mironychev 2024-08-29 09:46:41 +02:00
parent 1201da6af3
commit a613ea19f4
5 changed files with 37 additions and 6 deletions

View File

@ -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, QString LLMClientInterface::сontextBefore(TextEditor::TextEditorWidget *widget,
int lineNumber, int lineNumber,
int cursorPosition) int cursorPosition)
@ -175,9 +196,7 @@ void LLMClientInterface::handleShutdown(const QJsonObject &request)
emit messageReceived(LanguageServerProtocol::JsonRpcMessage(response)); emit messageReceived(LanguageServerProtocol::JsonRpcMessage(response));
} }
void LLMClientInterface::handleTextDocumentDidOpen(const QJsonObject &request) void LLMClientInterface::handleTextDocumentDidOpen(const QJsonObject &request) {}
{
}
void LLMClientInterface::handleInitialized(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(); QJsonObject position = request["params"].toObject()["doc"].toObject()["position"].toObject();
if (!settings().multiLineCompletion()
&& processSingleLineCompletion(reply, request, accumulatedResponse)) {
return;
}
if (isComplete || reply->isFinished()) { if (isComplete || reply->isFinished()) {
if (isComplete) { if (isComplete) {
auto cleanedCompletion = removeStopWords(accumulatedResponse); auto cleanedCompletion = removeStopWords(accumulatedResponse);
@ -353,8 +377,6 @@ QString LLMClientInterface::removeStopWords(const QString &completion)
return filteredCompletion; return filteredCompletion;
} }
void LLMClientInterface::parseCurrentMessage() void LLMClientInterface::parseCurrentMessage() {}
{
}
} // namespace QodeAssist } // namespace QodeAssist

View File

@ -69,6 +69,9 @@ private:
void handleInitialized(const QJsonObject &request); void handleInitialized(const QJsonObject &request);
void handleExit(const QJsonObject &request); void handleExit(const QJsonObject &request);
void handleCancelRequest(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 сontextBefore(TextEditor::TextEditorWidget *widget, int lineNumber, int cursorPosition);
QString сontextAfter(TextEditor::TextEditorWidget *widget, int lineNumber, int cursorPosition); QString сontextAfter(TextEditor::TextEditorWidget *widget, int lineNumber, int cursorPosition);

View File

@ -53,6 +53,7 @@ const char START_SUGGESTION_TIMER[] = "QodeAssist.startSuggestionTimer";
const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold"; const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold";
const char OLLAMA_LIVETIME[] = "QodeAssist.ollamaLivetime"; const char OLLAMA_LIVETIME[] = "QodeAssist.ollamaLivetime";
const char SPECIFIC_INSTRUCTIONS[] = "QodeAssist.specificInstractions"; 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_ID[] = "QodeAssist.GeneralOptions";
const char QODE_ASSIST_GENERAL_OPTIONS_CATEGORY[] = "QodeAssist.Category"; const char QODE_ASSIST_GENERAL_OPTIONS_CATEGORY[] = "QodeAssist.Category";

View File

@ -166,6 +166,9 @@ QodeAssistSettings::QodeAssistSettings()
"CRITICAL: Please provide minimal the best possible code completion suggestions.\n"); "CRITICAL: Please provide minimal the best possible code completion suggestions.\n");
resetToDefaults.m_buttonText = Tr::tr("Reset to Defaults"); 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(); const auto &manager = LLMProvidersManager::instance();
if (!manager.getProviderNames().isEmpty()) { if (!manager.getProviderNames().isEmpty()) {
@ -203,6 +206,7 @@ QodeAssistSettings::QodeAssistSettings()
return Column{Group{title(Tr::tr("General Settings")), return Column{Group{title(Tr::tr("General Settings")),
Form{Column{enableQodeAssist, Form{Column{enableQodeAssist,
enableAutoComplete, enableAutoComplete,
multiLineCompletion,
enableLogging, enableLogging,
Row{Stretch{1}, resetToDefaults}}}}, Row{Stretch{1}, resetToDefaults}}}},
Group{title(Tr::tr("LLM Providers")), Group{title(Tr::tr("LLM Providers")),

View File

@ -96,6 +96,7 @@ public:
Utils::StringAspect ollamaLivetime{this}; Utils::StringAspect ollamaLivetime{this};
Utils::StringAspect specificInstractions{this}; Utils::StringAspect specificInstractions{this};
Utils::BoolAspect multiLineCompletion{this};
ButtonAspect resetToDefaults{this}; ButtonAspect resetToDefaults{this};