From c724bace06d1b5476e7b2429a2be9f701eed0bc2 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Mon, 10 Mar 2025 18:54:03 +0200 Subject: [PATCH] refactor: Move document access out of prepareContext() (#129) --- LLMClientInterface.cpp | 19 +++++++++---------- LLMClientInterface.hpp | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/LLMClientInterface.cpp b/LLMClientInterface.cpp index a565d00..1b0f3af 100644 --- a/LLMClientInterface.cpp +++ b/LLMClientInterface.cpp @@ -161,7 +161,14 @@ void LLMClientInterface::handleExit(const QJsonObject &request) void LLMClientInterface::handleCompletion(const QJsonObject &request) { - auto updatedContext = prepareContext(request); + auto filePath = Context::extractFilePathFromRequest(request); + auto documentInfo = m_documentReader.readDocument(filePath); + if (!documentInfo.document) { + LOG_MESSAGE("Error: Document is not available for" + filePath); + return; + } + + auto updatedContext = prepareContext(request, documentInfo); bool isPreset1Active = Context::ContextManager::isSpecifyCompletion(request, m_generalSettings); @@ -256,19 +263,11 @@ void LLMClientInterface::handleCompletion(const QJsonObject &request) } LLMCore::ContextData LLMClientInterface::prepareContext( - const QJsonObject &request, const QStringView &accumulatedCompletion) + const QJsonObject &request, const Context::DocumentInfo &documentInfo) { QJsonObject params = request["params"].toObject(); QJsonObject doc = params["doc"].toObject(); QJsonObject position = doc["position"].toObject(); - auto filePath = Context::extractFilePathFromRequest(request); - - auto documentInfo = m_documentReader.readDocument(filePath); - if (!documentInfo.document) { - LOG_MESSAGE("Error: Document is not available for" + filePath); - return LLMCore::ContextData{}; - } - int cursorPosition = position["character"].toInt(); int lineNumber = position["line"].toInt(); diff --git a/LLMClientInterface.hpp b/LLMClientInterface.hpp index 6411dd8..d0a4971 100644 --- a/LLMClientInterface.hpp +++ b/LLMClientInterface.hpp @@ -72,7 +72,7 @@ private: void handleCancelRequest(const QJsonObject &request); LLMCore::ContextData prepareContext( - const QJsonObject &request, const QStringView &accumulatedCompletion = QString{}); + const QJsonObject &request, const Context::DocumentInfo &documentInfo); const Settings::CodeCompletionSettings &m_completeSettings; const Settings::GeneralSettings &m_generalSettings;