forked from qt-creator/qt-creator
CMake: Fix syntax highlighting for cmake files
The newest kate definition files for cmake contain no mimetype for the cmake definitions, which lead to us not finding the right definition. Instead add a method to find the definition based on the name, which is not as generic, but we know which one we want for cmake anyway. Task-number: QTCREATORBUG-13588 Change-Id: Ib57fe531a225310c32ca1ef909a31bd7f52c612f Reviewed-by: Guilhem Vallat <guilhem.vallat@gmail.com> Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com> Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -276,7 +276,7 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeSettingsPage *settingsPage)
|
||||
setEditorCreator([]() { return new CMakeEditor; });
|
||||
setEditorWidgetCreator([]() { return new CMakeEditorWidget; });
|
||||
setDocumentCreator([]() { return new CMakeDocument; });
|
||||
setGenericSyntaxHighlighter(QLatin1String(Constants::CMAKEMIMETYPE));
|
||||
setGenericSyntaxHighlighterByName(QLatin1String("CMake"));
|
||||
setCommentStyle(Utils::CommentDefinition::HashStyle);
|
||||
setCodeFoldingSupported(true);
|
||||
|
||||
|
||||
@@ -7377,6 +7377,20 @@ void TextEditorFactory::setGenericSyntaxHighlighter(const QString &mimeType)
|
||||
};
|
||||
}
|
||||
|
||||
void TextEditorFactory::setGenericSyntaxHighlighterByName(const QString &name)
|
||||
{
|
||||
d->m_syntaxHighlighterCreator = [this, name]() -> SyntaxHighlighter * {
|
||||
TextEditor::Highlighter *highlighter = new TextEditor::Highlighter();
|
||||
QString definitionId = Manager::instance()->definitionIdByName(name);
|
||||
if (!definitionId.isEmpty()) {
|
||||
const QSharedPointer<HighlightDefinition> &definition = Manager::instance()->definition(definitionId);
|
||||
if (!definition.isNull() && definition->isValid())
|
||||
highlighter->setDefaultContext(definition->initialContext());
|
||||
}
|
||||
return highlighter;
|
||||
};
|
||||
}
|
||||
|
||||
void TextEditorFactory::setAutoCompleterCreator(const AutoCompleterCreator &creator)
|
||||
{
|
||||
d->m_autoCompleterCreator = creator;
|
||||
|
||||
@@ -667,6 +667,7 @@ public:
|
||||
void setIndenterCreator(const IndenterCreator &creator);
|
||||
void setSyntaxHighlighterCreator(const SyntaxHighLighterCreator &creator);
|
||||
void setGenericSyntaxHighlighter(const QString &mimeType);
|
||||
void setGenericSyntaxHighlighterByName(const QString &name);
|
||||
void setAutoCompleterCreator(const AutoCompleterCreator &creator);
|
||||
|
||||
void setEditorActionHandlers(Core::Id contextId, uint optionalActions);
|
||||
|
||||
Reference in New Issue
Block a user