Generic highlighter: Try mime type aliases when looking for definitions

For example the yaml highlighting file declares text/yaml as the
supported mime type, but that is not the canonical name, which is
application/x-yaml.

Change-Id: If9e3f5e31bc5593a82cbbdac916ef41b0d23de7c
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2022-09-20 13:39:36 +02:00
parent 49190e989e
commit ccfd472a8c

View File

@@ -119,8 +119,15 @@ Highlighter::Definitions Highlighter::definitionsForDocument(const TextDocument
}
if (definitions.isEmpty()) {
const MimeType &mimeType = Utils::mimeTypeForName(document->mimeType());
if (mimeType.isValid())
definitions = definitionsForMimeType(mimeType.name());
if (mimeType.isValid()) {
// highlight definitions might not use the canonical name but an alias
const QStringList names = QStringList(mimeType.name()) + mimeType.aliases();
for (const QString &name : names) {
definitions = definitionsForMimeType(name);
if (!definitions.isEmpty())
break;
}
}
}
return definitions;