mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-06-04 01:28:58 -04:00
Add settings for cache of changes
This commit is contained in:
parent
2fb876ff00
commit
8e052ff45c
@ -282,13 +282,15 @@ ContextData LLMClientInterface::prepareContext(const QJsonObject &request,
|
|||||||
|
|
||||||
QString contextBefore = сontextBefore(widget, lineNumber, cursorPosition);
|
QString contextBefore = сontextBefore(widget, lineNumber, cursorPosition);
|
||||||
QString contextAfter = сontextAfter(widget, lineNumber, cursorPosition);
|
QString contextAfter = сontextAfter(widget, lineNumber, cursorPosition);
|
||||||
QString instructions = QString("%1%2%3").arg(Settings::contextSettings().useSpecificInstructions()
|
QString instructions
|
||||||
? reader.getSpecificInstructions()
|
= QString("%1%2%3").arg(Settings::contextSettings().useSpecificInstructions()
|
||||||
: QString(),
|
? reader.getSpecificInstructions()
|
||||||
Settings::contextSettings().useFilePathInContext()
|
: QString(),
|
||||||
? reader.getLanguageAndFileInfo()
|
Settings::contextSettings().useFilePathInContext()
|
||||||
: QString(),
|
? reader.getLanguageAndFileInfo()
|
||||||
recentChanges);
|
: QString(),
|
||||||
|
Settings::contextSettings().useProjectChangesCache() ? recentChanges
|
||||||
|
: QString());
|
||||||
|
|
||||||
return {QString("%1%2").arg(contextBefore, accumulatedCompletion), contextAfter, instructions};
|
return {QString("%1%2").arg(contextBefore, accumulatedCompletion), contextAfter, instructions};
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "LLMClientInterface.hpp"
|
#include "LLMClientInterface.hpp"
|
||||||
#include "LLMSuggestion.hpp"
|
#include "LLMSuggestion.hpp"
|
||||||
#include "core/ChangesManager.h"
|
#include "core/ChangesManager.h"
|
||||||
|
#include "settings/ContextSettings.hpp"
|
||||||
#include "settings/GeneralSettings.hpp"
|
#include "settings/GeneralSettings.hpp"
|
||||||
|
|
||||||
using namespace LanguageServerProtocol;
|
using namespace LanguageServerProtocol;
|
||||||
@ -85,7 +86,11 @@ void QodeAssistClient::openDocument(TextEditor::TextDocument *document)
|
|||||||
if (!textEditor || textEditor->document() != document)
|
if (!textEditor || textEditor->document() != document)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ChangesManager::instance().addChange(document, position, charsRemoved, charsAdded);
|
if (Settings::contextSettings().useProjectChangesCache())
|
||||||
|
ChangesManager::instance().addChange(document,
|
||||||
|
position,
|
||||||
|
charsRemoved,
|
||||||
|
charsAdded);
|
||||||
|
|
||||||
TextEditorWidget *widget = textEditor->editorWidget();
|
TextEditorWidget *widget = textEditor->editorWidget();
|
||||||
if (widget->isReadOnly() || widget->multiTextCursor().hasMultipleCursors())
|
if (widget->isReadOnly() || widget->multiTextCursor().hasMultipleCursors())
|
||||||
|
@ -59,6 +59,8 @@ const char API_KEY[] = "QodeAssist.apiKey";
|
|||||||
const char USE_SPECIFIC_INSTRUCTIONS[] = "QodeAssist.useSpecificInstructions";
|
const char USE_SPECIFIC_INSTRUCTIONS[] = "QodeAssist.useSpecificInstructions";
|
||||||
const char USE_FILE_PATH_IN_CONTEXT[] = "QodeAssist.useFilePathInContext";
|
const char USE_FILE_PATH_IN_CONTEXT[] = "QodeAssist.useFilePathInContext";
|
||||||
const char CUSTOM_JSON_TEMPLATE[] = "QodeAssist.customJsonTemplate";
|
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_OPTIONS_ID[] = "QodeAssist.GeneralOptions";
|
||||||
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";
|
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "ChangesManager.h"
|
#include "ChangesManager.h"
|
||||||
#include "QodeAssistUtils.hpp"
|
#include "QodeAssistUtils.hpp"
|
||||||
|
#include "settings/ContextSettings.hpp"
|
||||||
|
|
||||||
namespace QodeAssist {
|
namespace QodeAssist {
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ void ChangesManager::addChange(TextEditor::TextDocument *document,
|
|||||||
} else {
|
} else {
|
||||||
documentQueue.enqueue(change);
|
documentQueue.enqueue(change);
|
||||||
|
|
||||||
if (documentQueue.size() > MAX_CACHED_CHANGES) {
|
if (documentQueue.size() > Settings::contextSettings().maxChangesCacheSize()) {
|
||||||
documentQueue.dequeue();
|
documentQueue.dequeue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,6 @@ private:
|
|||||||
ChangesManager &operator=(const ChangesManager &) = delete;
|
ChangesManager &operator=(const ChangesManager &) = delete;
|
||||||
|
|
||||||
void cleanupOldChanges();
|
void cleanupOldChanges();
|
||||||
static const int MAX_CACHED_CHANGES = 50;
|
|
||||||
|
|
||||||
QHash<TextEditor::TextDocument *, QQueue<ChangeInfo>> m_documentChanges;
|
QHash<TextEditor::TextDocument *, QQueue<ChangeInfo>> m_documentChanges;
|
||||||
};
|
};
|
||||||
|
@ -74,6 +74,15 @@ ContextSettings::ContextSettings()
|
|||||||
|
|
||||||
resetToDefaults.m_buttonText = Tr::tr("Reset Page to Defaults");
|
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();
|
readSettings();
|
||||||
|
|
||||||
readStringsAfterCursor.setEnabled(!readFullFile());
|
readStringsAfterCursor.setEnabled(!readFullFile());
|
||||||
@ -90,6 +99,8 @@ ContextSettings::ContextSettings()
|
|||||||
useFilePathInContext,
|
useFilePathInContext,
|
||||||
useSpecificInstructions,
|
useSpecificInstructions,
|
||||||
specificInstractions,
|
specificInstractions,
|
||||||
|
useProjectChangesCache,
|
||||||
|
Row{maxChangesCacheSize, Stretch{1}},
|
||||||
Stretch{1}};
|
Stretch{1}};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,8 @@ public:
|
|||||||
Utils::StringAspect specificInstractions{this};
|
Utils::StringAspect specificInstractions{this};
|
||||||
Utils::BoolAspect useSpecificInstructions{this};
|
Utils::BoolAspect useSpecificInstructions{this};
|
||||||
Utils::BoolAspect useFilePathInContext{this};
|
Utils::BoolAspect useFilePathInContext{this};
|
||||||
|
Utils::BoolAspect useProjectChangesCache{this};
|
||||||
|
Utils::IntegerAspect maxChangesCacheSize{this};
|
||||||
|
|
||||||
ButtonAspect resetToDefaults{this};
|
ButtonAspect resetToDefaults{this};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user