LanguageClient: Fix regular expression

The match has to be a full match to avoid always validating
the full file if located at a literal.
This fixes bad performance of language clients in big files.
Amends 119a3c1ce9.

Change-Id: I7153f3d7d7125715846de7626d215093feae2908
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2020-09-09 12:37:44 +02:00
parent f7634fc738
commit 24f35037d1

View File

@@ -315,7 +315,7 @@ IAssistProposal *LanguageClientCompletionAssistProcessor::perform(const AssistIn
m_pos = interface->position(); m_pos = interface->position();
if (interface->reason() == IdleEditor) { 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 more than 2 "identifier" character
const QRegularExpression regexp("[_a-zA-Z0-9]+"); const QRegularExpression regexp("^[_a-zA-Z0-9]+$");
auto hasMatch = [&regexp](const QString &txt) { return regexp.match(txt).hasMatch(); }; auto hasMatch = [&regexp](const QString &txt) { return regexp.match(txt).hasMatch(); };
int delta = 0; int delta = 0;
while (m_pos - delta > 0 && hasMatch(interface->textAt(m_pos - delta - 1, delta + 1))) while (m_pos - delta > 0 && hasMatch(interface->textAt(m_pos - delta - 1, delta + 1)))