Commit 56f37f78 authored by Nikolai Kosjar's avatar Nikolai Kosjar

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: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 787b386e
...@@ -58,6 +58,11 @@ static void initializeTextMarks() ...@@ -58,6 +58,11 @@ static void initializeTextMarks()
Utils::Theme::ClangCodeModel_Error_TextMarkColor); Utils::Theme::ClangCodeModel_Error_TextMarkColor);
} }
ClangCodeModelPlugin::ClangCodeModelPlugin()
{
qRegisterMetaType<CppTools::ProjectPart::Ptr>();
}
bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *errorMessage) bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{ {
Q_UNUSED(arguments) Q_UNUSED(arguments)
......
...@@ -50,6 +50,8 @@ class ClangCodeModelPlugin: public ExtensionSystem::IPlugin ...@@ -50,6 +50,8 @@ class ClangCodeModelPlugin: public ExtensionSystem::IPlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClangCodeModel.json") Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClangCodeModel.json")
public: public:
ClangCodeModelPlugin();
bool initialize(const QStringList &arguments, QString *errorMessage); bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized(); void extensionsInitialized();
......
...@@ -99,6 +99,7 @@ void ClangEditorDocumentParser::updateHelper(const BaseEditorDocumentParser::InM ...@@ -99,6 +99,7 @@ void ClangEditorDocumentParser::updateHelper(const BaseEditorDocumentParser::InM
State state_ = state(); State state_ = state();
state_.projectPart = determineProjectPart(filePath(), configuration(), state_); state_.projectPart = determineProjectPart(filePath(), configuration(), state_);
setState(state_); setState(state_);
emit projectPartDetermined(state_.projectPart);
// Determine message line arguments // Determine message line arguments
const QStringList options = createOptions(filePath(), state_.projectPart, true); const QStringList options = createOptions(filePath(), state_.projectPart, true);
......
...@@ -50,6 +50,9 @@ public: ...@@ -50,6 +50,9 @@ public:
QList<SemanticMarker::Range> ifdefedOutBlocks() const; QList<SemanticMarker::Range> ifdefedOutBlocks() const;
SemanticMarker::Ptr semanticMarker() const; SemanticMarker::Ptr semanticMarker() const;
signals:
void projectPartDetermined(CppTools::ProjectPart::Ptr projectPart);
private: private:
void updateHelper(const BaseEditorDocumentParser::InMemoryInfo &info) override; void updateHelper(const BaseEditorDocumentParser::InMemoryInfo &info) override;
......
...@@ -88,6 +88,9 @@ ClangEditorDocumentProcessor::ClangEditorDocumentProcessor( ...@@ -88,6 +88,9 @@ ClangEditorDocumentProcessor::ClangEditorDocumentProcessor(
, m_semanticHighlighter(document) , m_semanticHighlighter(document)
, m_builtinProcessor(document, /*enableSemanticHighlighter=*/ false) , 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 // 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. // editor (widget) related features that are not yet implemented by the clang plugin.
connect(&m_builtinProcessor, &CppTools::BuiltinEditorDocumentProcessor::cppDocumentUpdated, connect(&m_builtinProcessor, &CppTools::BuiltinEditorDocumentProcessor::cppDocumentUpdated,
...@@ -231,9 +234,10 @@ static bool isProjectPartLoadedOrIsFallback(CppTools::ProjectPart::Ptr projectPa ...@@ -231,9 +234,10 @@ static bool isProjectPartLoadedOrIsFallback(CppTools::ProjectPart::Ptr projectPa
&& (projectPart->id().isEmpty() || ClangCodeModel::Utils::isProjectPartLoaded(projectPart)); && (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)) { if (isProjectPartLoadedOrIsFallback(projectPart)) {
updateTranslationUnitForEditor(projectPart.data()); updateTranslationUnitForEditor(projectPart.data());
...@@ -243,6 +247,12 @@ void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor( ...@@ -243,6 +247,12 @@ void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor(
} }
} }
void ClangEditorDocumentProcessor::onParserDeterminedProjectPart(
CppTools::ProjectPart::Ptr projectPart)
{
updateProjectPartAndTranslationUnitForEditor(projectPart);
}
void ClangEditorDocumentProcessor::onParserFinished() void ClangEditorDocumentProcessor::onParserFinished()
{ {
if (revision() != m_parserRevision) if (revision() != m_parserRevision)
...@@ -254,8 +264,6 @@ void ClangEditorDocumentProcessor::onParserFinished() ...@@ -254,8 +264,6 @@ void ClangEditorDocumentProcessor::onParserFinished()
// Run semantic highlighter // Run semantic highlighter
m_semanticHighlighter.run(); m_semanticHighlighter.run();
updateProjectPartAndTranslationUnitForEditor();
} }
void ClangEditorDocumentProcessor::updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart) void ClangEditorDocumentProcessor::updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart)
......
...@@ -85,10 +85,11 @@ public: ...@@ -85,10 +85,11 @@ public:
static ClangEditorDocumentProcessor *get(const QString &filePath); static ClangEditorDocumentProcessor *get(const QString &filePath);
private slots: private slots:
void onParserDeterminedProjectPart(CppTools::ProjectPart::Ptr projectPart);
void onParserFinished(); void onParserFinished();
private: private:
void updateProjectPartAndTranslationUnitForEditor(); void updateProjectPartAndTranslationUnitForEditor(CppTools::ProjectPart::Ptr projectPart);
void updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart); void updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart);
void requestDiagnostics(CppTools::ProjectPart *projectPart); void requestDiagnostics(CppTools::ProjectPart *projectPart);
void requestDiagnostics(); void requestDiagnostics();
......
...@@ -1037,6 +1037,7 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCodeInGeneratedUiFile( ...@@ -1037,6 +1037,7 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCodeInGeneratedUiFile(
CppTools::Tests::ProjectOpenerAndCloser projectManager; CppTools::Tests::ProjectOpenerAndCloser projectManager;
const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true); const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
QVERIFY(projectInfo.isValid()); QVERIFY(projectInfo.isValid());
QVERIFY(monitorGeneratedUiFile.waitUntilGenerated());
// Open file with ui object // Open file with ui object
const QString completionFile = testDir.absolutePath("mainwindow.cpp"); const QString completionFile = testDir.absolutePath("mainwindow.cpp");
...@@ -1046,7 +1047,6 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCodeInGeneratedUiFile( ...@@ -1046,7 +1047,6 @@ void ClangCodeCompletionTest::testCompleteProjectDependingCodeInGeneratedUiFile(
QVERIFY(openSource.succeeded()); QVERIFY(openSource.succeeded());
// ...and check comletions // ...and check comletions
QVERIFY(monitorGeneratedUiFile.waitUntilGenerated());
ProposalModel proposal = completionResults(openSource.editor()); ProposalModel proposal = completionResults(openSource.editor());
QVERIFY(hasItem(proposal, "menuBar")); QVERIFY(hasItem(proposal, "menuBar"));
QVERIFY(hasItem(proposal, "statusBar")); QVERIFY(hasItem(proposal, "statusBar"));
......
...@@ -247,4 +247,6 @@ private: ...@@ -247,4 +247,6 @@ private:
} // namespace CppTools } // namespace CppTools
Q_DECLARE_METATYPE(CppTools::ProjectPart::Ptr)
#endif // CPPPROJECTPART_H #endif // CPPPROJECTPART_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment