Clang: Speed up requesting diagnostics

Register the translation unit and request diagnostics from the
clangbackend as soon as the project part is determined. There is no
reason to wait until the parser is finished for the highlighter.

Change-Id: Iebccbf59ebd205389462dcee97363746fb651bb2
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2015-09-15 11:48:25 +02:00
parent 787b386ecc
commit 56f37f78b2
8 changed files with 28 additions and 6 deletions

View File

@@ -58,6 +58,11 @@ static void initializeTextMarks()
Utils::Theme::ClangCodeModel_Error_TextMarkColor);
}
ClangCodeModelPlugin::ClangCodeModelPlugin()
{
qRegisterMetaType<CppTools::ProjectPart::Ptr>();
}
bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
Q_UNUSED(arguments)

View File

@@ -50,6 +50,8 @@ class ClangCodeModelPlugin: public ExtensionSystem::IPlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClangCodeModel.json")
public:
ClangCodeModelPlugin();
bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized();

View File

@@ -99,6 +99,7 @@ void ClangEditorDocumentParser::updateHelper(const BaseEditorDocumentParser::InM
State state_ = state();
state_.projectPart = determineProjectPart(filePath(), configuration(), state_);
setState(state_);
emit projectPartDetermined(state_.projectPart);
// Determine message line arguments
const QStringList options = createOptions(filePath(), state_.projectPart, true);

View File

@@ -50,6 +50,9 @@ public:
QList<SemanticMarker::Range> ifdefedOutBlocks() const;
SemanticMarker::Ptr semanticMarker() const;
signals:
void projectPartDetermined(CppTools::ProjectPart::Ptr projectPart);
private:
void updateHelper(const BaseEditorDocumentParser::InMemoryInfo &info) override;

View File

@@ -88,6 +88,9 @@ ClangEditorDocumentProcessor::ClangEditorDocumentProcessor(
, m_semanticHighlighter(document)
, m_builtinProcessor(document, /*enableSemanticHighlighter=*/ false)
{
connect(m_parser.data(), &ClangEditorDocumentParser::projectPartDetermined,
this, &ClangEditorDocumentProcessor::onParserDeterminedProjectPart);
// Forwarding the semantic info from the builtin processor enables us to provide all
// editor (widget) related features that are not yet implemented by the clang plugin.
connect(&m_builtinProcessor, &CppTools::BuiltinEditorDocumentProcessor::cppDocumentUpdated,
@@ -231,9 +234,10 @@ static bool isProjectPartLoadedOrIsFallback(CppTools::ProjectPart::Ptr projectPa
&& (projectPart->id().isEmpty() || ClangCodeModel::Utils::isProjectPartLoaded(projectPart));
}
void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor()
void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor(
CppTools::ProjectPart::Ptr projectPart)
{
const CppTools::ProjectPart::Ptr projectPart = m_parser->projectPart();
QTC_ASSERT(projectPart, return);
if (isProjectPartLoadedOrIsFallback(projectPart)) {
updateTranslationUnitForEditor(projectPart.data());
@@ -243,6 +247,12 @@ void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor(
}
}
void ClangEditorDocumentProcessor::onParserDeterminedProjectPart(
CppTools::ProjectPart::Ptr projectPart)
{
updateProjectPartAndTranslationUnitForEditor(projectPart);
}
void ClangEditorDocumentProcessor::onParserFinished()
{
if (revision() != m_parserRevision)
@@ -254,8 +264,6 @@ void ClangEditorDocumentProcessor::onParserFinished()
// Run semantic highlighter
m_semanticHighlighter.run();
updateProjectPartAndTranslationUnitForEditor();
}
void ClangEditorDocumentProcessor::updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart)

View File

@@ -85,10 +85,11 @@ public:
static ClangEditorDocumentProcessor *get(const QString &filePath);
private slots:
void onParserDeterminedProjectPart(CppTools::ProjectPart::Ptr projectPart);
void onParserFinished();
private:
void updateProjectPartAndTranslationUnitForEditor();
void updateProjectPartAndTranslationUnitForEditor(CppTools::ProjectPart::Ptr projectPart);
void updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart);
void requestDiagnostics(CppTools::ProjectPart *projectPart);
void requestDiagnostics();

View File

@@ -1037,6 +1037,7 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCodeInGeneratedUiFile(
CppTools::Tests::ProjectOpenerAndCloser projectManager;
const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
QVERIFY(projectInfo.isValid());
QVERIFY(monitorGeneratedUiFile.waitUntilGenerated());
// Open file with ui object
const QString completionFile = testDir.absolutePath("mainwindow.cpp");
@@ -1046,7 +1047,6 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCodeInGeneratedUiFile(
QVERIFY(openSource.succeeded());
// ...and check comletions
QVERIFY(monitorGeneratedUiFile.waitUntilGenerated());
ProposalModel proposal = completionResults(openSource.editor());
QVERIFY(hasItem(proposal, "menuBar"));
QVERIFY(hasItem(proposal, "statusBar"));

View File

@@ -247,4 +247,6 @@ private:
} // namespace CppTools
Q_DECLARE_METATYPE(CppTools::ProjectPart::Ptr)
#endif // CPPPROJECTPART_H