forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/10.0'
Conflicts: src/plugins/python/pipsupport.cpp src/plugins/qtsupport/exampleslistmodel.cpp src/plugins/qtsupport/examplesparser.cpp tests/auto/examples/tst_examples.cpp Change-Id: I00273622423fa99d41621969f6ecbbdaa0e18664
This commit is contained in:
@@ -13,6 +13,7 @@ add_qtc_plugin(ClangCodeModel
|
||||
clangactivationsequencecontextprocessor.cpp clangactivationsequencecontextprocessor.h
|
||||
clangactivationsequenceprocessor.cpp clangactivationsequenceprocessor.h
|
||||
clangcodemodelplugin.cpp clangcodemodelplugin.h
|
||||
clangcodemodeltr.h
|
||||
clangcompletioncontextanalyzer.cpp clangcompletioncontextanalyzer.h
|
||||
clangconstants.h
|
||||
clangdast.cpp clangdast.h
|
||||
|
||||
@@ -385,14 +385,14 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir, c
|
||||
{
|
||||
setName(Tr::tr("clangd"));
|
||||
LanguageFilter langFilter;
|
||||
langFilter.mimeTypes = QStringList{"text/x-chdr", "text/x-csrc",
|
||||
"text/x-c++hdr", "text/x-c++src", "text/x-objc++src", "text/x-objcsrc"};
|
||||
using namespace CppEditor::Constants;
|
||||
langFilter.mimeTypes = QStringList{C_HEADER_MIMETYPE, C_SOURCE_MIMETYPE,
|
||||
CPP_HEADER_MIMETYPE, CPP_SOURCE_MIMETYPE, OBJECTIVE_CPP_SOURCE_MIMETYPE,
|
||||
OBJECTIVE_C_SOURCE_MIMETYPE, CUDA_SOURCE_MIMETYPE};
|
||||
setSupportedLanguage(langFilter);
|
||||
setActivateDocumentAutomatically(true);
|
||||
setCompletionAssistProvider(new ClangdCompletionAssistProvider(this));
|
||||
setQuickFixAssistProvider(new ClangdQuickFixProvider(this));
|
||||
symbolSupport().setDefaultRenamingSymbolMapper(
|
||||
[](const QString &oldSymbol) { return oldSymbol + "_new"; });
|
||||
symbolSupport().setLimitRenamingToProjects(true);
|
||||
if (!project) {
|
||||
QJsonObject initOptions;
|
||||
@@ -523,21 +523,56 @@ void ClangdClient::closeExtraFile(const Utils::FilePath &filePath)
|
||||
SendDocUpdates::Ignore);
|
||||
}
|
||||
|
||||
void ClangdClient::findUsages(TextDocument *document, const QTextCursor &cursor,
|
||||
void ClangdClient::findUsages(const CppEditor::CursorInEditor &cursor,
|
||||
const std::optional<QString> &replacement,
|
||||
const std::function<void()> &renameCallback)
|
||||
{
|
||||
// Quick check: Are we even on anything searchable?
|
||||
const QTextCursor adjustedCursor = d->adjustedCursor(cursor, document);
|
||||
const QTextCursor adjustedCursor = d->adjustedCursor(cursor.cursor(), cursor.textDocument());
|
||||
const QString searchTerm = d->searchTermFromCursor(adjustedCursor);
|
||||
if (searchTerm.isEmpty())
|
||||
return;
|
||||
|
||||
if (replacement && versionNumber() >= QVersionNumber(16)
|
||||
&& Utils::qtcEnvironmentVariable("QTC_CLANGD_RENAMING") != "0") {
|
||||
symbolSupport().renameSymbol(document, adjustedCursor, *replacement, renameCallback,
|
||||
CppEditor::preferLowerCaseFileNames());
|
||||
return;
|
||||
&& Utils::qtcEnvironmentVariable("QTC_CLANGD_RENAMING") != "0") {
|
||||
|
||||
// If we have up-to-date highlighting data, we can prevent giving clangd
|
||||
// macros or namespaces to rename, which it can't cope with.
|
||||
// TODO: Fix this upstream for macros; see https://github.com/clangd/clangd/issues/729.
|
||||
bool useClangdForRenaming = true;
|
||||
const auto highlightingData = d->highlightingData.constFind(cursor.textDocument());
|
||||
if (highlightingData != d->highlightingData.end()
|
||||
&& highlightingData->previousTokens.second == documentVersion(cursor.filePath())) {
|
||||
const auto candidate = std::lower_bound(
|
||||
highlightingData->previousTokens.first.cbegin(),
|
||||
highlightingData->previousTokens.first.cend(),
|
||||
cursor.cursor().position(),
|
||||
[&cursor](const ExpandedSemanticToken &token, int pos) {
|
||||
const int startPos = Utils::Text::positionInText(
|
||||
cursor.textDocument()->document(), token.line, token.column);
|
||||
return startPos + token.length < pos;
|
||||
});
|
||||
if (candidate != highlightingData->previousTokens.first.cend()) {
|
||||
const int startPos = Utils::Text::positionInText(
|
||||
cursor.textDocument()->document(), candidate->line, candidate->column);
|
||||
if (startPos <= cursor.cursor().position()) {
|
||||
if (candidate->type == "namespace") {
|
||||
CppEditor::CppModelManager::globalRename(
|
||||
cursor, *replacement, renameCallback,
|
||||
CppEditor::CppModelManager::Backend::Builtin);
|
||||
return;
|
||||
}
|
||||
if (candidate->type == "macro")
|
||||
useClangdForRenaming = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useClangdForRenaming) {
|
||||
symbolSupport().renameSymbol(cursor.textDocument(), adjustedCursor, *replacement,
|
||||
renameCallback, CppEditor::preferLowerCaseFileNames());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const bool categorize = CppEditor::codeModelSettings()->categorizeFindReferences();
|
||||
@@ -546,14 +581,15 @@ void ClangdClient::findUsages(TextDocument *document, const QTextCursor &cursor,
|
||||
if (searchTerm != "operator" && Utils::allOf(searchTerm, [](const QChar &c) {
|
||||
return c.isLetterOrNumber() || c == '_';
|
||||
})) {
|
||||
d->findUsages(document, adjustedCursor, searchTerm, replacement, renameCallback, categorize);
|
||||
d->findUsages(cursor.textDocument(), adjustedCursor, searchTerm, replacement,
|
||||
renameCallback, categorize);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise get the proper spelling of the search term from clang, so we can put it into the
|
||||
// search widget.
|
||||
const auto symbolInfoHandler = [this, doc = QPointer(document), adjustedCursor, replacement,
|
||||
renameCallback, categorize]
|
||||
const auto symbolInfoHandler = [this, doc = QPointer(cursor.textDocument()), adjustedCursor,
|
||||
replacement, renameCallback, categorize]
|
||||
(const QString &name, const QString &, const MessageId &) {
|
||||
if (!doc)
|
||||
return;
|
||||
@@ -561,7 +597,8 @@ void ClangdClient::findUsages(TextDocument *document, const QTextCursor &cursor,
|
||||
return;
|
||||
d->findUsages(doc.data(), adjustedCursor, name, replacement, renameCallback, categorize);
|
||||
};
|
||||
requestSymbolInfo(document->filePath(), Range(adjustedCursor).start(), symbolInfoHandler);
|
||||
requestSymbolInfo(cursor.textDocument()->filePath(), Range(adjustedCursor).start(),
|
||||
symbolInfoHandler);
|
||||
}
|
||||
|
||||
void ClangdClient::checkUnused(const Utils::Link &link, Core::SearchResult *search,
|
||||
@@ -1053,9 +1090,8 @@ void ClangdClient::gatherHelpItemForTooltip(const HoverRequest::Response &hoverR
|
||||
QString cleanString = markupString;
|
||||
cleanString.remove('`');
|
||||
const QStringList lines = cleanString.trimmed().split('\n');
|
||||
if (!lines.isEmpty()) {
|
||||
const auto markupFilePath = Utils::FilePath::fromUserInput(
|
||||
lines.last().simplified());
|
||||
for (const QString &line : lines) {
|
||||
const auto markupFilePath = Utils::FilePath::fromUserInput(line.simplified());
|
||||
if (markupFilePath.exists()) {
|
||||
d->setHelpItemForTooltip(hoverResponse.id(),
|
||||
filePath,
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
void openExtraFile(const Utils::FilePath &filePath, const QString &content = {});
|
||||
void closeExtraFile(const Utils::FilePath &filePath);
|
||||
|
||||
void findUsages(TextEditor::TextDocument *document, const QTextCursor &cursor,
|
||||
void findUsages(const CppEditor::CursorInEditor &cursor,
|
||||
const std::optional<QString> &replacement,
|
||||
const std::function<void()> &renameCallback);
|
||||
void checkUnused(const Utils::Link &link, Core::SearchResult *search,
|
||||
|
||||
@@ -319,7 +319,7 @@ void ClangModelManagerSupport::globalRename(const CursorInEditor &cursor,
|
||||
client && client->isFullyIndexed()) {
|
||||
QTC_ASSERT(client->documentOpen(cursor.textDocument()),
|
||||
client->openDocument(cursor.textDocument()));
|
||||
client->findUsages(cursor.textDocument(), cursor.cursor(), replacement, callback);
|
||||
client->findUsages(cursor, replacement, callback);
|
||||
return;
|
||||
}
|
||||
CppModelManager::globalRename(cursor, replacement, callback, CppModelManager::Backend::Builtin);
|
||||
@@ -331,8 +331,7 @@ void ClangModelManagerSupport::findUsages(const CursorInEditor &cursor) const
|
||||
client && client->isFullyIndexed()) {
|
||||
QTC_ASSERT(client->documentOpen(cursor.textDocument()),
|
||||
client->openDocument(cursor.textDocument()));
|
||||
client->findUsages(cursor.textDocument(), cursor.cursor(), {}, {});
|
||||
|
||||
client->findUsages(cursor, {}, {});
|
||||
return;
|
||||
}
|
||||
CppModelManager::findUsages(cursor, CppModelManager::Backend::Builtin);
|
||||
|
||||
@@ -314,7 +314,7 @@ void ClangdTestFindReferences::test()
|
||||
QVERIFY(doc);
|
||||
QTextCursor cursor(doc->document());
|
||||
cursor.setPosition(pos);
|
||||
client()->findUsages(doc, cursor, {}, {});
|
||||
client()->findUsages(CppEditor::CursorInEditor(cursor, doc->filePath(), nullptr, doc), {}, {});
|
||||
QVERIFY(waitForSignalOrTimeout(client(), &ClangdClient::findUsagesDone, timeOutInMs()));
|
||||
|
||||
QCOMPARE(m_actualResults.size(), expectedResults.size());
|
||||
|
||||
Reference in New Issue
Block a user