Skip to content

Commit

Permalink
Add singleline completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Palm1r committed Aug 29, 2024
1 parent 1201da6 commit a613ea1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
34 changes: 28 additions & 6 deletions LLMClientInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -353,8 +377,6 @@ QString LLMClientInterface::removeStopWords(const QString &completion)
return filteredCompletion;
}

void LLMClientInterface::parseCurrentMessage()
{
}
void LLMClientInterface::parseCurrentMessage() {}

} // namespace QodeAssist
3 changes: 3 additions & 0 deletions LLMClientInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions QodeAssistConstants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 4 additions & 0 deletions QodeAssistSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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")),
Expand Down
1 change: 1 addition & 0 deletions QodeAssistSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class QodeAssistSettings : public Utils::AspectContainer

Utils::StringAspect ollamaLivetime{this};
Utils::StringAspect specificInstractions{this};
Utils::BoolAspect multiLineCompletion{this};

ButtonAspect resetToDefaults{this};

Expand Down

0 comments on commit a613ea1

Please sign in to comment.