From 3a8bd77c959e0998db3e8c8eb08ff1c715a53896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Fri, 14 Apr 2023 21:29:38 -0300 Subject: [PATCH] Allow disabling semantic highlighting for a specific lang. --- .../ecode/plugins/lsp/lspclientplugin.cpp | 26 +++++++++++++++++++ .../ecode/plugins/lsp/lspclientplugin.hpp | 4 +++ .../ecode/plugins/lsp/lspdocumentclient.cpp | 8 ++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp index 904ed9197..58ea1320f 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp @@ -424,6 +424,12 @@ void LSPClientPlugin::setSemanticHighlighting( bool semanticHighlighting ) { mSemanticHighlighting = semanticHighlighting; } +bool LSPClientPlugin::langSupportsSemanticHighlighting( const std::string& lspLang ) { + return !std::any_of( mSemanticHighlightingDisabledLangs.begin(), + mSemanticHighlightingDisabledLangs.end(), + [&lspLang]( const auto& other ) { return lspLang == other; } ); +} + bool LSPClientPlugin::editorExists( UICodeEditor* editor ) { return mManager->getSplitter()->editorExists( editor ); } @@ -756,6 +762,26 @@ void LSPClientPlugin::loadLSPConfig( std::vector& lsps, const std mSemanticHighlighting = config.value( "semantic_highlighting", false ); else if ( updateConfigFile ) config["semantic_highlighting"] = mSemanticHighlighting; + + if ( config.contains( "disable_semantic_highlighting_lang" ) ) { + try { + mSemanticHighlightingDisabledLangs.clear(); + const auto& langs = config["disable_semantic_highlighting_lang"]; + for ( const auto& lang : langs ) { + if ( lang.is_string() ) { + std::string lg = lang.get(); + if ( !lg.empty() ) + mSemanticHighlightingDisabledLangs.insert( lg ); + } + } + } catch ( const json::exception& e ) { + Log::debug( "LSPClientPlugin::loadLSPConfig: Error parsing " + "disable_semantic_highlighting_lang: %s", + e.what() ); + } + } else { + config["disable_semantic_highlighting_lang"] = json::array(); + } } if ( mKeyBindings.empty() ) { diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.hpp b/src/tools/ecode/plugins/lsp/lspclientplugin.hpp index 942bcf035..4b523c4d7 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.hpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.hpp @@ -13,6 +13,7 @@ #include #include #include +#include using namespace EE; using namespace EE::System; using namespace EE::UI; @@ -79,6 +80,8 @@ class LSPClientPlugin : public Plugin { void setSemanticHighlighting( bool semanticHighlighting ); + bool langSupportsSemanticHighlighting( const std::string& lspLang ); + protected: friend class LSPDocumentClient; friend class LSPClientServer; @@ -105,6 +108,7 @@ class LSPClientPlugin : public Plugin { Uint32 mOldTextStyle{ 0 }; Uint32 mOldTextAlign{ 0 }; LSPDiagnosticsCodeAction mQuickFix; + std::unordered_set mSemanticHighlightingDisabledLangs; LSPClientPlugin( PluginManager* pluginManager, bool sync ); diff --git a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp index 73176d597..023fd8dd3 100644 --- a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp +++ b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp @@ -112,7 +112,9 @@ void LSPDocumentClient::refreshTag() { } void LSPDocumentClient::requestSemanticHighlighting() { - if ( !mServer || !mServer->getManager()->getPlugin()->semanticHighlightingEnabled() ) + if ( !mServer || !mServer->getManager()->getPlugin()->semanticHighlightingEnabled() || + !mServer->getManager()->getPlugin()->langSupportsSemanticHighlighting( + mServer->getDefinition().language ) ) return; const auto& cap = mServer->getCapabilities(); if ( !cap.semanticTokenProvider.full && !cap.semanticTokenProvider.fullDelta && @@ -143,7 +145,9 @@ void LSPDocumentClient::requestSemanticHighlighting() { } void LSPDocumentClient::requestSemanticHighlightingDelayed() { - if ( !mServer || !mServer->getManager()->getPlugin()->semanticHighlightingEnabled() ) + if ( !mServer || !mServer->getManager()->getPlugin()->semanticHighlightingEnabled() || + !mServer->getManager()->getPlugin()->langSupportsSemanticHighlighting( + mServer->getDefinition().language ) ) return; const auto& cap = mServer->getCapabilities(); if ( !cap.semanticTokenProvider.full && !cap.semanticTokenProvider.fullDelta &&