Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions LLMClientInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

Expand Down
2 changes: 1 addition & 1 deletion LLMClientInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LLMClientInterface : public LanguageClient::BaseClientInterface
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;
Expand Down