refactor: Move document access out of prepareContext() (#129)

This commit is contained in:
Povilas Kanapickas 2025-03-10 18:54:03 +02:00 committed by GitHub
parent 719065ebfc
commit c724bace06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 11 deletions

View File

@ -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();

View File

@ -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;