mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
refactor: Reduce dependency on TextDocument in ContextManager (#128)
This commit is contained in:
parent
c724bace06
commit
3d770f91c7
@ -170,7 +170,8 @@ void LLMClientInterface::handleCompletion(const QJsonObject &request)
|
|||||||
|
|
||||||
auto updatedContext = prepareContext(request, documentInfo);
|
auto updatedContext = prepareContext(request, documentInfo);
|
||||||
|
|
||||||
bool isPreset1Active = Context::ContextManager::isSpecifyCompletion(request, m_generalSettings);
|
bool isPreset1Active
|
||||||
|
= Context::ContextManager::isSpecifyCompletion(documentInfo, m_generalSettings);
|
||||||
|
|
||||||
const auto providerName = !isPreset1Active ? m_generalSettings.ccProvider()
|
const auto providerName = !isPreset1Active ? m_generalSettings.ccProvider()
|
||||||
: m_generalSettings.ccPreset1Provider();
|
: m_generalSettings.ccPreset1Provider();
|
||||||
@ -279,7 +280,10 @@ LLMCore::ContextData LLMClientInterface::prepareContext(
|
|||||||
void LLMClientInterface::sendCompletionToClient(
|
void LLMClientInterface::sendCompletionToClient(
|
||||||
const QString &completion, const QJsonObject &request, bool isComplete)
|
const QString &completion, const QJsonObject &request, bool isComplete)
|
||||||
{
|
{
|
||||||
bool isPreset1Active = Context::ContextManager::isSpecifyCompletion(request, m_generalSettings);
|
auto filePath = Context::extractFilePathFromRequest(request);
|
||||||
|
auto documentInfo = m_documentReader.readDocument(filePath);
|
||||||
|
bool isPreset1Active
|
||||||
|
= Context::ContextManager::isSpecifyCompletion(documentInfo, m_generalSettings);
|
||||||
|
|
||||||
auto templateName = !isPreset1Active ? m_generalSettings.ccTemplate()
|
auto templateName = !isPreset1Active ? m_generalSettings.ccTemplate()
|
||||||
: m_generalSettings.ccPreset1Template();
|
: m_generalSettings.ccPreset1Template();
|
||||||
|
@ -26,9 +26,6 @@
|
|||||||
|
|
||||||
#include "GeneralSettings.hpp"
|
#include "GeneralSettings.hpp"
|
||||||
#include "Logger.hpp"
|
#include "Logger.hpp"
|
||||||
#include "Utils.hpp"
|
|
||||||
#include <texteditor/textdocument.h>
|
|
||||||
#include <utils/filepath.h>
|
|
||||||
|
|
||||||
namespace QodeAssist::Context {
|
namespace QodeAssist::Context {
|
||||||
|
|
||||||
@ -71,24 +68,20 @@ ContentFile ContextManager::createContentFile(const QString &filePath) const
|
|||||||
return contentFile;
|
return contentFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgrammingLanguage ContextManager::getDocumentLanguage(const QJsonObject &request)
|
ProgrammingLanguage ContextManager::getDocumentLanguage(const DocumentInfo &documentInfo)
|
||||||
{
|
{
|
||||||
auto filePath = extractFilePathFromRequest(request);
|
if (!documentInfo.document) {
|
||||||
TextEditor::TextDocument *textDocument = TextEditor::TextDocument::textDocumentForFilePath(
|
LOG_MESSAGE("Error: Document is not available for" + documentInfo.filePath);
|
||||||
Utils::FilePath::fromString(filePath));
|
|
||||||
|
|
||||||
if (!textDocument) {
|
|
||||||
LOG_MESSAGE("Error: Document is not available for" + filePath);
|
|
||||||
return Context::ProgrammingLanguage::Unknown;
|
return Context::ProgrammingLanguage::Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Context::ProgrammingLanguageUtils::fromMimeType(textDocument->mimeType());
|
return Context::ProgrammingLanguageUtils::fromMimeType(documentInfo.mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContextManager::isSpecifyCompletion(
|
bool ContextManager::isSpecifyCompletion(
|
||||||
const QJsonObject &request, const Settings::GeneralSettings &generalSettings)
|
const DocumentInfo &documentInfo, const Settings::GeneralSettings &generalSettings)
|
||||||
{
|
{
|
||||||
Context::ProgrammingLanguage documentLanguage = getDocumentLanguage(request);
|
Context::ProgrammingLanguage documentLanguage = getDocumentLanguage(documentInfo);
|
||||||
Context::ProgrammingLanguage preset1Language = Context::ProgrammingLanguageUtils::fromString(
|
Context::ProgrammingLanguage preset1Language = Context::ProgrammingLanguageUtils::fromString(
|
||||||
generalSettings.preset1Language.displayForIndex(generalSettings.preset1Language()));
|
generalSettings.preset1Language.displayForIndex(generalSettings.preset1Language()));
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "ContentFile.hpp"
|
#include "ContentFile.hpp"
|
||||||
|
#include "IDocumentReader.hpp"
|
||||||
#include "ProgrammingLanguage.hpp"
|
#include "ProgrammingLanguage.hpp"
|
||||||
#include "settings/GeneralSettings.hpp"
|
#include "settings/GeneralSettings.hpp"
|
||||||
|
|
||||||
@ -37,9 +38,9 @@ public:
|
|||||||
QString readFile(const QString &filePath) const;
|
QString readFile(const QString &filePath) const;
|
||||||
QList<ContentFile> getContentFiles(const QStringList &filePaths) const;
|
QList<ContentFile> getContentFiles(const QStringList &filePaths) const;
|
||||||
|
|
||||||
static ProgrammingLanguage getDocumentLanguage(const QJsonObject &request);
|
static ProgrammingLanguage getDocumentLanguage(const DocumentInfo &documentInfo);
|
||||||
static bool isSpecifyCompletion(
|
static bool isSpecifyCompletion(
|
||||||
const QJsonObject &request, const Settings::GeneralSettings &generalSettings);
|
const DocumentInfo &documentInfo, const Settings::GeneralSettings &generalSettings);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ContextManager(QObject *parent = nullptr);
|
explicit ContextManager(QObject *parent = nullptr);
|
||||||
|
Loading…
Reference in New Issue
Block a user