Merge remote-tracking branch 'origin/4.9'

Change-Id: If4e8f52fc94c4e5fd9ec69c9000436d4ded913ff
This commit is contained in:
Orgad Shaneh
2019-02-15 13:42:44 +02:00
164 changed files with 7476 additions and 1069 deletions

View File

@@ -41,6 +41,7 @@
#include <QDir>
#include <QRegularExpression>
#include <QtGlobal>
namespace CppTools {
@@ -701,6 +702,10 @@ void CompilerOptionsBuilder::reset()
// QMakeProject: -pipe -Whello -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC
void CompilerOptionsBuilder::evaluateCompilerFlags()
{
static QStringList userBlackList = QString::fromLocal8Bit(
qgetenv("QTC_CLANG_CMD_OPTIONS_BLACKLIST"))
.split(';', QString::SkipEmptyParts);
bool containsDriverMode = false;
bool skipNext = false;
for (const QString &option : m_projectPart.compilerFlags) {
@@ -709,6 +714,9 @@ void CompilerOptionsBuilder::evaluateCompilerFlags()
continue;
}
if (userBlackList.contains(option))
continue;
// Ignore warning flags as these interfere with our user-configured diagnostics.
// Note that once "-w" is provided, no warnings will be emitted, even if "-Wall" follows.
if (m_useBuildSystemWarnings == UseBuildSystemWarnings::No

View File

@@ -26,6 +26,7 @@
#include "cpphoverhandler.h"
#include "cppelementevaluator.h"
#include "cpptoolsreuse.h"
#include <coreplugin/helpmanager.h>
#include <texteditor/texteditor.h>
@@ -56,14 +57,16 @@ void CppHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos, Rep
tip += evaluator.diagnosis();
setPriority(Priority_Diagnostic);
}
const QStringList fallback = identifierWordsUnderCursor(tc);
if (evaluator.identifiedCppElement()) {
const QSharedPointer<CppElement> &cppElement = evaluator.cppElement();
QStringList candidates = cppElement->helpIdCandidates;
candidates.removeDuplicates();
const HelpItem helpItem(candidates, cppElement->helpMark, cppElement->helpCategory);
const QStringList candidates = cppElement->helpIdCandidates;
const HelpItem helpItem(candidates + fallback, cppElement->helpMark, cppElement->helpCategory);
setLastHelpItemIdentified(helpItem); // tool tip appended by decorateToolTip
if (!helpItem.isValid())
tip += cppElement->tooltip;
} else {
setLastHelpItemIdentified({fallback, {}, HelpItem::Unknown});
}
setToolTip(tip);
}

View File

@@ -41,6 +41,7 @@
#include <utils/qtcassert.h>
#include <QDebug>
#include <QRegularExpression>
#include <QSet>
#include <QStringRef>
#include <QTextCursor>
@@ -50,29 +51,91 @@ using namespace CPlusPlus;
namespace CppTools {
static void moveCursorToStartOrEndOfIdentifier(QTextCursor *tc,
QTextCursor::MoveOperation op,
int posDiff = 0)
static int skipChars(QTextCursor *tc,
QTextCursor::MoveOperation op,
int offset,
std::function<bool(const QChar &)> skip)
{
QTextDocument *doc = tc->document();
const QTextDocument *doc = tc->document();
if (!doc)
return;
QChar ch = doc->characterAt(tc->position() - posDiff);
while (isValidIdentifierChar(ch)) {
tc->movePosition(op);
ch = doc->characterAt(tc->position() - posDiff);
return 0;
QChar ch = doc->characterAt(tc->position() + offset);
if (ch.isNull())
return 0;
int count = 0;
while (skip(ch)) {
if (tc->movePosition(op))
++count;
else
break;
ch = doc->characterAt(tc->position() + offset);
}
return count;
}
static int skipCharsForward(QTextCursor *tc, std::function<bool(const QChar &)> skip)
{
return skipChars(tc, QTextCursor::NextCharacter, 0, skip);
}
static int skipCharsBackward(QTextCursor *tc, std::function<bool(const QChar &)> skip)
{
return skipChars(tc, QTextCursor::PreviousCharacter, -1, skip);
}
QStringList identifierWordsUnderCursor(const QTextCursor &tc)
{
const QTextDocument *document = tc.document();
if (!document)
return {};
const auto isSpace = [](const QChar &c) { return c.isSpace(); };
const auto isColon = [](const QChar &c) { return c == ':'; };
const auto isValidIdentifierCharAt = [document](const QTextCursor &tc) {
return isValidIdentifierChar(document->characterAt(tc.position()));
};
// move to the end
QTextCursor endCursor(tc);
do {
moveCursorToEndOfIdentifier(&endCursor);
// possibly skip ::
QTextCursor temp(endCursor);
skipCharsForward(&temp, isSpace);
const int colons = skipCharsForward(&temp, isColon);
skipCharsForward(&temp, isSpace);
if (colons == 2 && isValidIdentifierCharAt(temp))
endCursor = temp;
} while (isValidIdentifierCharAt(endCursor));
QStringList results;
QTextCursor startCursor(endCursor);
do {
moveCursorToStartOfIdentifier(&startCursor);
if (startCursor.position() == endCursor.position())
break;
QTextCursor temp(endCursor);
temp.setPosition(startCursor.position(), QTextCursor::KeepAnchor);
results.append(temp.selectedText().remove(QRegularExpression("\\s")));
// possibly skip ::
temp = startCursor;
skipCharsBackward(&temp, isSpace);
const int colons = skipCharsBackward(&temp, isColon);
skipCharsBackward(&temp, isSpace);
if (colons == 2
&& isValidIdentifierChar(document->characterAt(temp.position() - 1))) {
startCursor = temp;
}
} while (!isValidIdentifierCharAt(startCursor));
return results;
}
void moveCursorToEndOfIdentifier(QTextCursor *tc)
{
moveCursorToStartOrEndOfIdentifier(tc, QTextCursor::NextCharacter);
skipCharsForward(tc, isValidIdentifierChar);
}
void moveCursorToStartOfIdentifier(QTextCursor *tc)
{
moveCursorToStartOrEndOfIdentifier(tc, QTextCursor::PreviousCharacter, 1);
skipCharsBackward(tc, isValidIdentifierChar);
}
static bool isOwnershipRAIIName(const QString &name)

View File

@@ -58,6 +58,7 @@ bool CPPTOOLS_EXPORT isValidFirstIdentifierChar(const QChar &ch);
bool CPPTOOLS_EXPORT isValidIdentifierChar(const QChar &ch);
bool CPPTOOLS_EXPORT isValidIdentifier(const QString &s);
QStringList CPPTOOLS_EXPORT identifierWordsUnderCursor(const QTextCursor &tc);
QString CPPTOOLS_EXPORT identifierUnderCursor(QTextCursor *cursor);
bool CPPTOOLS_EXPORT isOwnershipRAIIType(CPlusPlus::Symbol *symbol,