mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-07-20 22:14:42 -04:00
refactor: Extract document reading to separate class (#127)
This decouples LLMClientInterface from Qt Creator text editor implementation and allows to write tests
This commit is contained in:
committed by
GitHub
parent
a218064a4f
commit
719065ebfc
@ -23,8 +23,6 @@
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include <texteditor/textdocument.h>
|
||||
|
||||
#include "CodeHandler.hpp"
|
||||
#include "context/ContextManager.hpp"
|
||||
#include "context/DocumentContextReader.hpp"
|
||||
@ -44,12 +42,14 @@ LLMClientInterface::LLMClientInterface(
|
||||
LLMCore::IProviderRegistry &providerRegistry,
|
||||
LLMCore::IPromptProvider *promptProvider,
|
||||
LLMCore::RequestHandlerBase &requestHandler,
|
||||
Context::IDocumentReader &documentReader,
|
||||
IRequestPerformanceLogger &performanceLogger)
|
||||
: m_generalSettings(generalSettings)
|
||||
, m_completeSettings(completeSettings)
|
||||
, m_providerRegistry(providerRegistry)
|
||||
, m_promptProvider(promptProvider)
|
||||
, m_requestHandler(requestHandler)
|
||||
, m_documentReader(documentReader)
|
||||
, m_performanceLogger(performanceLogger)
|
||||
{
|
||||
connect(
|
||||
@ -261,12 +261,10 @@ LLMCore::ContextData LLMClientInterface::prepareContext(
|
||||
QJsonObject params = request["params"].toObject();
|
||||
QJsonObject doc = params["doc"].toObject();
|
||||
QJsonObject position = doc["position"].toObject();
|
||||
|
||||
auto filePath = Context::extractFilePathFromRequest(request);
|
||||
TextEditor::TextDocument *textDocument = TextEditor::TextDocument::textDocumentForFilePath(
|
||||
Utils::FilePath::fromString(filePath));
|
||||
|
||||
if (!textDocument) {
|
||||
auto documentInfo = m_documentReader.readDocument(filePath);
|
||||
if (!documentInfo.document) {
|
||||
LOG_MESSAGE("Error: Document is not available for" + filePath);
|
||||
return LLMCore::ContextData{};
|
||||
}
|
||||
@ -275,7 +273,7 @@ LLMCore::ContextData LLMClientInterface::prepareContext(
|
||||
int lineNumber = position["line"].toInt();
|
||||
|
||||
Context::DocumentContextReader
|
||||
reader(textDocument->document(), textDocument->mimeType(), filePath);
|
||||
reader(documentInfo.document, documentInfo.mimeType, documentInfo.filePath);
|
||||
return reader.prepareContext(lineNumber, cursorPosition, m_completeSettings);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user