Commit 241d71a2 authored by Thomas Schöps's avatar Thomas Schöps

clang: Fix a case of concurrent access to KTextEditor

parent 9c4b8e75
......@@ -25,6 +25,7 @@
#include "util/clangtypes.h"
#include "util/clangdebug.h"
#include "util/clangutils.h"
#include <language/duchain/duchainlock.h>
#include <language/codegen/documentchangeset.h>
......@@ -66,7 +67,7 @@ inline QString prettyDiagnosticSpelling(const QString& str)
return ret;
}
ClangFixits fixitsForDiagnostic(CXDiagnostic diagnostic)
ClangFixits fixitsForDiagnostic(CXDiagnostic diagnostic, CXTranslationUnit unit)
{
ClangFixits fixits;
auto numFixits = clang_getDiagnosticNumFixIts(diagnostic);
......@@ -74,12 +75,8 @@ ClangFixits fixitsForDiagnostic(CXDiagnostic diagnostic)
for (uint i = 0; i < numFixits; ++i) {
CXSourceRange range;
const QString replacementText = ClangString(clang_getDiagnosticFixIt(diagnostic, i, &range)).toString();
const auto docRange = ClangRange(range).toDocumentRange();
auto doc = KDevelop::ICore::self()->documentController()->documentForUrl(docRange.document.toUrl());
const QString original = doc ? doc->text(docRange) : QString{};
fixits << ClangFixit{replacementText, docRange, QString(), original};
QByteArray original = ClangUtils::getRawContents(unit, range);
fixits << ClangFixit{replacementText, ClangRange(range).toDocumentRange(), QString(), QString::fromLocal8Bit(original)};
}
return fixits;
}
......@@ -168,7 +165,7 @@ ClangProblem::ClangProblem(CXDiagnostic diagnostic, CXTranslationUnit unit)
}
}
setFixits(fixitsForDiagnostic(diagnostic));
setFixits(fixitsForDiagnostic(diagnostic, unit));
setFinalLocation(docRange);
setSource(IProblem::SemanticAnalysis);
......
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