forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/7.0'
Conflicts: src/plugins/mcusupport/mcupackage.cpp src/plugins/mcusupport/mcusupportoptions.cpp src/plugins/mcusupport/mcusupportoptions.h src/plugins/mcusupport/mcusupportoptionspage.cpp src/plugins/mcusupport/mcusupportplugin.cpp src/plugins/mcusupport/mcusupportsdk.cpp Change-Id: Ib423e9f23877176f01b188104b0a179ed32c4770
This commit is contained in:
@@ -1402,7 +1402,10 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir)
|
||||
setClientCapabilities(caps);
|
||||
setLocatorsEnabled(false);
|
||||
setAutoRequestCodeActions(false); // clangd sends code actions inside diagnostics
|
||||
setProgressTitleForToken(indexingToken(), tr("Parsing C/C++ Files (clangd)"));
|
||||
if (project) {
|
||||
setProgressTitleForToken(indexingToken(),
|
||||
tr("Indexing %1 with clangd").arg(project->displayName()));
|
||||
}
|
||||
setCurrentProject(project);
|
||||
setDocumentChangeUpdateThreshold(d->settings.documentUpdateThreshold);
|
||||
|
||||
@@ -2958,9 +2961,10 @@ void ClangdClient::Private::handleSemanticTokens(TextDocument *doc,
|
||||
int version, bool force)
|
||||
{
|
||||
SubtaskTimer t(highlightingTimer);
|
||||
qCDebug(clangdLog) << "handling LSP tokens" << doc->filePath() << tokens.size();
|
||||
qCInfo(clangdLogHighlight) << "handling LSP tokens" << doc->filePath()
|
||||
<< version << tokens.size();
|
||||
if (version != q->documentVersion(doc->filePath())) {
|
||||
qCDebug(clangdLogHighlight) << "LSP tokens outdated; aborting highlighting procedure"
|
||||
qCInfo(clangdLogHighlight) << "LSP tokens outdated; aborting highlighting procedure"
|
||||
<< version << q->documentVersion(doc->filePath());
|
||||
return;
|
||||
}
|
||||
@@ -2968,7 +2972,7 @@ void ClangdClient::Private::handleSemanticTokens(TextDocument *doc,
|
||||
const auto previous = previousTokens.find(doc);
|
||||
if (previous != previousTokens.end()) {
|
||||
if (!force && previous->first == tokens && previous->second == version) {
|
||||
qCDebug(clangdLogHighlight) << "tokens and version same as last time; nothing to do";
|
||||
qCInfo(clangdLogHighlight) << "tokens and version same as last time; nothing to do";
|
||||
return;
|
||||
}
|
||||
previous->first = tokens;
|
||||
@@ -2985,7 +2989,7 @@ void ClangdClient::Private::handleSemanticTokens(TextDocument *doc,
|
||||
if (!q->documentOpen(doc))
|
||||
return;
|
||||
if (version != q->documentVersion(doc->filePath())) {
|
||||
qCDebug(clangdLogHighlight) << "AST not up to date; aborting highlighting procedure"
|
||||
qCInfo(clangdLogHighlight) << "AST not up to date; aborting highlighting procedure"
|
||||
<< version << q->documentVersion(doc->filePath());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <coreplugin/messagemanager.h>
|
||||
|
||||
#include <cppeditor/cppcodemodelsettings.h>
|
||||
#include <cppeditor/cppeditorconstants.h>
|
||||
#include <cppeditor/cppfollowsymbolundercursor.h>
|
||||
#include <cppeditor/cppmodelmanager.h>
|
||||
#include <cppeditor/cppprojectfile.h>
|
||||
@@ -58,6 +59,7 @@
|
||||
#include <projectexplorer/buildsystem.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
@@ -85,21 +87,20 @@ static CppEditor::CppModelManager *cppModelManager()
|
||||
return CppEditor::CppModelManager::instance();
|
||||
}
|
||||
|
||||
static const QList<TextEditor::BaseTextEditor *> allCppEditors()
|
||||
static ProjectExplorer::Project *fallbackProject()
|
||||
{
|
||||
QList<TextEditor::BaseTextEditor *> cppEditors;
|
||||
for (const Core::DocumentModel::Entry * const entry : Core::DocumentModel::entries()) {
|
||||
const auto textDocument = qobject_cast<TextEditor::TextDocument *>(entry->document);
|
||||
if (!textDocument)
|
||||
continue;
|
||||
if (const auto cppEditor = qobject_cast<TextEditor::BaseTextEditor *>(Utils::findOrDefault(
|
||||
Core::DocumentModel::editorsForDocument(textDocument), [](Core::IEditor *editor) {
|
||||
return CppEditor::CppModelManager::isCppEditor(editor);
|
||||
}))) {
|
||||
cppEditors << cppEditor;
|
||||
}
|
||||
}
|
||||
return cppEditors;
|
||||
if (ProjectExplorer::Project * const p = ProjectExplorer::ProjectTree::currentProject())
|
||||
return p;
|
||||
return ProjectExplorer::SessionManager::startupProject();
|
||||
}
|
||||
|
||||
static const QList<TextEditor::TextDocument *> allCppDocuments()
|
||||
{
|
||||
const auto isCppDocument = Utils::equal(&Core::IDocument::id,
|
||||
Utils::Id(CppEditor::Constants::CPPEDITOR_ID));
|
||||
const QList<Core::IDocument *> documents
|
||||
= Utils::filtered(Core::DocumentModel::openedDocuments(), isCppDocument);
|
||||
return Utils::qobject_container_cast<TextEditor::TextDocument *>(documents);
|
||||
}
|
||||
|
||||
ClangModelManagerSupport::ClangModelManagerSupport()
|
||||
@@ -149,10 +150,7 @@ ClangModelManagerSupport::ClangModelManagerSupport()
|
||||
connect(sessionManager, &ProjectExplorer::SessionManager::aboutToRemoveProject,
|
||||
this, &ClangModelManagerSupport::onAboutToRemoveProject);
|
||||
connect(sessionManager, &ProjectExplorer::SessionManager::projectRemoved,
|
||||
this, [this] {
|
||||
if (ClangdClient * const fallbackClient = clientForProject(nullptr))
|
||||
claimNonProjectSources(fallbackClient);
|
||||
});
|
||||
this, [this] { claimNonProjectSources(clientForProject(fallbackProject())); });
|
||||
|
||||
CppEditor::ClangdSettings::setDefaultClangdPath(Core::ICore::clangdExecutable(CLANG_BINDIR));
|
||||
connect(&CppEditor::ClangdSettings::instance(), &CppEditor::ClangdSettings::changed,
|
||||
@@ -369,13 +367,15 @@ void ClangModelManagerSupport::updateLanguageClient(
|
||||
|
||||
// Acquaint the client with all open C++ documents for this project.
|
||||
bool hasDocuments = false;
|
||||
for (TextEditor::BaseTextEditor * const editor : allCppEditors()) {
|
||||
const Utils::FilePath filePath = editor->textDocument()->filePath();
|
||||
if (!project->isKnownFile(filePath))
|
||||
continue;
|
||||
LanguageClientManager::openDocumentWithClient(editor->textDocument(), client);
|
||||
ClangEditorDocumentProcessor::clearTextMarks(filePath);
|
||||
hasDocuments = true;
|
||||
for (TextEditor::TextDocument * const doc : allCppDocuments()) {
|
||||
const Client * const currentClient = LanguageClientManager::clientForDocument(doc);
|
||||
if (!currentClient || !currentClient->project()
|
||||
|| currentClient->state() != Client::Initialized
|
||||
|| project->isKnownFile(doc->filePath())) {
|
||||
LanguageClientManager::openDocumentWithClient(doc, client);
|
||||
ClangEditorDocumentProcessor::clearTextMarks(doc->filePath());
|
||||
hasDocuments = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (client->state() == Client::Initialized)
|
||||
@@ -444,7 +444,7 @@ ClangdClient *ClangModelManagerSupport::clientForProject(
|
||||
|
||||
ClangdClient *ClangModelManagerSupport::clientForFile(const Utils::FilePath &file) const
|
||||
{
|
||||
return clientForProject(ProjectExplorer::SessionManager::projectForFile(file));
|
||||
return qobject_cast<ClangdClient *>(LanguageClientManager::clientForFilePath(file));
|
||||
}
|
||||
|
||||
ClangdClient *ClangModelManagerSupport::createClient(ProjectExplorer::Project *project,
|
||||
@@ -455,15 +455,18 @@ ClangdClient *ClangModelManagerSupport::createClient(ProjectExplorer::Project *p
|
||||
return client;
|
||||
}
|
||||
|
||||
void ClangModelManagerSupport::claimNonProjectSources(ClangdClient *fallbackClient)
|
||||
void ClangModelManagerSupport::claimNonProjectSources(ClangdClient *client)
|
||||
{
|
||||
for (TextEditor::BaseTextEditor * const editor : allCppEditors()) {
|
||||
if (ProjectExplorer::SessionManager::projectForFile(editor->textDocument()->filePath()))
|
||||
if (!client)
|
||||
return;
|
||||
for (TextEditor::TextDocument * const doc : allCppDocuments()) {
|
||||
if (Client * const currentClient = LanguageClientManager::clientForDocument(doc);
|
||||
currentClient && currentClient->state() == Client::Initialized
|
||||
&& (currentClient == client || currentClient->project())) {
|
||||
continue;
|
||||
if (!fallbackClient->documentOpen(editor->textDocument())) {
|
||||
ClangEditorDocumentProcessor::clearTextMarks(editor->textDocument()->filePath());
|
||||
fallbackClient->openDocument(editor->textDocument());
|
||||
}
|
||||
ClangEditorDocumentProcessor::clearTextMarks(doc->filePath());
|
||||
client->openDocument(doc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -563,8 +566,10 @@ void ClangModelManagerSupport::onEditorOpened(Core::IEditor *editor)
|
||||
|
||||
// TODO: Ensure that not fully loaded documents are updated?
|
||||
|
||||
ProjectExplorer::Project * const project
|
||||
ProjectExplorer::Project * project
|
||||
= ProjectExplorer::SessionManager::projectForFile(document->filePath());
|
||||
if (!project)
|
||||
project = fallbackProject();
|
||||
if (ClangdClient * const client = clientForProject(project))
|
||||
LanguageClientManager::openDocumentWithClient(textDocument, client);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ private:
|
||||
void updateLanguageClient(ProjectExplorer::Project *project,
|
||||
const CppEditor::ProjectInfo::ConstPtr &projectInfo);
|
||||
ClangdClient *createClient(ProjectExplorer::Project *project, const Utils::FilePath &jsonDbDir);
|
||||
void claimNonProjectSources(ClangdClient *fallbackClient);
|
||||
void claimNonProjectSources(ClangdClient *client);
|
||||
void watchForExternalChanges();
|
||||
void watchForInternalChanges();
|
||||
|
||||
|
||||
@@ -35,10 +35,12 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <cppeditor/cppcodemodelsettings.h>
|
||||
#include <cppeditor/cpptoolsreuse.h>
|
||||
#include <cppeditor/cpptoolstestcase.h>
|
||||
#include <cppeditor/modelmanagertesthelper.h>
|
||||
#include <cppeditor/projectinfo.h>
|
||||
#include <languageclient/languageclientmanager.h>
|
||||
#include <texteditor/codeassist/assistproposalitem.h>
|
||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
@@ -514,6 +516,13 @@ namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
namespace Tests {
|
||||
|
||||
void ClangCodeCompletionTest::initTestCase()
|
||||
{
|
||||
CppEditor::ClangdSettings::setUseClangd(false);
|
||||
for (LanguageClient::Client * const c : LanguageClient::LanguageClientManager::clients())
|
||||
LanguageClient::LanguageClientManager::shutdownClient(c);
|
||||
}
|
||||
|
||||
void ClangCodeCompletionTest::testCompleteDoxygenKeywords()
|
||||
{
|
||||
ProjectLessCompletionTest t("doxygenKeywordsCompletion.cpp");
|
||||
|
||||
@@ -38,6 +38,8 @@ class ClangCodeCompletionTest : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
|
||||
void testCompleteDoxygenKeywords();
|
||||
void testCompletePreprocessorKeywords();
|
||||
void testCompleteIncludeDirective();
|
||||
|
||||
@@ -2036,7 +2036,7 @@ void ClangdTestExternalChanges::test()
|
||||
QVERIFY(waitForSignalOrTimeout(ClangModelManagerSupport::instance(),
|
||||
&ClangModelManagerSupport::createdClient, timeOutInMs()));
|
||||
ClangdClient * const newClient = ClangModelManagerSupport::instance()
|
||||
->clientForFile(filePath("main.cpp"));
|
||||
->clientForProject(project());
|
||||
QVERIFY(newClient);
|
||||
QVERIFY(newClient != oldClient);
|
||||
newClient->enableTesting();
|
||||
|
||||
Reference in New Issue
Block a user