Commit 2a0f901e authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Use the document in the snapshot when available.

parent 3141edd2
...@@ -42,10 +42,10 @@ ...@@ -42,10 +42,10 @@
using namespace CPlusPlus; using namespace CPlusPlus;
CheckUndefinedSymbols::CheckUndefinedSymbols(Document::Ptr doc, const Snapshot &snapshot) CheckUndefinedSymbols::CheckUndefinedSymbols(TranslationUnit *unit, const LookupContext &context)
: ASTVisitor(doc->translationUnit()), _context(doc, snapshot) : ASTVisitor(unit), _context(context)
{ {
_fileName = doc->fileName(); _fileName = context.thisDocument()->fileName();
} }
CheckUndefinedSymbols::~CheckUndefinedSymbols() CheckUndefinedSymbols::~CheckUndefinedSymbols()
......
...@@ -39,7 +39,7 @@ namespace CPlusPlus { ...@@ -39,7 +39,7 @@ namespace CPlusPlus {
class CPLUSPLUS_EXPORT CheckUndefinedSymbols: protected ASTVisitor class CPLUSPLUS_EXPORT CheckUndefinedSymbols: protected ASTVisitor
{ {
public: public:
CheckUndefinedSymbols(Document::Ptr doc, const Snapshot &snapshot); CheckUndefinedSymbols(TranslationUnit *unit, const LookupContext &context);
virtual ~CheckUndefinedSymbols(); virtual ~CheckUndefinedSymbols();
QList<Document::DiagnosticMessage> operator()(AST *ast); QList<Document::DiagnosticMessage> operator()(AST *ast);
......
...@@ -1997,15 +1997,24 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source) ...@@ -1997,15 +1997,24 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
} }
if (! doc) { if (! doc) {
const QByteArray preprocessedCode = source.snapshot.preprocessedCode(source.code, source.fileName);
snapshot = source.snapshot; snapshot = source.snapshot;
doc = source.snapshot.documentFromSource(preprocessedCode, source.fileName); const QByteArray preprocessedCode = snapshot.preprocessedCode(source.code, source.fileName);
doc = snapshot.documentFromSource(preprocessedCode, source.fileName);
doc->check(); doc->check();
// ### check undefined symbols. Document::Ptr documentInSnapshot = snapshot.document(source.fileName);
CheckUndefinedSymbols checkUndefinedSymbols(doc, snapshot); if (! documentInSnapshot) {
diagnosticMessages = checkUndefinedSymbols(doc->translationUnit()->ast()); // use the newly parsed document.
documentInSnapshot = doc;
}
LookupContext context(doc, snapshot);
if (TranslationUnit *unit = doc->translationUnit()) {
CheckUndefinedSymbols checkUndefinedSymbols(unit, context);
diagnosticMessages = checkUndefinedSymbols(unit->ast());
}
} }
TranslationUnit *translationUnit = doc->translationUnit(); TranslationUnit *translationUnit = doc->translationUnit();
......
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