From 25a7f30ffc8fcfc75040949e95d64e866653a10e Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 6 Oct 2021 13:27:23 +0200 Subject: [PATCH] ClangCodeModel: Do not hold highlighters by value in ClangdClient Semantic highlighter objects are owned by their respective documents, so we can run into destruction issues when keeping them by value. Fixes: QTCREATORBUG-26364 Change-Id: Idc128d685ccdd25989dd9389d352453ccc935fa9 Reviewed-by: Eike Ziller --- src/plugins/clangcodemodel/clangdclient.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 8ba51f2fba0..fb3efa95ecc 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -77,6 +77,7 @@ #include #include +#include using namespace CPlusPlus; using namespace Core; @@ -934,7 +935,10 @@ public: Utils::optional switchDeclDefData; Utils::optional localRefsData; Utils::optional versionNumber; - std::unordered_map highlighters; + + // The highlighters are owned by their respective documents. + std::unordered_map highlighters; + VersionedDataCache astCache; VersionedDataCache externalAstCache; TaskTimer highlightingTimer{"highlighting"}; @@ -2400,12 +2404,13 @@ void ClangdClient::Private::handleSemanticTokens(TextDocument *doc, auto it = highlighters.find(doc); if (it == highlighters.end()) { - it = highlighters.emplace(doc, doc).first; + it = highlighters.insert(std::make_pair(doc, new CppEditor::SemanticHighlighter(doc))) + .first; } else { - it->second.updateFormatMapFromFontSettings(); + it->second->updateFormatMapFromFontSettings(); } - it->second.setHighlightingRunner(runner); - it->second.run(); + it->second->setHighlightingRunner(runner); + it->second->run(); }; getAndHandleAst(doc, astHandler, AstCallbackMode::SyncIfPossible); }