diff options
author | David Schulz <david.schulz@qt.io> | 2022-06-29 12:02:47 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2022-06-29 13:01:18 +0000 |
commit | 56faa204bd9fc408ea101bbb010abdc89cff4810 (patch) | |
tree | fd1c196345a2c1bf9bb97982b145b324de9ccf32 /src/libs/3rdparty/syntax-highlighting/src | |
parent | 5edbf915a426b87f7fbc1a48332ec9c14e392c07 (diff) |
Editor: update ksyntaxhighlighting engine to v5.95.0
Task-number: QTCREATORBUG-22558
Change-Id: I475730f342e7cc822fecdf7c9db64dc47baea83a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/libs/3rdparty/syntax-highlighting/src')
12 files changed, 406 insertions, 15 deletions
diff --git a/src/libs/3rdparty/syntax-highlighting/src/indexer/CMakeLists.txt b/src/libs/3rdparty/syntax-highlighting/src/indexer/CMakeLists.txt index 9aede60ad7..77a16faf22 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/indexer/CMakeLists.txt +++ b/src/libs/3rdparty/syntax-highlighting/src/indexer/CMakeLists.txt @@ -19,6 +19,7 @@ elseif(CMAKE_CROSSCOMPILING) CMAKE_ARGS -DKSYNTAXHIGHLIGHTING_USE_GUI=OFF -DECM_DIR=${ECM_DIR} -DCMAKE_PREFIX_PATH=${NATIVE_PREFIX} -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR} + -DQT_MAJOR_VERSION=${QT_MAJOR_VERSION} INSTALL_COMMAND "" BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/native_katehighlightingindexer-prefix/src/native_katehighlightingindexer-build/bin/katehighlightingindexer ) diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/CMakeLists.txt b/src/libs/3rdparty/syntax-highlighting/src/lib/CMakeLists.txt index 2ab0e603a2..58533cc713 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/CMakeLists.txt +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/CMakeLists.txt @@ -47,7 +47,7 @@ set_target_properties(KF5SyntaxHighlighting PROPERTIES SOVERSION ${SyntaxHighlighting_SOVERSION} EXPORT_NAME SyntaxHighlighting ) -target_include_directories(KF5SyntaxHighlighting INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF}/KSyntaxHighlighting;${KDE_INSTALL_INCLUDEDIR_KF}>") +target_include_directories(KF5SyntaxHighlighting INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF}/KSyntaxHighlighting>") target_include_directories(KF5SyntaxHighlighting PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_BINARY_DIR};>") target_link_libraries(KF5SyntaxHighlighting PUBLIC @@ -56,26 +56,38 @@ target_link_libraries(KF5SyntaxHighlighting Qt${QT_MAJOR_VERSION}::Network ) -ecm_generate_headers(SyntaxHighlighting_HEADERS - HEADER_NAMES - AbstractHighlighter - Definition - DefinitionDownloader - FoldingRegion - Format - Repository - State - SyntaxHighlighter - Theme - WildcardMatcher +set(Forwarding_Header_Names + AbstractHighlighter + Definition + DefinitionDownloader + FoldingRegion + Format + Repository + State + SyntaxHighlighter + Theme + WildcardMatcher +) + +ecm_generate_headers(CamelCase_HEADERS + HEADER_NAMES ${Forwarding_Header_Names} REQUIRED_HEADERS SyntaxHighlighting_HEADERS + # Avoid unprefixed headers in build dir (which is part of library's build interface include directories) + # and thus visible to anything linking it in the same build, incl. when used with CMake's FetchContent. + # E.g. there can be look-up clashes on case-insensitive filesystems with C++20's <format> file and + # the library's generated "Format" file. + # See BUG: 453759 + OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/camelcaseheaders ) install(TARGETS KF5SyntaxHighlighting EXPORT KF5SyntaxHighlightingTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) + install(FILES + ${CamelCase_HEADERS} ${SyntaxHighlighting_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/ksyntaxhighlighting_export.h - DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF}/KSyntaxHighlighting) + DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF}/KSyntaxHighlighting/KSyntaxHighlighting +) if(BUILD_QCH) ecm_add_qch( diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h b/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h index 9e19ecda56..3739b55e78 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h @@ -9,9 +9,9 @@ #include "ksyntaxhighlighting_export.h" +#include <QVector> #include <memory> #include <qglobal.h> -#include <qvector.h> QT_BEGIN_NAMESPACE class QString; diff --git a/src/libs/3rdparty/syntax-highlighting/src/quick/CMakeLists.txt b/src/libs/3rdparty/syntax-highlighting/src/quick/CMakeLists.txt new file mode 100644 index 0000000000..f40b3ae1ca --- /dev/null +++ b/src/libs/3rdparty/syntax-highlighting/src/quick/CMakeLists.txt @@ -0,0 +1,17 @@ +# SPDX-FileCopyrightText: 2018 Eike Hein <hein@kde.org> +# SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> +# SPDX-License-Identifier: BSD-3-Clause + +add_library(kquicksyntaxhighlightingplugin) +target_sources(kquicksyntaxhighlightingplugin PRIVATE + kquicksyntaxhighlightingplugin.cpp + kquicksyntaxhighlighter.cpp + repositorywrapper.cpp +) +target_link_libraries(kquicksyntaxhighlightingplugin PRIVATE + KF5SyntaxHighlighting + Qt${QT_MAJOR_VERSION}::Quick +) + +install(TARGETS kquicksyntaxhighlightingplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/syntaxhighlighting) +install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/syntaxhighlighting) diff --git a/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlighter.cpp b/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlighter.cpp new file mode 100644 index 0000000000..428a6c40cb --- /dev/null +++ b/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlighter.cpp @@ -0,0 +1,112 @@ +/* + SPDX-FileCopyrightText: 2018 Eike Hein <hein@kde.org> + SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> + + SPDX-License-Identifier: MIT +*/ + +#include "kquicksyntaxhighlighter.h" + +#include <repository.h> +#include <syntaxhighlighter.h> + +#include <QGuiApplication> +#include <QPalette> +#include <QQuickTextDocument> +#include <QTextDocument> + +using namespace KSyntaxHighlighting; + +extern Repository *defaultRepository(); + +KQuickSyntaxHighlighter::KQuickSyntaxHighlighter(QObject *parent) + : QObject(parent) + , m_textEdit(nullptr) + , m_highlighter(new KSyntaxHighlighting::SyntaxHighlighter(this)) +{ +} + +KQuickSyntaxHighlighter::~KQuickSyntaxHighlighter() = default; + +QObject *KQuickSyntaxHighlighter::textEdit() const +{ + return m_textEdit; +} + +void KQuickSyntaxHighlighter::setTextEdit(QObject *textEdit) +{ + if (m_textEdit != textEdit) { + m_textEdit = textEdit; + m_highlighter->setDocument(m_textEdit->property("textDocument").value<QQuickTextDocument *>()->textDocument()); + } +} + +QVariant KQuickSyntaxHighlighter::definition() const +{ + return QVariant::fromValue(m_definition); +} + +void KQuickSyntaxHighlighter::setDefinition(const QVariant &definition) +{ + Definition def; + if (definition.type() == QVariant::String) { + def = unwrappedRepository()->definitionForName(definition.toString()); + } else { + def = definition.value<Definition>(); + } + + if (m_definition != def) { + m_definition = def; + + m_highlighter->setTheme(m_theme.isValid() ? m_theme : unwrappedRepository()->themeForPalette(QGuiApplication::palette())); + m_highlighter->setDefinition(def); + + Q_EMIT definitionChanged(); + } +} + +QVariant KQuickSyntaxHighlighter::theme() const +{ + return QVariant::fromValue(m_theme); +} + +void KQuickSyntaxHighlighter::setTheme(const QVariant &theme) +{ + Theme t; + if (theme.type() == QVariant::String) { + t = unwrappedRepository()->theme(theme.toString()); + } else if (theme.type() == QVariant::Int) { + t = unwrappedRepository()->defaultTheme(static_cast<Repository::DefaultTheme>(theme.toInt())); + } else { + t = theme.value<Theme>(); + } + + if (m_theme.name() != t.name()) { + m_theme = t; + m_highlighter->setTheme(m_theme); + m_highlighter->rehighlight(); + Q_EMIT themeChanged(); + } +} + +RepositoryWrapper *KQuickSyntaxHighlighter::repository() const +{ + return m_repository; +} + +void KQuickSyntaxHighlighter::setRepository(RepositoryWrapper *repository) +{ + if (m_repository == repository) { + return; + } + m_repository = repository; + Q_EMIT repositoryChanged(); +} + +Repository *KQuickSyntaxHighlighter::unwrappedRepository() const +{ + if (m_repository) { + return m_repository->m_repository; + } + return defaultRepository(); +} diff --git a/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlighter.h b/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlighter.h new file mode 100644 index 0000000000..38cd7b52af --- /dev/null +++ b/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlighter.h @@ -0,0 +1,66 @@ +/* + SPDX-FileCopyrightText: 2018 Eike Hein <hein@kde.org> + SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> + + SPDX-License-Identifier: MIT +*/ + +#ifndef KQUICKSYNTAXHIGHLIGHTER_H +#define KQUICKSYNTAXHIGHLIGHTER_H + +#include "repositorywrapper.h" + +#include <definition.h> +#include <theme.h> + +#include <QObject> +#include <QVariant> + +namespace KSyntaxHighlighting +{ +class Repository; +class SyntaxHighlighter; +} + +class KQuickSyntaxHighlighter : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QObject *textEdit READ textEdit WRITE setTextEdit NOTIFY textEditChanged) + Q_PROPERTY(QVariant definition READ definition WRITE setDefinition NOTIFY definitionChanged) + Q_PROPERTY(QVariant theme READ theme WRITE setTheme NOTIFY themeChanged) + Q_PROPERTY(RepositoryWrapper *repository READ repository WRITE setRepository NOTIFY repositoryChanged) + +public: + explicit KQuickSyntaxHighlighter(QObject *parent = nullptr); + ~KQuickSyntaxHighlighter() override; + + QObject *textEdit() const; + void setTextEdit(QObject *textEdit); + + QVariant definition() const; + void setDefinition(const QVariant &definition); + + QVariant theme() const; + void setTheme(const QVariant &theme); + + RepositoryWrapper *repository() const; + void setRepository(RepositoryWrapper *repository); + +Q_SIGNALS: + void textEditChanged() const; + void definitionChanged() const; + void themeChanged(); + void repositoryChanged(); + +private: + KSyntaxHighlighting::Repository *unwrappedRepository() const; + + QObject *m_textEdit; + KSyntaxHighlighting::Definition m_definition; + KSyntaxHighlighting::Theme m_theme; + RepositoryWrapper *m_repository = nullptr; + KSyntaxHighlighting::SyntaxHighlighter *m_highlighter = nullptr; +}; + +#endif // KQUICKSYNTAXHIGHLIGHTER_H diff --git a/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlightingplugin.cpp b/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlightingplugin.cpp new file mode 100644 index 0000000000..62c571e1b6 --- /dev/null +++ b/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlightingplugin.cpp @@ -0,0 +1,47 @@ +/* + SPDX-FileCopyrightText: 2018 Eike Hein <hein@kde.org> + SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> + + SPDX-License-Identifier: MIT +*/ + +#include "kquicksyntaxhighlightingplugin.h" +#include "kquicksyntaxhighlighter.h" +#include "repositorywrapper.h" + +#include <definition.h> +#include <repository.h> +#include <theme.h> + + +#include <memory> + +using namespace KSyntaxHighlighting; + +Repository *defaultRepository() +{ + static std::unique_ptr<Repository> s_instance; + if (!s_instance) { + s_instance = std::make_unique<Repository>(); + } + return s_instance.get(); +} + +void KQuickSyntaxHighlightingPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.syntaxhighlighting")); + qRegisterMetaType<Definition>(); + qRegisterMetaType<QVector<Definition>>(); + qRegisterMetaType<Theme>(); + qRegisterMetaType<QVector<Theme>>(); + qmlRegisterType<KQuickSyntaxHighlighter>(uri, 1, 0, "SyntaxHighlighter"); + qmlRegisterUncreatableType<Definition>(uri, 1, 0, "Definition", {}); + qmlRegisterUncreatableType<Theme>(uri, 1, 0, "Theme", {}); + qmlRegisterSingletonType<RepositoryWrapper>(uri, 1, 0, "Repository", [](auto engine, auto scriptEngine) { + (void)engine; + (void)scriptEngine; + auto repo = new RepositoryWrapper; + repo->m_repository = defaultRepository(); + return repo; + }); +} diff --git a/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlightingplugin.h b/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlightingplugin.h new file mode 100644 index 0000000000..a92405bb15 --- /dev/null +++ b/src/libs/3rdparty/syntax-highlighting/src/quick/kquicksyntaxhighlightingplugin.h @@ -0,0 +1,22 @@ +/* + SPDX-FileCopyrightText: 2018 Eike Hein <hein@kde.org> + + SPDX-License-Identifier: MIT +*/ + +#ifndef KQUICKSYNTAXHIGHLIGHTINGPLUGIN_H +#define KQUICKSYNTAXHIGHLIGHTINGPLUGIN_H + +#include <QQmlEngine> +#include <QQmlExtensionPlugin> + +class KQuickSyntaxHighlightingPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) override; +}; + +#endif // KQUICKSYNTAXHIGHLIGHTINGPLUGIN_H diff --git a/src/libs/3rdparty/syntax-highlighting/src/quick/qmldir b/src/libs/3rdparty/syntax-highlighting/src/quick/qmldir new file mode 100644 index 0000000000..0837f1bed1 --- /dev/null +++ b/src/libs/3rdparty/syntax-highlighting/src/quick/qmldir @@ -0,0 +1,2 @@ +module org.kde.syntaxhighlighting +plugin kquicksyntaxhighlightingplugin diff --git a/src/libs/3rdparty/syntax-highlighting/src/quick/qmldir.license b/src/libs/3rdparty/syntax-highlighting/src/quick/qmldir.license new file mode 100644 index 0000000000..c475521fa5 --- /dev/null +++ b/src/libs/3rdparty/syntax-highlighting/src/quick/qmldir.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2018 Eike Hein <hein@kde.org> +SPDX-License-Identifier: CC0-1.0 diff --git a/src/libs/3rdparty/syntax-highlighting/src/quick/repositorywrapper.cpp b/src/libs/3rdparty/syntax-highlighting/src/quick/repositorywrapper.cpp new file mode 100644 index 0000000000..88030c3912 --- /dev/null +++ b/src/libs/3rdparty/syntax-highlighting/src/quick/repositorywrapper.cpp @@ -0,0 +1,65 @@ +/* + SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> + + SPDX-License-Identifier: MIT +*/ + +#include "repositorywrapper.h" + +#include <definition.h> +#include <repository.h> +#include <theme.h> + +using namespace KSyntaxHighlighting; + +RepositoryWrapper::RepositoryWrapper(QObject *parent) + : QObject(parent) +{ +} + +Definition RepositoryWrapper::definitionForName(const QString &defName) const +{ + return m_repository->definitionForName(defName); +} + +Definition RepositoryWrapper::definitionForFileName(const QString &fileName) const +{ + return m_repository->definitionForFileName(fileName); +} + +QVector<Definition> RepositoryWrapper::definitionsForFileName(const QString &fileName) const +{ + return m_repository->definitionsForFileName(fileName); +} + +Definition RepositoryWrapper::definitionForMimeType(const QString &mimeType) const +{ + return m_repository->definitionForMimeType(mimeType); +} + +QVector<Definition> RepositoryWrapper::definitionsForMimeType(const QString &mimeType) const +{ + return m_repository->definitionsForMimeType(mimeType); +} + +QVector<Definition> RepositoryWrapper::definitions() const +{ + return m_repository->definitions(); +} + +QVector<Theme> RepositoryWrapper::themes() const +{ + return m_repository->themes(); +} + +Theme RepositoryWrapper::theme(const QString &themeName) const +{ + return m_repository->theme(themeName); +} + +Theme RepositoryWrapper::defaultTheme(DefaultTheme t) const +{ + return m_repository->defaultTheme(static_cast<Repository::DefaultTheme>(t)); +} + +#include "moc_repositorywrapper.cpp" diff --git a/src/libs/3rdparty/syntax-highlighting/src/quick/repositorywrapper.h b/src/libs/3rdparty/syntax-highlighting/src/quick/repositorywrapper.h new file mode 100644 index 0000000000..d4fb8d251c --- /dev/null +++ b/src/libs/3rdparty/syntax-highlighting/src/quick/repositorywrapper.h @@ -0,0 +1,45 @@ +/* + SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> + + SPDX-License-Identifier: MIT +*/ + +#ifndef REPOSITORYWRAPPER_H +#define REPOSITORYWRAPPER_H + +#include <QObject> + +namespace KSyntaxHighlighting +{ +class Definition; +class Repository; +class Theme; +} + +// TODO KF6: merge this into KSyntaxHighlighting::Repository +class RepositoryWrapper : public QObject +{ + Q_OBJECT + // TODO KF6: NOTIFY on reload + Q_PROPERTY(QVector<KSyntaxHighlighting::Definition> definitions READ definitions CONSTANT) + Q_PROPERTY(QVector<KSyntaxHighlighting::Theme> themes READ themes CONSTANT) +public: + explicit RepositoryWrapper(QObject *parent = nullptr); + + Q_INVOKABLE KSyntaxHighlighting::Definition definitionForName(const QString &defName) const; + Q_INVOKABLE KSyntaxHighlighting::Definition definitionForFileName(const QString &fileName) const; + Q_INVOKABLE QVector<KSyntaxHighlighting::Definition> definitionsForFileName(const QString &fileName) const; + Q_INVOKABLE KSyntaxHighlighting::Definition definitionForMimeType(const QString &mimeType) const; + Q_INVOKABLE QVector<KSyntaxHighlighting::Definition> definitionsForMimeType(const QString &mimeType) const; + QVector<KSyntaxHighlighting::Definition> definitions() const; + + QVector<KSyntaxHighlighting::Theme> themes() const; + Q_INVOKABLE KSyntaxHighlighting::Theme theme(const QString &themeName) const; + enum DefaultTheme { LightTheme, DarkTheme }; + Q_ENUM(DefaultTheme) + Q_INVOKABLE KSyntaxHighlighting::Theme defaultTheme(DefaultTheme t = LightTheme) const; + + KSyntaxHighlighting::Repository *m_repository = nullptr; +}; + +#endif // REPOSITORYWRAPPER_H |