From 2fb876ff00fefcb9de50bfa68e12ad3cc4ca94dc Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Wed, 11 Sep 2024 01:37:57 +0200 Subject: [PATCH] Exclude current file cache from request --- LLMClientInterface.cpp | 2 +- core/ChangesManager.cpp | 10 ++++++---- core/ChangesManager.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/LLMClientInterface.cpp b/LLMClientInterface.cpp index 3facf56..cb78ddb 100644 --- a/LLMClientInterface.cpp +++ b/LLMClientInterface.cpp @@ -278,7 +278,7 @@ ContextData LLMClientInterface::prepareContext(const QJsonObject &request, DocumentContextReader reader(widget->textDocument()); - QString recentChanges = ChangesManager::instance().getRecentChangesContext(); + QString recentChanges = ChangesManager::instance().getRecentChangesContext(textDocument); QString contextBefore = сontextBefore(widget, lineNumber, cursorPosition); QString contextAfter = сontextAfter(widget, lineNumber, cursorPosition); diff --git a/core/ChangesManager.cpp b/core/ChangesManager.cpp index fcee753..032dee7 100644 --- a/core/ChangesManager.cpp +++ b/core/ChangesManager.cpp @@ -72,12 +72,14 @@ void ChangesManager::addChange(TextEditor::TextDocument *document, logMessage(QString("ChangesManager: Document queue size %1").arg(documentQueue.size())); } -QString ChangesManager::getRecentChangesContext() const +QString ChangesManager::getRecentChangesContext(const TextEditor::TextDocument *currentDocument) const { QString context; - for (const auto &documentChanges : m_documentChanges) { - for (const auto &change : documentChanges) { - context += change.lineContent + "\n"; + for (auto it = m_documentChanges.constBegin(); it != m_documentChanges.constEnd(); ++it) { + if (it.key() != currentDocument) { + for (const auto &change : it.value()) { + context += change.lineContent + "\n"; + } } } return context; diff --git a/core/ChangesManager.h b/core/ChangesManager.h index 4bd759b..7132347 100644 --- a/core/ChangesManager.h +++ b/core/ChangesManager.h @@ -45,7 +45,7 @@ public: int position, int charsRemoved, int charsAdded); - QString getRecentChangesContext() const; + QString getRecentChangesContext(const TextEditor::TextDocument *currentDocument) const; private: ChangesManager();