mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-06-04 01:28:58 -04:00
Add smart trigger for call suggestion
This commit is contained in:
parent
15af137728
commit
9361c27d6e
@ -43,6 +43,7 @@ namespace QodeAssist {
|
|||||||
|
|
||||||
QodeAssistClient::QodeAssistClient()
|
QodeAssistClient::QodeAssistClient()
|
||||||
: LanguageClient::Client(new LLMClientInterface())
|
: LanguageClient::Client(new LLMClientInterface())
|
||||||
|
, m_recentCharCount(0)
|
||||||
{
|
{
|
||||||
setName("Qode Assist");
|
setName("Qode Assist");
|
||||||
LanguageClient::LanguageFilter filter;
|
LanguageClient::LanguageFilter filter;
|
||||||
@ -51,6 +52,8 @@ QodeAssistClient::QodeAssistClient()
|
|||||||
|
|
||||||
start();
|
start();
|
||||||
setupConnections();
|
setupConnections();
|
||||||
|
|
||||||
|
m_typingTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
QodeAssistClient::~QodeAssistClient()
|
QodeAssistClient::~QodeAssistClient()
|
||||||
@ -86,7 +89,18 @@ void QodeAssistClient::openDocument(TextEditor::TextDocument *document)
|
|||||||
const int cursorPosition = widget->textCursor().position();
|
const int cursorPosition = widget->textCursor().position();
|
||||||
if (cursorPosition < position || cursorPosition > position + charsAdded)
|
if (cursorPosition < position || cursorPosition > position + charsAdded)
|
||||||
return;
|
return;
|
||||||
scheduleRequest(widget);
|
|
||||||
|
m_recentCharCount += charsAdded;
|
||||||
|
|
||||||
|
if (m_typingTimer.elapsed()
|
||||||
|
> Settings::generalSettings().autoCompletionTypingInterval()) {
|
||||||
|
m_recentCharCount = charsAdded;
|
||||||
|
m_typingTimer.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_recentCharCount > Settings::generalSettings().autoCompletionCharThreshold()) {
|
||||||
|
scheduleRequest(widget);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +144,8 @@ void QodeAssistClient::scheduleRequest(TextEditor::TextEditorWidget *editor)
|
|||||||
connect(timer, &QTimer::timeout, this, [this, editor]() {
|
connect(timer, &QTimer::timeout, this, [this, editor]() {
|
||||||
if (editor
|
if (editor
|
||||||
&& editor->textCursor().position()
|
&& editor->textCursor().position()
|
||||||
== m_scheduledRequests[editor]->property("cursorPosition").toInt())
|
== m_scheduledRequests[editor]->property("cursorPosition").toInt()
|
||||||
|
&& m_recentCharCount > Settings::generalSettings().autoCompletionCharThreshold())
|
||||||
requestCompletions(editor);
|
requestCompletions(editor);
|
||||||
});
|
});
|
||||||
connect(editor, &TextEditorWidget::destroyed, this, [this, editor]() {
|
connect(editor, &TextEditorWidget::destroyed, this, [this, editor]() {
|
||||||
@ -146,7 +161,6 @@ void QodeAssistClient::scheduleRequest(TextEditor::TextEditorWidget *editor)
|
|||||||
it.value()->setProperty("cursorPosition", editor->textCursor().position());
|
it.value()->setProperty("cursorPosition", editor->textCursor().position());
|
||||||
it.value()->start(Settings::generalSettings().startSuggestionTimer());
|
it.value()->start(Settings::generalSettings().startSuggestionTimer());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QodeAssistClient::handleCompletions(const GetCompletionRequest::Response &response,
|
void QodeAssistClient::handleCompletions(const GetCompletionRequest::Response &response,
|
||||||
TextEditor::TextEditorWidget *editor)
|
TextEditor::TextEditorWidget *editor)
|
||||||
{
|
{
|
||||||
|
@ -55,6 +55,9 @@ private:
|
|||||||
QHash<TextEditor::TextEditorWidget *, QTimer *> m_scheduledRequests;
|
QHash<TextEditor::TextEditorWidget *, QTimer *> m_scheduledRequests;
|
||||||
QMetaObject::Connection m_documentOpenedConnection;
|
QMetaObject::Connection m_documentOpenedConnection;
|
||||||
QMetaObject::Connection m_documentClosedConnection;
|
QMetaObject::Connection m_documentClosedConnection;
|
||||||
|
|
||||||
|
QElapsedTimer m_typingTimer;
|
||||||
|
int m_recentCharCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QodeAssist
|
} // namespace QodeAssist
|
||||||
|
@ -49,6 +49,8 @@ const char USE_FREQUENCY_PENALTY[] = "QodeAssist.useFrequencyPenalty";
|
|||||||
const char FREQUENCY_PENALTY[] = "QodeAssist.frequencyPenalty";
|
const char FREQUENCY_PENALTY[] = "QodeAssist.frequencyPenalty";
|
||||||
const char PROVIDER_PATHS[] = "QodeAssist.providerPaths";
|
const char PROVIDER_PATHS[] = "QodeAssist.providerPaths";
|
||||||
const char START_SUGGESTION_TIMER[] = "QodeAssist.startSuggestionTimer";
|
const char START_SUGGESTION_TIMER[] = "QodeAssist.startSuggestionTimer";
|
||||||
|
const char AUTO_COMPLETION_CHAR_THRESHOLD[] = "QodeAssist.autoCompletionCharThreshold";
|
||||||
|
const char AUTO_COMPLETION_TYPING_INTERVAL[] = "QodeAssist.autoCompletionTypingInterval";
|
||||||
const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold";
|
const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold";
|
||||||
const char OLLAMA_LIVETIME[] = "QodeAssist.ollamaLivetime";
|
const char OLLAMA_LIVETIME[] = "QodeAssist.ollamaLivetime";
|
||||||
const char SPECIFIC_INSTRUCTIONS[] = "QodeAssist.specificInstractions";
|
const char SPECIFIC_INSTRUCTIONS[] = "QodeAssist.specificInstractions";
|
||||||
|
@ -66,6 +66,24 @@ GeneralSettings::GeneralSettings()
|
|||||||
startSuggestionTimer.setRange(10, 10000);
|
startSuggestionTimer.setRange(10, 10000);
|
||||||
startSuggestionTimer.setDefaultValue(500);
|
startSuggestionTimer.setDefaultValue(500);
|
||||||
|
|
||||||
|
autoCompletionCharThreshold.setSettingsKey(Constants::AUTO_COMPLETION_CHAR_THRESHOLD);
|
||||||
|
autoCompletionCharThreshold.setLabelText(
|
||||||
|
Tr::tr("Character threshold for AI suggestion start:"));
|
||||||
|
autoCompletionCharThreshold.setToolTip(
|
||||||
|
Tr::tr("The number of characters that need to be typed within the typing interval "
|
||||||
|
"before an AI suggestion request is sent."));
|
||||||
|
autoCompletionCharThreshold.setRange(1, 10);
|
||||||
|
autoCompletionCharThreshold.setDefaultValue(2);
|
||||||
|
|
||||||
|
autoCompletionTypingInterval.setSettingsKey(Constants::AUTO_COMPLETION_TYPING_INTERVAL);
|
||||||
|
autoCompletionTypingInterval.setLabelText(
|
||||||
|
Tr::tr("Typing interval for AI suggestion start(ms):"));
|
||||||
|
autoCompletionTypingInterval.setToolTip(
|
||||||
|
Tr::tr("The time window (in milliseconds) during which the character threshold "
|
||||||
|
"must be met to trigger an AI suggestion request."));
|
||||||
|
autoCompletionTypingInterval.setRange(500, 5000);
|
||||||
|
autoCompletionTypingInterval.setDefaultValue(2000);
|
||||||
|
|
||||||
llmProviders.setSettingsKey(Constants::LLM_PROVIDERS);
|
llmProviders.setSettingsKey(Constants::LLM_PROVIDERS);
|
||||||
llmProviders.setDisplayName(Tr::tr("FIM Provider:"));
|
llmProviders.setDisplayName(Tr::tr("FIM Provider:"));
|
||||||
llmProviders.setDisplayStyle(Utils::SelectionAspect::DisplayStyle::ComboBox);
|
llmProviders.setDisplayStyle(Utils::SelectionAspect::DisplayStyle::ComboBox);
|
||||||
@ -121,6 +139,8 @@ GeneralSettings::GeneralSettings()
|
|||||||
auto rootLayout = Column{Row{enableQodeAssist, Stretch{1}, resetToDefaults},
|
auto rootLayout = Column{Row{enableQodeAssist, Stretch{1}, resetToDefaults},
|
||||||
enableAutoComplete,
|
enableAutoComplete,
|
||||||
startSuggestionTimer,
|
startSuggestionTimer,
|
||||||
|
autoCompletionCharThreshold,
|
||||||
|
autoCompletionTypingInterval,
|
||||||
multiLineCompletion,
|
multiLineCompletion,
|
||||||
Space{8},
|
Space{8},
|
||||||
enableLogging,
|
enableLogging,
|
||||||
@ -208,6 +228,8 @@ void GeneralSettings::resetPageToDefaults()
|
|||||||
resetAspect(fimPrompts);
|
resetAspect(fimPrompts);
|
||||||
resetAspect(enableLogging);
|
resetAspect(enableLogging);
|
||||||
resetAspect(startSuggestionTimer);
|
resetAspect(startSuggestionTimer);
|
||||||
|
resetAspect(autoCompletionTypingInterval);
|
||||||
|
resetAspect(autoCompletionCharThreshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
fimPrompts.setStringValue("StarCoder2");
|
fimPrompts.setStringValue("StarCoder2");
|
||||||
|
@ -35,6 +35,8 @@ public:
|
|||||||
Utils::BoolAspect multiLineCompletion{this};
|
Utils::BoolAspect multiLineCompletion{this};
|
||||||
Utils::BoolAspect enableLogging{this};
|
Utils::BoolAspect enableLogging{this};
|
||||||
Utils::IntegerAspect startSuggestionTimer{this};
|
Utils::IntegerAspect startSuggestionTimer{this};
|
||||||
|
Utils::IntegerAspect autoCompletionCharThreshold{this};
|
||||||
|
Utils::IntegerAspect autoCompletionTypingInterval{this};
|
||||||
|
|
||||||
Utils::SelectionAspect llmProviders{this};
|
Utils::SelectionAspect llmProviders{this};
|
||||||
Utils::StringAspect url{this};
|
Utils::StringAspect url{this};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user