forked from qt-creator/qt-creator
Generic highlighter: Fix matching the right definition
No longer uses artificial mime types for highlighting files that do not specify a mime type. No longer registers mime types that are specified but that Qt Creator does not know about. Instead, try to match the mime type, and if that fails, or if the result does not match the file name pattern, try to match file name patterns instead. This also fixes the potential problem that mime types were always only added, never removed, even if the user removed definitions and triggered a reparse. Also fixes that a highlight definition in the fallback location could overwrite a highlight definition in the preferred location, if it has a higher priority setting. Task-number: QTCREATORBUG-13912 Change-Id: I86ce10f4f4341f6add0d2b58a04f080501d0cbf4 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -37,30 +37,10 @@
|
||||
using namespace TextEditor;
|
||||
using namespace Internal;
|
||||
|
||||
QString TextEditor::findDefinitionId(const Core::MimeType &mimeType,
|
||||
bool considerParents)
|
||||
{
|
||||
QString definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.aliases());
|
||||
if (definitionId.isEmpty() && considerParents) {
|
||||
definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.subClassesOf());
|
||||
if (definitionId.isEmpty()) {
|
||||
foreach (const QString &parent, mimeType.subClassesOf()) {
|
||||
const Core::MimeType &parentMimeType = Core::MimeDatabase::findByType(parent);
|
||||
definitionId = findDefinitionId(parentMimeType, considerParents);
|
||||
}
|
||||
}
|
||||
}
|
||||
return definitionId;
|
||||
}
|
||||
|
||||
void TextEditor::setMimeTypeForHighlighter(Highlighter *highlighter, const Core::MimeType &mimeType,
|
||||
QString *foundDefinitionId)
|
||||
const QString &filePath, QString *foundDefinitionId)
|
||||
{
|
||||
const QString type = mimeType.type();
|
||||
QString definitionId = Manager::instance()->definitionIdByMimeType(type);
|
||||
if (definitionId.isEmpty())
|
||||
definitionId = findDefinitionId(mimeType, true);
|
||||
|
||||
QString definitionId = Manager::instance()->definitionIdByMimeTypeAndFile(mimeType, filePath);
|
||||
if (!definitionId.isEmpty()) {
|
||||
const QSharedPointer<HighlightDefinition> &definition =
|
||||
Manager::instance()->definition(definitionId);
|
||||
@@ -72,9 +52,3 @@ void TextEditor::setMimeTypeForHighlighter(Highlighter *highlighter, const Core:
|
||||
*foundDefinitionId = definitionId;
|
||||
}
|
||||
|
||||
SyntaxHighlighter *TextEditor::createGenericSyntaxHighlighter(const Core::MimeType &mimeType)
|
||||
{
|
||||
Highlighter *highlighter = new Highlighter();
|
||||
setMimeTypeForHighlighter(highlighter, mimeType);
|
||||
return highlighter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user