diff --git a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp index b7faeb99d31..ebbc2e58e7b 100644 --- a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp +++ b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -405,11 +406,11 @@ bool ClangCompletionAssistProcessor::accepts() const return true; } else { - // Trigger completion after three characters of a name have been typed, when not editing an existing name + // Trigger completion after n characters of a name have been typed, when not editing an existing name QChar characterUnderCursor = m_interface->characterAt(pos); if (!characterUnderCursor.isLetterOrNumber() && characterUnderCursor != QLatin1Char('_')) { const int startOfName = findStartOfName(pos); - if (pos - startOfName >= 3) { + if (pos - startOfName >= TextEditorSettings::completionSettings().m_characterThreshold) { const QChar firstCharacter = m_interface->characterAt(startOfName); if (firstCharacter.isLetter() || firstCharacter == QLatin1Char('_')) { // Finally check that we're not inside a comment or string (code copied from startOfOperator) diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp index 0a7624576ad..eabe85c62be 100644 --- a/src/plugins/cpptools/cppcompletionassist.cpp +++ b/src/plugins/cpptools/cppcompletionassist.cpp @@ -851,12 +851,12 @@ bool InternalCppCompletionAssistProcessor::accepts() const return true; } else { - // Trigger completion after three characters of a name have been typed, when not editing an existing name + // Trigger completion after n characters of a name have been typed, when not editing an existing name QChar characterUnderCursor = m_interface->characterAt(pos); if (!isValidIdentifierChar(characterUnderCursor)) { const int startOfName = findStartOfName(pos); - if (pos - startOfName >= 3) { + if (pos - startOfName >= TextEditorSettings::completionSettings().m_characterThreshold) { const QChar firstCharacter = m_interface->characterAt(startOfName); if (isValidFirstIdentifierChar(firstCharacter)) { // Finally check that we're not inside a comment or string (code copied from startOfOperator) diff --git a/src/plugins/glsleditor/glslcompletionassist.cpp b/src/plugins/glsleditor/glslcompletionassist.cpp index 69802b7470e..ef86585051f 100644 --- a/src/plugins/glsleditor/glslcompletionassist.cpp +++ b/src/plugins/glsleditor/glslcompletionassist.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -528,7 +529,8 @@ bool GlslCompletionAssistProcessor::acceptsIdleEditor() const ++pos; const QString word = m_interface->textAt(pos, cursorPosition - pos); - if (word.length() > 2 && checkStartOfIdentifier(word)) { + if (word.length() >= TextEditorSettings::completionSettings().m_characterThreshold + && checkStartOfIdentifier(word)) { for (auto character : word) { if (!isIdentifierChar(character)) return false; diff --git a/src/plugins/languageclient/languageclientcompletionassist.cpp b/src/plugins/languageclient/languageclientcompletionassist.cpp index 1d40a38033e..fe460c1581b 100644 --- a/src/plugins/languageclient/languageclientcompletionassist.cpp +++ b/src/plugins/languageclient/languageclientcompletionassist.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -314,13 +315,13 @@ IAssistProposal *LanguageClientCompletionAssistProcessor::perform(const AssistIn QTC_ASSERT(m_client, return nullptr); m_pos = interface->position(); if (interface->reason() == IdleEditor) { - // Trigger an automatic completion request only when we are on a word with more than 2 "identifier" character + // Trigger an automatic completion request only when we are on a word with at least n "identifier" characters const QRegularExpression regexp("[_a-zA-Z0-9]+"); auto hasMatch = [®exp](const QString &txt) { return regexp.match(txt).hasMatch(); }; int delta = 0; while (m_pos - delta > 0 && hasMatch(interface->textAt(m_pos - delta - 1, delta + 1))) ++delta; - if (delta < 3) + if (delta < TextEditorSettings::completionSettings().m_characterThreshold) return nullptr; if (m_client->documentUpdatePostponed(interface->fileName())) { m_postponedUpdateConnection diff --git a/src/plugins/qmljseditor/qmljscompletionassist.cpp b/src/plugins/qmljseditor/qmljscompletionassist.cpp index 0f7fdf0a881..1209e1ab585 100644 --- a/src/plugins/qmljseditor/qmljscompletionassist.cpp +++ b/src/plugins/qmljseditor/qmljscompletionassist.cpp @@ -891,7 +891,8 @@ bool QmlJSCompletionAssistProcessor::acceptsIdleEditor() const ++startPos; const QString &word = m_interface->textAt(startPos, cursorPos - startPos); - if (word.length() > 2 && isIdentifierChar(word.at(0), true)) { + if (word.length() >= TextEditorSettings::completionSettings().m_characterThreshold + && isIdentifierChar(word.at(0), true)) { for (int i = 1; i < word.length(); ++i) { if (!isIdentifierChar(word.at(i))) return false; diff --git a/src/plugins/texteditor/codeassist/documentcontentcompletion.cpp b/src/plugins/texteditor/codeassist/documentcontentcompletion.cpp index 8558e9c392f..4715364f9db 100644 --- a/src/plugins/texteditor/codeassist/documentcontentcompletion.cpp +++ b/src/plugins/texteditor/codeassist/documentcontentcompletion.cpp @@ -31,6 +31,8 @@ #include "genericproposalmodel.h" #include "iassistprocessor.h" #include "../snippets/snippetassistcollector.h" +#include "../completionsettings.h" +#include "../texteditorsettings.h" #include #include @@ -127,8 +129,10 @@ IAssistProposal *DocumentContentCompletionProcessor::perform(const AssistInterfa if (interface->reason() == IdleEditor) { QChar characterUnderCursor = interface->characterAt(interface->position()); - if (characterUnderCursor.isLetterOrNumber() || length < 3) + if (characterUnderCursor.isLetterOrNumber() + || length < TextEditorSettings::completionSettings().m_characterThreshold) { return nullptr; + } } const QString wordUnderCursor = interface->textAt(pos, length); diff --git a/src/plugins/texteditor/codeassist/keywordscompletionassist.cpp b/src/plugins/texteditor/codeassist/keywordscompletionassist.cpp index b08fdc558f7..87a89e9890e 100644 --- a/src/plugins/texteditor/codeassist/keywordscompletionassist.cpp +++ b/src/plugins/texteditor/codeassist/keywordscompletionassist.cpp @@ -195,7 +195,8 @@ IAssistProposal *KeywordsCompletionAssistProcessor::perform(const AssistInterfac if (interface->reason() == IdleEditor) { QChar characterUnderCursor = interface->characterAt(interface->position()); - if (characterUnderCursor.isLetterOrNumber() || interface->position() - startPosition < 3) { + if (characterUnderCursor.isLetterOrNumber() || interface->position() - startPosition + < TextEditorSettings::completionSettings().m_characterThreshold) { QList items; if (m_dynamicCompletionFunction) m_dynamicCompletionFunction(interface, &items, startPosition); diff --git a/src/plugins/texteditor/completionsettings.cpp b/src/plugins/texteditor/completionsettings.cpp index aca84ef1046..e21a7a0c8f8 100644 --- a/src/plugins/texteditor/completionsettings.cpp +++ b/src/plugins/texteditor/completionsettings.cpp @@ -31,6 +31,7 @@ static const char settingsGroup[] = "CppTools/Completion"; static const char caseSensitivityKey[] = "CaseSensitivity"; static const char completionTriggerKey[] = "CompletionTrigger"; static const char automaticProposalTimeoutKey[] = "AutomaticProposalTimeout"; +static const char characterThresholdKey[] = "CharacterThreshold"; static const char autoInsertBracesKey[] = "AutoInsertBraces"; static const char surroundingAutoBracketsKey[] = "SurroundingAutoBrackets"; static const char autoInsertQuotesKey[] = "AutoInsertQuotes"; @@ -52,6 +53,7 @@ void CompletionSettings::toSettings(QSettings *s) const s->setValue(caseSensitivityKey, (int) m_caseSensitivity); s->setValue(completionTriggerKey, (int) m_completionTrigger); s->setValue(automaticProposalTimeoutKey, m_automaticProposalTimeoutInMs); + s->setValue(characterThresholdKey, m_characterThreshold); s->setValue(autoInsertBracesKey, m_autoInsertBrackets); s->setValue(surroundingAutoBracketsKey, m_surroundingAutoBrackets); s->setValue(autoInsertQuotesKey, m_autoInsertQuotes); @@ -78,6 +80,8 @@ void CompletionSettings::fromSettings(QSettings *s) s->value(completionTriggerKey, m_completionTrigger).toInt(); m_automaticProposalTimeoutInMs = s->value(automaticProposalTimeoutKey, m_automaticProposalTimeoutInMs).toInt(); + m_characterThreshold = + s->value(characterThresholdKey, m_characterThreshold).toInt(); m_autoInsertBrackets = s->value(autoInsertBracesKey, m_autoInsertBrackets).toBool(); m_surroundingAutoBrackets = @@ -110,6 +114,7 @@ bool CompletionSettings::equals(const CompletionSettings &cs) const return m_caseSensitivity == cs.m_caseSensitivity && m_completionTrigger == cs.m_completionTrigger && m_automaticProposalTimeoutInMs == cs.m_automaticProposalTimeoutInMs + && m_characterThreshold == cs.m_characterThreshold && m_autoInsertBrackets == cs.m_autoInsertBrackets && m_surroundingAutoBrackets == cs.m_surroundingAutoBrackets && m_autoInsertQuotes == cs.m_autoInsertQuotes diff --git a/src/plugins/texteditor/completionsettings.h b/src/plugins/texteditor/completionsettings.h index c670c05443f..fd274a42c0c 100644 --- a/src/plugins/texteditor/completionsettings.h +++ b/src/plugins/texteditor/completionsettings.h @@ -59,6 +59,7 @@ public: CaseSensitivity m_caseSensitivity = CaseInsensitive; CompletionTrigger m_completionTrigger = AutomaticCompletion; int m_automaticProposalTimeoutInMs = 400; + int m_characterThreshold = 3; bool m_autoInsertBrackets = true; bool m_surroundingAutoBrackets = true; bool m_autoInsertQuotes = true; diff --git a/src/plugins/texteditor/completionsettingspage.cpp b/src/plugins/texteditor/completionsettingspage.cpp index bb8b89a1313..668d5a79b83 100644 --- a/src/plugins/texteditor/completionsettingspage.cpp +++ b/src/plugins/texteditor/completionsettingspage.cpp @@ -100,6 +100,7 @@ CompletionSettingsPageWidget::CompletionSettingsPageWidget(CompletionSettingsPag m_ui.completionTrigger->setCurrentIndex(completionTriggerIndex); m_ui.automaticProposalTimeoutSpinBox ->setValue(m_owner->m_completionSettings.m_automaticProposalTimeoutInMs); + m_ui.thresholdSpinBox->setValue(m_owner->m_completionSettings.m_characterThreshold); m_ui.insertBrackets->setChecked(m_owner->m_completionSettings.m_autoInsertBrackets); m_ui.surroundBrackets->setChecked(m_owner->m_completionSettings.m_surroundingAutoBrackets); m_ui.insertQuotes->setChecked(m_owner->m_completionSettings.m_autoInsertQuotes); @@ -173,6 +174,7 @@ void CompletionSettingsPageWidget::settingsFromUi(CompletionSettings &completion completion.m_completionTrigger = completionTrigger(); completion.m_automaticProposalTimeoutInMs = m_ui.automaticProposalTimeoutSpinBox->value(); + completion.m_characterThreshold = m_ui.thresholdSpinBox->value(); completion.m_autoInsertBrackets = m_ui.insertBrackets->isChecked(); completion.m_surroundingAutoBrackets = m_ui.surroundBrackets->isChecked(); completion.m_autoInsertQuotes = m_ui.insertQuotes->isChecked(); diff --git a/src/plugins/texteditor/completionsettingspage.ui b/src/plugins/texteditor/completionsettingspage.ui index 59e60cb70ee..c661f531ee9 100644 --- a/src/plugins/texteditor/completionsettingspage.ui +++ b/src/plugins/texteditor/completionsettingspage.ui @@ -6,8 +6,8 @@ 0 0 - 551 - 507 + 823 + 756 @@ -16,138 +16,198 @@ Behavior - - - - - Activate completion: - - - - - - - Qt::Horizontal - - - - 70 - 24 - - - - - - - - &Case-sensitivity: - - - caseSensitivity - - - - - - - - 0 - 0 - - - - - Full - + + + + + + + &Case-sensitivity: + + + caseSensitivity + + - - - None - + + + + + + + 0 + 0 + + + + + Full + + + + + None + + + + + First Letter + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - First Letter - + + + + Activate completion: + + - - - - - - - Manually - + + + + + + + Manually + + + + + When Triggered + + + + + Always + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - When Triggered - + + + + Timeout in ms: + + - - - Always - + + + + + + 2000 + + + 50 + + + 400 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - - - - Timeout in ms: - - - - - - - 2000 - - - 50 - - - 400 - - - - - - - Qt::Horizontal - - - - 40 - 24 - - - - - - - - Inserts the common prefix of available completion items. - - - Autocomplete common &prefix - - - true - - - - - - - Splits a string into two lines by adding an end quote at the cursor position when you press Enter and a start quote to the next line, before the rest of the string. + + + + Character threshold: + + + + + + + + + 1 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Inserts the common prefix of available completion items. + + + Autocomplete common &prefix + + + true + + + + + + + Splits a string into two lines by adding an end quote at the cursor position when you press Enter and a start quote to the next line, before the rest of the string. In addition, Shift+Enter inserts an escape character at the cursor position and moves the rest of the string to the next line. - - - Automatically split strings - - + + + Automatically split strings + + + +