From cfe29cc936cf951e16a67295c16e2edd561a187b Mon Sep 17 00:00:00 2001
From: Fawzi Mohamed <fawzi.mohamed@digia.com>
Date: Tue, 2 Dec 2014 13:24:25 +0100
Subject: [PATCH] qmljs: fix projectInfoForPath and fileToPath mapping

m_fileToPath was not always updated correctly which lead
projectInfoForPath to return a wrong/invalid project info,
messing up the paths used by the code model.

Change-Id: If5e144f1ef2c7353b9077deb1b9c9aa9d1708651
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@theqtcompany.com>
---
 src/libs/qmljs/qmljsmodelmanagerinterface.cpp | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
index dd7491eefaa..64b2a4331d0 100644
--- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
+++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp
@@ -563,9 +563,9 @@ void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectE
         if (!snapshot.document(file))
             newFiles += file;
     }
-    updateSourceFiles(newFiles, false);
-    foreach (const QString &newFile, deletedFiles)
+    foreach (const QString &newFile, newFiles)
         m_fileToProject.insert(newFile, p);
+    updateSourceFiles(newFiles, false);
 
     // update qrc cache
     foreach (const QString &newQrc, pinfo.allResourceFiles)
@@ -608,6 +608,10 @@ ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(QSt
     {
         QMutexLocker locker(&m_mutex);
         projects = m_fileToProject.values(path);
+        if (projects.isEmpty()) {
+            QFileInfo fInfo(path);
+            projects = m_fileToProject.values(fInfo.canonicalFilePath());
+        }
     }
     QList<ProjectInfo> infos;
     foreach (ProjectExplorer::Project *project, projects) {
@@ -616,6 +620,7 @@ ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfoForPath(QSt
             infos.append(info);
     }
     std::sort(infos.begin(), infos.end(), &pInfoLessThanImports);
+    infos.append(m_defaultProjectInfo);
 
     ProjectInfo res;
     foreach (const ProjectInfo &pInfo, infos) {
@@ -1321,7 +1326,7 @@ ModelManagerInterface::CppDataHash ModelManagerInterface::cppData() const
 
 LibraryInfo ModelManagerInterface::builtins(const Document::Ptr &doc) const
 {
-    ProjectInfo info = projectInfoForPath(doc->path());
+    ProjectInfo info = projectInfoForPath(doc->fileName());
     if (!info.isValid())
         return LibraryInfo();
     if (!info.qtQmlPath.isEmpty())
@@ -1343,7 +1348,7 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
         res.language = doc->language();
     ProjectInfo info;
     if (!doc.isNull())
-        info = projectInfoForPath(doc->path());
+        info = projectInfoForPath(doc->fileName());
     ViewerContext defaultVCtx = defaultVContext(res.language, Document::Ptr(0), false);
     ProjectInfo defaultInfo = defaultProjectInfo();
     if (info.qtImportsPath.isEmpty())
-- 
GitLab