diff --git a/QodeAssistClient.cpp b/QodeAssistClient.cpp index 1866c3a..aadcfe2 100644 --- a/QodeAssistClient.cpp +++ b/QodeAssistClient.cpp @@ -152,14 +152,16 @@ void QodeAssistClient::openDocument(TextEditor::TextDocument *document) } bool isSpaceOrTab = lastChar[0].isSpace(); + bool ignoreWhitespace + = Settings::codeCompletionSettings().ignoreWhitespaceInCharCount(); - if (!isSpaceOrTab) { + if (!ignoreWhitespace || !isSpaceOrTab) { m_recentCharCount += charsAdded; } if (m_typingTimer.elapsed() > Settings::codeCompletionSettings().autoCompletionTypingInterval()) { - m_recentCharCount = isSpaceOrTab ? 0 : charsAdded; + m_recentCharCount = (ignoreWhitespace && isSpaceOrTab) ? 0 : charsAdded; m_typingTimer.restart(); } diff --git a/settings/CodeCompletionSettings.cpp b/settings/CodeCompletionSettings.cpp index e332e77..8ba751a 100644 --- a/settings/CodeCompletionSettings.cpp +++ b/settings/CodeCompletionSettings.cpp @@ -132,6 +132,15 @@ CodeCompletionSettings::CodeCompletionSettings() "Space is recommended as least conflicting with context menu.\n" "(Only for Hint-based trigger mode)")); + ignoreWhitespaceInCharCount.setSettingsKey(Constants::CC_IGNORE_WHITESPACE_IN_CHAR_COUNT); + ignoreWhitespaceInCharCount.setLabelText( + Tr::tr("Ignore spaces and tabs in character count")); + ignoreWhitespaceInCharCount.setDefaultValue(true); + ignoreWhitespaceInCharCount.setToolTip( + Tr::tr("When enabled, spaces and tabs are not counted towards the character threshold " + "for triggering completions. This helps trigger completions based on actual code " + "characters only.")); + // General Parameters Settings temperature.setSettingsKey(Constants::CC_TEMPERATURE); temperature.setLabelText(Tr::tr("Temperature:")); @@ -364,7 +373,8 @@ CodeCompletionSettings::CodeCompletionSettings() auto hintTriggerSettings = Column{ Row{hintCharThreshold, hintHideTimeout, Stretch{1}}, - Row{hintTriggerKey, Stretch{1}}}; + Row{hintTriggerKey, Stretch{1}}, + ignoreWhitespaceInCharCount}; return Column{Row{Stretch{1}, resetToDefaults}, Space{8}, @@ -461,6 +471,7 @@ void CodeCompletionSettings::resetSettingsToDefaults() resetAspect(hintCharThreshold); resetAspect(hintHideTimeout); resetAspect(hintTriggerKey); + resetAspect(ignoreWhitespaceInCharCount); resetAspect(abortAssistOnRequest); writeSettings(); } diff --git a/settings/CodeCompletionSettings.hpp b/settings/CodeCompletionSettings.hpp index caa9656..597d1f1 100644 --- a/settings/CodeCompletionSettings.hpp +++ b/settings/CodeCompletionSettings.hpp @@ -44,6 +44,7 @@ public: Utils::IntegerAspect hintCharThreshold{this}; Utils::IntegerAspect hintHideTimeout{this}; Utils::SelectionAspect hintTriggerKey{this}; + Utils::BoolAspect ignoreWhitespaceInCharCount{this}; Utils::StringListAspect customLanguages{this}; diff --git a/settings/SettingsConstants.hpp b/settings/SettingsConstants.hpp index 6521a9b..16faae5 100644 --- a/settings/SettingsConstants.hpp +++ b/settings/SettingsConstants.hpp @@ -89,6 +89,7 @@ const char CC_HINT_CHAR_THRESHOLD[] = "QodeAssist.ccHintCharThreshold"; const char CC_HINT_HIDE_TIMEOUT[] = "QodeAssist.ccHintHideTimeout"; const char CC_HINT_TRIGGER_KEY[] = "QodeAssist.ccHintTriggerKey"; const char CC_ABORT_ASSIST_ON_REQUEST[] = "QodeAssist.ccAbortAssistOnRequest"; +const char CC_IGNORE_WHITESPACE_IN_CHAR_COUNT[] = "QodeAssist.ccIgnoreWhitespaceInCharCount"; const char MAX_FILE_THRESHOLD[] = "QodeAssist.maxFileThreshold"; const char CC_MULTILINE_COMPLETION[] = "QodeAssist.ccMultilineCompletion"; const char CC_MODEL_OUTPUT_HANDLER[] = "QodeAssist.ccModelOutputHandler";