diff options
Diffstat (limited to 'src/plugins/cpptools')
-rw-r--r-- | src/plugins/cpptools/cppcompletionassist.cpp | 11 | ||||
-rw-r--r-- | src/plugins/cpptools/cppcompletionassistprovider.cpp | 7 | ||||
-rw-r--r-- | src/plugins/cpptools/cppcompletionassistprovider.h | 1 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptoolsreuse.cpp | 21 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptoolsreuse.h | 4 |
5 files changed, 36 insertions, 8 deletions
diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp index 70c190b9ef..77a25b1d5c 100644 --- a/src/plugins/cpptools/cppcompletionassist.cpp +++ b/src/plugins/cpptools/cppcompletionassist.cpp @@ -35,6 +35,7 @@ #include "cppsnapshotupdater.h" #include "cpptoolsconstants.h" #include "cpptoolseditorsupport.h" +#include "cpptoolsreuse.h" #include <coreplugin/icore.h> #include <cppeditor/cppeditorconstants.h> @@ -314,8 +315,7 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e while (preserveLength > 0) { if (inEditor.startsWith(toInsert.right(preserveLength)) && (inEditorLength == preserveLength - || (!inEditor.at(preserveLength).isLetterOrNumber() - && inEditor.at(preserveLength) != QLatin1Char('_')))) { + || !CppTools::isValidIdentifierChar(inEditor.at(preserveLength)))) { break; } --preserveLength; @@ -671,11 +671,12 @@ bool CppCompletionAssistProcessor::accepts() const } else { // Trigger completion after three characters of a name have been typed, when not editing an existing name QChar characterUnderCursor = m_interface->characterAt(pos); - if (!characterUnderCursor.isLetterOrNumber() && characterUnderCursor != QLatin1Char('_')) { + + if (!isValidIdentifierChar(characterUnderCursor)) { const int startOfName = findStartOfName(pos); if (pos - startOfName >= 3) { const QChar firstCharacter = m_interface->characterAt(startOfName); - if (firstCharacter.isLetter() || firstCharacter == QLatin1Char('_')) { + if (isValidFirstIdentifierChar(firstCharacter)) { // Finally check that we're not inside a comment or string (code copied from startOfOperator) QTextCursor tc(m_interface->textDocument()); tc.setPosition(pos); @@ -875,7 +876,7 @@ int CppCompletionAssistProcessor::findStartOfName(int pos) const // Skip to the start of a name do { chr = m_interface->characterAt(--pos); - } while (chr.isLetterOrNumber() || chr == QLatin1Char('_')); + } while (CppTools::isValidIdentifierChar(chr)); return pos + 1; } diff --git a/src/plugins/cpptools/cppcompletionassistprovider.cpp b/src/plugins/cpptools/cppcompletionassistprovider.cpp index 11824b3b1d..c6a5dacfe4 100644 --- a/src/plugins/cpptools/cppcompletionassistprovider.cpp +++ b/src/plugins/cpptools/cppcompletionassistprovider.cpp @@ -29,6 +29,8 @@ #include "cppcompletionassistprovider.h" +#include "cpptoolsreuse.h" + #include <cppeditor/cppeditorconstants.h> #include <cplusplus/Token.h> @@ -59,6 +61,11 @@ bool CppCompletionAssistProvider::isActivationCharSequence(const QString &sequen return false; } +bool CppCompletionAssistProvider::isContinuationChar(const QChar &c) const +{ + return isValidIdentifierChar(c); +} + int CppCompletionAssistProvider::activationSequenceChar(const QChar &ch, const QChar &ch2, const QChar &ch3, diff --git a/src/plugins/cpptools/cppcompletionassistprovider.h b/src/plugins/cpptools/cppcompletionassistprovider.h index 21116a456a..de91093e43 100644 --- a/src/plugins/cpptools/cppcompletionassistprovider.h +++ b/src/plugins/cpptools/cppcompletionassistprovider.h @@ -58,6 +58,7 @@ public: bool supportsEditor(const Core::Id &editorId) const QTC_OVERRIDE; int activationCharSequenceLength() const QTC_OVERRIDE; bool isActivationCharSequence(const QString &sequence) const QTC_OVERRIDE; + bool isContinuationChar(const QChar &c) const QTC_OVERRIDE; virtual TextEditor::IAssistInterface *createAssistInterface( ProjectExplorer::Project *project, TextEditor::BaseTextEditor *editor, diff --git a/src/plugins/cpptools/cpptoolsreuse.cpp b/src/plugins/cpptools/cpptoolsreuse.cpp index b2d9c17d16..b71ceeecac 100644 --- a/src/plugins/cpptools/cpptoolsreuse.cpp +++ b/src/plugins/cpptools/cpptoolsreuse.cpp @@ -50,7 +50,7 @@ static void moveCursorToStartOrEndOfIdentifier(QTextCursor *tc, return; QChar ch = doc->characterAt(tc->position() - posDiff); - while (ch.isLetterOrNumber() || ch == QLatin1Char('_')) { + while (isValidIdentifierChar(ch)) { tc->movePosition(op); ch = doc->characterAt(tc->position() - posDiff); } @@ -111,16 +111,31 @@ bool isOwnershipRAIIType(CPlusPlus::Symbol *symbol, const LookupContext &context return false; } +bool isValidAsciiIdentifierChar(const QChar &ch) +{ + return ch.isLetterOrNumber() || ch == QLatin1Char(' '); +} + +bool isValidFirstIdentifierChar(const QChar &ch) +{ + return ch.isLetter() || ch == QLatin1Char('_') || ch.isHighSurrogate() || ch.isLowSurrogate(); +} + +bool isValidIdentifierChar(const QChar &ch) +{ + return isValidFirstIdentifierChar(ch) || ch.isNumber(); +} + bool isValidIdentifier(const QString &s) { const int length = s.length(); for (int i = 0; i < length; ++i) { const QChar &c = s.at(i); if (i == 0) { - if (!c.isLetter() && c != QLatin1Char('_')) + if (!isValidFirstIdentifierChar(c)) return false; } else { - if (!c.isLetterOrNumber() && c != QLatin1Char('_')) + if (!isValidIdentifierChar(c)) return false; } } diff --git a/src/plugins/cpptools/cpptoolsreuse.h b/src/plugins/cpptools/cpptoolsreuse.h index a0156a8093..87b1e5eb3e 100644 --- a/src/plugins/cpptools/cpptoolsreuse.h +++ b/src/plugins/cpptools/cpptoolsreuse.h @@ -32,6 +32,7 @@ #include "cpptools_global.h" +QT_FORWARD_DECLARE_CLASS(QChar) QT_FORWARD_DECLARE_CLASS(QTextCursor) QT_FORWARD_DECLARE_CLASS(QStringRef) @@ -48,6 +49,9 @@ void CPPTOOLS_EXPORT moveCursorToStartOfIdentifier(QTextCursor *tc); bool CPPTOOLS_EXPORT isOwnershipRAIIType(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context); +bool CPPTOOLS_EXPORT isValidAsciiIdentifierChar(const QChar &ch); +bool CPPTOOLS_EXPORT isValidFirstIdentifierChar(const QChar &ch); +bool CPPTOOLS_EXPORT isValidIdentifierChar(const QChar &ch); bool CPPTOOLS_EXPORT isValidIdentifier(const QString &s); bool CPPTOOLS_EXPORT isQtKeyword(const QStringRef &text); |