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) ...@@ -655,7 +655,11 @@ void CPPEditorWidget::onDocumentUpdated(Document::Ptr doc)
if (doc->editorRevision() != editorRevision()) if (doc->editorRevision() != editorRevision())
return; 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; m_initialized = true;
rehighlight(/* force = */ true); rehighlight(/* force = */ true);
} }
...@@ -2149,58 +2153,55 @@ void SemanticHighlighter::run() ...@@ -2149,58 +2153,55 @@ void SemanticHighlighter::run()
SemanticInfo SemanticHighlighter::semanticInfo(const Source &source) SemanticInfo SemanticHighlighter::semanticInfo(const Source &source)
{ {
m_mutex.lock(); SemanticInfo semanticInfo;
const int revision = m_lastSemanticInfo.revision; semanticInfo.revision = source.revision;
m_mutex.unlock(); semanticInfo.forced = source.force;
Snapshot snapshot;
Document::Ptr doc;
QList<Document::DiagnosticMessage> diagnosticMessages;
QList<SemanticInfo::Use> objcKeywords;
if (! source.force && revision == source.revision) { m_mutex.lock();
m_mutex.lock(); if (! source.force
snapshot = m_lastSemanticInfo.snapshot; // ### TODO: use the new snapshot. && m_lastSemanticInfo.revision == source.revision
doc = m_lastSemanticInfo.doc; && m_lastSemanticInfo.doc
diagnosticMessages = m_lastSemanticInfo.diagnosticMessages; && m_lastSemanticInfo.doc->translationUnit()->ast()
objcKeywords = m_lastSemanticInfo.objcKeywords; && m_lastSemanticInfo.doc->fileName() == source.fileName) {
m_mutex.unlock(); 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) { if (! semanticInfo.doc) {
snapshot = source.snapshot; semanticInfo.snapshot = source.snapshot;
const QByteArray preprocessedCode = snapshot.preprocessedCode(source.code, source.fileName); if (source.snapshot.contains(source.fileName)) {
const QByteArray &preprocessedCode =
doc = snapshot.documentFromSource(preprocessedCode, source.fileName); source.snapshot.preprocessedCode(source.code, source.fileName);
doc->control()->setTopLevelDeclarationProcessor(this); Document::Ptr doc =
doc->check(); source.snapshot.documentFromSource(preprocessedCode, source.fileName);
doc->control()->setTopLevelDeclarationProcessor(this);
doc->check();
semanticInfo.doc = doc;
#if 0 #if 0
if (TranslationUnit *unit = doc->translationUnit()) { if (TranslationUnit *unit = doc->translationUnit()) {
FindObjCKeywords findObjCKeywords(unit); // ### remove me FindObjCKeywords findObjCKeywords(unit); // ### remove me
objcKeywords = findObjCKeywords(); objcKeywords = findObjCKeywords();
} }
#endif #endif
}
} }
TranslationUnit *translationUnit = doc->translationUnit(); if (semanticInfo.doc) {
AST *ast = translationUnit->ast(); TranslationUnit *translationUnit = semanticInfo.doc->translationUnit();
AST * ast = translationUnit->ast();
FunctionDefinitionUnderCursor functionDefinitionUnderCursor(translationUnit);
DeclarationAST *currentFunctionDefinition = functionDefinitionUnderCursor(ast, source.line, source.column);
const LocalSymbols useTable(doc, currentFunctionDefinition); FunctionDefinitionUnderCursor functionDefinitionUnderCursor(semanticInfo.doc->translationUnit());
DeclarationAST *currentFunctionDefinition = functionDefinitionUnderCursor(ast, source.line, source.column);
SemanticInfo semanticInfo; const LocalSymbols useTable(semanticInfo.doc, currentFunctionDefinition);
semanticInfo.revision = source.revision; semanticInfo.localUses = useTable.uses;
semanticInfo.snapshot = snapshot; semanticInfo.hasQ = useTable.hasQ;
semanticInfo.doc = doc; semanticInfo.hasD = useTable.hasD;
semanticInfo.localUses = useTable.uses; }
semanticInfo.hasQ = useTable.hasQ;
semanticInfo.hasD = useTable.hasD;
semanticInfo.forced = source.force;
semanticInfo.diagnosticMessages = diagnosticMessages;
semanticInfo.objcKeywords = objcKeywords;
return semanticInfo; 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