Add settings for cache of changes

This commit is contained in:
Petr Mironychev 2024-09-11 01:59:25 +02:00
parent 2fb876ff00
commit 8e052ff45c
7 changed files with 32 additions and 10 deletions

View File

@ -282,13 +282,15 @@ ContextData LLMClientInterface::prepareContext(const QJsonObject &request,
QString contextBefore = сontextBefore(widget, lineNumber, cursorPosition);
QString contextAfter = сontextAfter(widget, lineNumber, cursorPosition);
QString instructions = QString("%1%2%3").arg(Settings::contextSettings().useSpecificInstructions()
? reader.getSpecificInstructions()
: QString(),
Settings::contextSettings().useFilePathInContext()
? reader.getLanguageAndFileInfo()
: QString(),
recentChanges);
QString instructions
= QString("%1%2%3").arg(Settings::contextSettings().useSpecificInstructions()
? reader.getSpecificInstructions()
: QString(),
Settings::contextSettings().useFilePathInContext()
? reader.getLanguageAndFileInfo()
: QString(),
Settings::contextSettings().useProjectChangesCache() ? recentChanges
: QString());
return {QString("%1%2").arg(contextBefore, accumulatedCompletion), contextAfter, instructions};
}

View File

@ -32,6 +32,7 @@
#include "LLMClientInterface.hpp"
#include "LLMSuggestion.hpp"
#include "core/ChangesManager.h"
#include "settings/ContextSettings.hpp"
#include "settings/GeneralSettings.hpp"
using namespace LanguageServerProtocol;
@ -85,7 +86,11 @@ void QodeAssistClient::openDocument(TextEditor::TextDocument *document)
if (!textEditor || textEditor->document() != document)
return;
ChangesManager::instance().addChange(document, position, charsRemoved, charsAdded);
if (Settings::contextSettings().useProjectChangesCache())
ChangesManager::instance().addChange(document,
position,
charsRemoved,
charsAdded);
TextEditorWidget *widget = textEditor->editorWidget();
if (widget->isReadOnly() || widget->multiTextCursor().hasMultipleCursors())

View File

@ -59,6 +59,8 @@ const char API_KEY[] = "QodeAssist.apiKey";
const char USE_SPECIFIC_INSTRUCTIONS[] = "QodeAssist.useSpecificInstructions";
const char USE_FILE_PATH_IN_CONTEXT[] = "QodeAssist.useFilePathInContext";
const char CUSTOM_JSON_TEMPLATE[] = "QodeAssist.customJsonTemplate";
const char USE_PROJECT_CHANGES_CACHE[] = "QodeAssist.useProjectChangesCache";
const char MAX_CHANGES_CACHE_SIZE[] = "QodeAssist.maxChangesCacheSize";
const char QODE_ASSIST_GENERAL_OPTIONS_ID[] = "QodeAssist.GeneralOptions";
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";

View File

@ -19,6 +19,7 @@
#include "ChangesManager.h"
#include "QodeAssistUtils.hpp"
#include "settings/ContextSettings.hpp"
namespace QodeAssist {
@ -60,7 +61,7 @@ void ChangesManager::addChange(TextEditor::TextDocument *document,
} else {
documentQueue.enqueue(change);
if (documentQueue.size() > MAX_CACHED_CHANGES) {
if (documentQueue.size() > Settings::contextSettings().maxChangesCacheSize()) {
documentQueue.dequeue();
}
}

View File

@ -54,7 +54,6 @@ private:
ChangesManager &operator=(const ChangesManager &) = delete;
void cleanupOldChanges();
static const int MAX_CACHED_CHANGES = 50;
QHash<TextEditor::TextDocument *, QQueue<ChangeInfo>> m_documentChanges;
};

View File

@ -74,6 +74,15 @@ ContextSettings::ContextSettings()
resetToDefaults.m_buttonText = Tr::tr("Reset Page to Defaults");
useProjectChangesCache.setSettingsKey(Constants::USE_PROJECT_CHANGES_CACHE);
useProjectChangesCache.setDefaultValue(true);
useProjectChangesCache.setLabelText(Tr::tr("Use Project Changes Cache"));
maxChangesCacheSize.setSettingsKey(Constants::MAX_CHANGES_CACHE_SIZE);
maxChangesCacheSize.setLabelText(Tr::tr("Max Changes Cache Size"));
maxChangesCacheSize.setRange(2, 1000);
maxChangesCacheSize.setDefaultValue(20);
readSettings();
readStringsAfterCursor.setEnabled(!readFullFile());
@ -90,6 +99,8 @@ ContextSettings::ContextSettings()
useFilePathInContext,
useSpecificInstructions,
specificInstractions,
useProjectChangesCache,
Row{maxChangesCacheSize, Stretch{1}},
Stretch{1}};
});
}

View File

@ -37,6 +37,8 @@ public:
Utils::StringAspect specificInstractions{this};
Utils::BoolAspect useSpecificInstructions{this};
Utils::BoolAspect useFilePathInContext{this};
Utils::BoolAspect useProjectChangesCache{this};
Utils::IntegerAspect maxChangesCacheSize{this};
ButtonAspect resetToDefaults{this};