Commit def863ee authored by Fawzi Mohamed's avatar Fawzi Mohamed
Browse files

qmljs: split Unknown in NoLanguage and AnyLanguage



Change-Id: I31276084af5e2f0c5f4ca861f17e29430563bb13
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent 9cee5d3b
......@@ -68,7 +68,7 @@ enum Enum
namespace Language {
enum Enum
{
Unknown = 0,
NoLanguage = 0,
JavaScript = 1,
Json = 2,
Qml = 3,
......@@ -76,7 +76,8 @@ enum Enum
QmlQtQuick2 = 5,
QmlQbs = 6,
QmlProject = 7,
QmlTypeInfo = 8
QmlTypeInfo = 8,
AnyLanguage = 9,
};
}
......
......@@ -97,6 +97,7 @@ bool Document::isQmlLikeLanguage(Language::Enum language)
case Language::QmlQbs:
case Language::QmlProject:
case Language::QmlTypeInfo:
case Language::AnyLanguage:
return true;
default:
return false;
......@@ -112,7 +113,8 @@ bool Document::isFullySupportedLanguage(Language::Enum language)
case Language::QmlQtQuick1:
case Language::QmlQtQuick2:
return true;
case Language::Unknown:
case Language::NoLanguage:
case Language::AnyLanguage:
case Language::QmlQbs:
case Language::QmlProject:
case Language::QmlTypeInfo:
......@@ -131,6 +133,7 @@ bool Document::isQmlLikeOrJsLanguage(Language::Enum language)
case Language::QmlProject:
case Language::QmlTypeInfo:
case Language::JavaScript:
case Language::AnyLanguage:
return true;
default:
return false;
......@@ -157,12 +160,16 @@ QList<Language::Enum> Document::companionLanguages(Language::Enum language)
case Language::QmlQtQuick2:
langs << Language::Qml << Language::JavaScript;
break;
case Language::Unknown:
case Language::AnyLanguage:
langs << Language::JavaScript << Language::Json << Language::QmlProject << Language:: QmlQbs
<< Language::QmlTypeInfo << Language::QmlQtQuick1 << Language::QmlQtQuick2
<< Language::Qml;
break;
case Language::NoLanguage:
return QList<Language::Enum>(); // return at least itself?
}
if (language != Language::AnyLanguage)
langs << Language::AnyLanguage;
return langs;
}
......@@ -531,7 +538,7 @@ void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info)
if (!info.wasFound()) return;
CoreImport cImport;
cImport.importId = path;
cImport.language = Language::Unknown;
cImport.language = Language::AnyLanguage;
QSet<ImportKey> packages;
foreach (const ModuleApiInfo &moduleInfo, info.moduleApis()) {
ImportKey iKey(ImportType::Library, moduleInfo.uri, moduleInfo.version.majorVersion(),
......
......@@ -774,7 +774,7 @@ void ImportDependencies::addExport(const QString &importId, const ImportKey &imp
{
if (!m_coreImports.contains(importId)) {
CoreImport newImport(importId);
newImport.language = Language::Unknown;
newImport.language = Language::AnyLanguage;
newImport.possibleExports.append(Export(importKey, requiredPath, false));
m_coreImports.insert(newImport.importId, newImport);
m_importCache[importKey].append(importId);
......
......@@ -154,7 +154,7 @@ Language::Enum ModelManagerInterface::guessLanguageOfFile(const QString &fileNam
lMapping = defaultLanguageMapping();
const QFileInfo info(fileName);
const QString fileSuffix = info.suffix();
return lMapping.value(fileSuffix, Language::Unknown);
return lMapping.value(fileSuffix, Language::NoLanguage);
}
QStringList ModelManagerInterface::globPatternsForLanguages(const QList<Language::Enum> languages)
......@@ -333,7 +333,7 @@ void ModelManagerInterface::fileChangedOnDisk(const QString &path)
{
QtConcurrent::run(&ModelManagerInterface::parse,
workingCopyInternal(), QStringList() << path,
this, Language::Unknown, true);
this, Language::AnyLanguage, true);
}
void ModelManagerInterface::removeFiles(const QStringList &files)
......@@ -756,7 +756,7 @@ static bool findNewQmlLibraryInPath(const QString &path,
const QString path = QDir::cleanPath(componentFileInfo.absolutePath());
if (! scannedPaths->contains(path)) {
*importedFiles += filesInDirectoryForLanguages(path,
Document::companionLanguages(Language::Unknown));
Document::companionLanguages(Language::AnyLanguage));
scannedPaths->insert(path);
}
}
......@@ -839,7 +839,7 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
const QString fileName = files.at(i);
Language::Enum language = guessLanguageOfFile(fileName);
if (language == Language::Unknown) {
if (language == Language::NoLanguage) {
if (fileName.endsWith(QLatin1String(".qrc")))
modelManager->updateQrcFile(fileName);
continue;
......@@ -1305,7 +1305,7 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
foreach (const QString &path, defaultVCtx.paths)
res.maybeAddPath(path);
switch (res.language) {
case Language::Unknown:
case Language::AnyLanguage:
case Language::Qml:
res.maybeAddPath(info.qtQmlPath);
// fallthrough
......@@ -1328,6 +1328,7 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
}
break;
}
case Language::NoLanguage:
case Language::JavaScript:
case Language::QmlTypeInfo:
case Language::Json:
......@@ -1343,10 +1344,10 @@ ViewerContext ModelManagerInterface::completeVContext(const ViewerContext &vCtx,
case ViewerContext::AddDefaultPaths:
foreach (const QString &path, defaultVCtx.paths)
res.maybeAddPath(path);
if (res.language == Language::Unknown || res.language == Language::Qml
if (res.language == Language::AnyLanguage || res.language == Language::Qml
|| res.language == Language::QmlQtQuick2)
res.maybeAddPath(info.qtImportsPath);
if (res.language == Language::Unknown || res.language == Language::Qml
if (res.language == Language::AnyLanguage || res.language == Language::Qml
|| res.language == Language::QmlQtQuick1)
res.maybeAddPath(info.qtQmlPath);
break;
......@@ -1360,7 +1361,7 @@ ViewerContext ModelManagerInterface::defaultVContext(Language::Enum language,
bool autoComplete) const
{
if (!doc.isNull()) {
if (language == Language::Unknown)
if (language == Language::AnyLanguage)
language = doc->language();
else if (language == Language::Qml &&
(doc->language() == Language::QmlQtQuick1 || doc->language() == Language::QmlQtQuick2))
......
......@@ -56,6 +56,8 @@ ViewerContext::ViewerContext(QStringList selectors, QStringList paths,
*/
bool ViewerContext::languageIsCompatible(Language::Enum l) const
{
if (l == Language::AnyLanguage && language != Language::NoLanguage)
return true;
switch (language) {
case Language::JavaScript:
case Language::Json:
......@@ -70,10 +72,12 @@ bool ViewerContext::languageIsCompatible(Language::Enum l) const
return l == Language::Qml || l == Language::QmlQtQuick1 || l == Language::JavaScript;
case Language::QmlQtQuick2:
return l == Language::Qml || l == Language::QmlQtQuick2 || l == Language::JavaScript;
case Language::Unknown: // ?
case Language::AnyLanguage:
return true;
case Language::NoLanguage:
break;
}
return true;
return false;
}
void ViewerContext::maybeAddPath(const QString &path)
......
......@@ -817,6 +817,10 @@ static void find_helper(QFutureInterface<FindReferences::Usage> &future,
language = oldDoc->language();
else
language = ModelManagerInterface::guessLanguageOfFile(fileName);
if (language == Language::NoLanguage) {
qCDebug(qmljsLog) << "NoLanguage in qmljsfindreferences.cpp find_helper for " << fileName;
language = Language::AnyLanguage;
}
Document::MutablePtr newDoc = snapshot.documentFromSource(
it.value().first, fileName, language);
......
......@@ -161,7 +161,7 @@ void QmlTaskManager::updateMessagesNow(bool updateSemantic)
QFuture<FileErrorMessages> future =
QtConcurrent::run<FileErrorMessages>(
&collectMessages, modelManager->newestSnapshot(), modelManager->projectInfos(),
modelManager->defaultVContext(Language::Unknown), updateSemantic);
modelManager->defaultVContext(Language::AnyLanguage), updateSemantic);
m_messageCollector.setFuture(future);
}
......
......@@ -124,7 +124,7 @@ QmlJSRefactoringFile::QmlJSRefactoringFile(const QString &fileName, const QShare
: RefactoringFile(fileName, data)
{
// the RefactoringFile is invalid if its not for a file with qml or js code
if (ModelManagerInterface::guessLanguageOfFile(fileName) == Language::Unknown)
if (ModelManagerInterface::guessLanguageOfFile(fileName) == Language::NoLanguage)
m_fileName.clear();
}
......
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