Commit 4becd473 authored by Leandro Melo's avatar Leandro Melo Committed by Leandro T. C. Melo

C++ editor: Make semantic info aware of file rename

This also changes the mutex so that the check for reusing
the last semantic info is consistent.

Task-number: QTCREATORBUG-5276

Change-Id: Ia5a2dae25ba3aa40949ac751bcda209d0bcf1f3c
Reviewed-on: http://codereview.qt.nokia.com/1581Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent 9198aa23
......@@ -655,7 +655,11 @@ void CPPEditorWidget::onDocumentUpdated(Document::Ptr doc)
if (doc->editorRevision() != editorRevision())
return;
if (! m_initialized) {
if (! m_initialized ||
(Core::EditorManager::instance()->currentEditor() == editor()
&& (!m_lastSemanticInfo.doc
|| !m_lastSemanticInfo.doc->translationUnit()->ast()
|| m_lastSemanticInfo.doc->fileName() != file()->fileName()))) {
m_initialized = true;
rehighlight(/* force = */ true);
}
......@@ -2149,31 +2153,33 @@ void SemanticHighlighter::run()
SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
{
m_mutex.lock();
const int revision = m_lastSemanticInfo.revision;
m_mutex.unlock();
Snapshot snapshot;
Document::Ptr doc;
QList<Document::DiagnosticMessage> diagnosticMessages;
QList<SemanticInfo::Use> objcKeywords;
SemanticInfo semanticInfo;
semanticInfo.revision = source.revision;
semanticInfo.forced = source.force;
if (! source.force && revision == source.revision) {
m_mutex.lock();
snapshot = m_lastSemanticInfo.snapshot; // ### TODO: use the new snapshot.
doc = m_lastSemanticInfo.doc;
diagnosticMessages = m_lastSemanticInfo.diagnosticMessages;
objcKeywords = m_lastSemanticInfo.objcKeywords;
m_mutex.unlock();
if (! source.force
&& m_lastSemanticInfo.revision == source.revision
&& m_lastSemanticInfo.doc
&& m_lastSemanticInfo.doc->translationUnit()->ast()
&& m_lastSemanticInfo.doc->fileName() == source.fileName) {
semanticInfo.snapshot = m_lastSemanticInfo.snapshot; // ### TODO: use the new snapshot.
semanticInfo.doc = m_lastSemanticInfo.doc;
semanticInfo.diagnosticMessages = m_lastSemanticInfo.diagnosticMessages;
semanticInfo.objcKeywords = m_lastSemanticInfo.objcKeywords;
}
m_mutex.unlock();
if (! doc) {
snapshot = source.snapshot;
const QByteArray preprocessedCode = snapshot.preprocessedCode(source.code, source.fileName);
doc = snapshot.documentFromSource(preprocessedCode, source.fileName);
if (! semanticInfo.doc) {
semanticInfo.snapshot = source.snapshot;
if (source.snapshot.contains(source.fileName)) {
const QByteArray &preprocessedCode =
source.snapshot.preprocessedCode(source.code, source.fileName);
Document::Ptr doc =
source.snapshot.documentFromSource(preprocessedCode, source.fileName);
doc->control()->setTopLevelDeclarationProcessor(this);
doc->check();
semanticInfo.doc = doc;
#if 0
if (TranslationUnit *unit = doc->translationUnit()) {
......@@ -2182,25 +2188,20 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
}
#endif
}
}
TranslationUnit *translationUnit = doc->translationUnit();
AST *ast = translationUnit->ast();
if (semanticInfo.doc) {
TranslationUnit *translationUnit = semanticInfo.doc->translationUnit();
AST * ast = translationUnit->ast();
FunctionDefinitionUnderCursor functionDefinitionUnderCursor(translationUnit);
FunctionDefinitionUnderCursor functionDefinitionUnderCursor(semanticInfo.doc->translationUnit());
DeclarationAST *currentFunctionDefinition = functionDefinitionUnderCursor(ast, source.line, source.column);
const LocalSymbols useTable(doc, currentFunctionDefinition);
SemanticInfo semanticInfo;
semanticInfo.revision = source.revision;
semanticInfo.snapshot = snapshot;
semanticInfo.doc = doc;
const LocalSymbols useTable(semanticInfo.doc, currentFunctionDefinition);
semanticInfo.localUses = useTable.uses;
semanticInfo.hasQ = useTable.hasQ;
semanticInfo.hasD = useTable.hasD;
semanticInfo.forced = source.force;
semanticInfo.diagnosticMessages = diagnosticMessages;
semanticInfo.objcKeywords = objcKeywords;
}
return semanticInfo;
}
......
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