From 32b6aab371b8aa4f9e09fe953858a971ab0f51f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 22 Dec 2022 01:44:36 -0300 Subject: [PATCH] Updated SOIL2. Allow to register space for the upper zone of the UICodeEditor. ecode: Minor fixes. --- bin/assets/plugins/formatters.json | 2 +- bin/assets/plugins/linters.json | 2 +- include/eepp/ui/uicodeeditor.hpp | 21 +++++++- src/eepp/ui/uicodeeditor.cpp | 51 +++++++++++++++++-- src/thirdparty/SOIL2 | 2 +- src/tools/ecode/appconfig.cpp | 2 +- .../ecode/plugins/lsp/lspclientplugin.cpp | 10 +++- .../ecode/plugins/lsp/lspclientplugin.hpp | 4 ++ 8 files changed, 84 insertions(+), 10 deletions(-) diff --git a/bin/assets/plugins/formatters.json b/bin/assets/plugins/formatters.json index 5efe32122..92051e25a 100644 --- a/bin/assets/plugins/formatters.json +++ b/bin/assets/plugins/formatters.json @@ -11,7 +11,7 @@ "command": "prettier $FILENAME" }, { - "file_patterns": ["%.cpp$", "%.h$", "%.hpp$"], + "file_patterns": ["%.inl$", "%.cpp$", "%.hpp$", "%.cc$", "%.cxx$", "%.c++$", "%.hh$", "%.hxx$", "%.h++$", "%.objcpp$"], "command": "clang-format --style=file $FILENAME" }, { diff --git a/bin/assets/plugins/linters.json b/bin/assets/plugins/linters.json index e170a2d27..62fb9a767 100644 --- a/bin/assets/plugins/linters.json +++ b/bin/assets/plugins/linters.json @@ -47,7 +47,7 @@ "command": "solhint $FILENAME" }, { - "file_patterns": ["%.cpp$", "%.hpp$", "%.cxx$", "%.hxx$"], + "file_patterns": ["%.inl$", "%.cpp$", "%.hpp$", "%.cc$", "%.cxx$", "%.c++$", "%.hh$", "%.hxx$", "%.h++$", "%.objcpp$"], "warning_pattern": "$FILENAME:(%d+):(%d+):%s?([^%s]*)([^\n]*)", "warning_pattern_order": { "line": 1, "col": 2, "message": 4, "type": 3 }, "command": "cppcheck --language=c++ --enable=all --template=gcc $FILENAME" diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index c0ee5656c..6fdfc31da 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -84,6 +84,9 @@ class UICodeEditorPlugin { const Vector2f& /*screenStart*/, const Float& /*lineHeight*/, const Float& /*gutterWidth*/, const Float& /*fontSize*/ ){}; + virtual void drawTop( UICodeEditor* /*editor*/, const Vector2f& /*screenStart*/, + const Sizef& /*size*/, const Float& /*fontSize*/ ){}; + Uint32 addOnReadyCallback( const OnReadyCb& cb ) { mOnReadyCallbacks[mReadyCbNum++] = cb; return mReadyCbNum; @@ -537,12 +540,22 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { bool unregisterGutterSpace( UICodeEditorPlugin* plugin ); + /** Register a top space to be used by a plugin. + * @param plugin Plugin requesting it + * @param pixels Amount of pixels to request in the gutter + * @param order Order goes from left (lower number) to right (bigger number). */ + bool registerTopSpace( UICodeEditorPlugin* plugin, const Float& pixels, int order ); + + bool unregisterTopSpace( UICodeEditorPlugin* plugin ); + void showFindReplace(); TextPosition resolveScreenPosition( const Vector2f& position, bool clamp = true ) const; Rectf getScreenPosition( const TextPosition& position ) const; + const Float& getPluginsTopSpace() const; + protected: struct LastXOffset { TextPosition position; @@ -633,13 +646,15 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { }; mutable std::map mTextCache; Tools::UIDocFindReplace* mFindReplace{ nullptr }; - struct PluginGutterSpace { + struct PluginRequestedSpace { UICodeEditorPlugin* plugin; Float space; int order; }; - std::vector mPluginGutterSpaces; + std::vector mPluginGutterSpaces; Float mPluginsGutterSpace{ 0 }; + std::vector mPluginTopSpaces; + Float mPluginsTopSpace{ 0 }; Uint64 mLastExecuteEventId{ 0 }; UICodeEditor( const std::string& elementTag, const bool& autoRegisterBaseCommands = true, @@ -813,6 +828,8 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { void updateLineCache( const Int64& lineIndex ); bool gutterSpaceExists( UICodeEditorPlugin* plugin ) const; + + bool topSpaceExists( UICodeEditorPlugin* plugin ) const; }; }} // namespace EE::UI diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 4d0b438c2..15aa4c1d7 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -217,7 +217,7 @@ void UICodeEditor::draw() { int lineNumberDigits = getLineNumberDigits(); Float gutterWidth = getGutterWidth(); Vector2f screenStart( getScreenStart() ); - Vector2f start( screenStart.x + gutterWidth, screenStart.y ); + Vector2f start( screenStart.x + gutterWidth, screenStart.y + getPluginsTopSpace() ); Vector2f startScroll( start - mScroll ); Primitives primitives; TextPosition cursor( mDoc->getSelection().start() ); @@ -225,6 +225,15 @@ void UICodeEditor::draw() { for ( auto& plugin : mPlugins ) plugin->preDraw( this, startScroll, lineHeight, cursor ); + if ( mPluginsTopSpace > 0 ) { + Float curTopPos = 0.f; + for ( auto& plugin : mPluginTopSpaces ) { + plugin.plugin->drawTop( this, { screenStart.x, screenStart.y + curTopPos }, + { mSize.getWidth(), plugin.space }, charSize ); + curTopPos += plugin.space; + } + } + if ( !mLocked && mHighlightCurrentLine ) { primitives.setColor( Color( mCurrentLineBackgroundColor ).blendAlpha( mAlpha ) ); primitives.drawRectangle( Rectf( @@ -870,6 +879,7 @@ TextPosition UICodeEditor::resolveScreenPosition( const Vector2f& position, bool localPos += mScroll; localPos.x -= mPaddingPx.Left + getGutterWidth(); localPos.y -= mPaddingPx.Top; + localPos.y -= getPluginsTopSpace(); Int64 line = (Int64)eefloor( localPos.y / getLineHeight() ); if ( clamp ) line = eeclamp( line, 0, (Int64)( mDoc->linesCount() - 1 ) ); @@ -886,10 +896,14 @@ Rectf UICodeEditor::getScreenPosition( const TextPosition& position ) const { { getGlyphWidth(), lineHeight } }; } +const Float& UICodeEditor::getPluginsTopSpace() const { + return mPluginsTopSpace; +} + Vector2f UICodeEditor::getViewPortLineCount() const { return Vector2f( eefloor( getViewportWidth() / getGlyphWidth() ), - eefloor( ( mSize.getHeight() - mPaddingPx.Top - + eefloor( ( mSize.getHeight() - mPaddingPx.Top - getPluginsTopSpace() - ( mHScrollBar->isVisible() ? mHScrollBar->getPixelsSize().getHeight() : 0.f ) ) / getLineHeight() ) ); } @@ -2133,6 +2147,14 @@ bool UICodeEditor::gutterSpaceExists( UICodeEditorPlugin* plugin ) const { return false; } +bool UICodeEditor::topSpaceExists( UICodeEditorPlugin* plugin ) const { + for ( const auto& space : mPluginTopSpaces ) { + if ( space.plugin == plugin ) + return true; + } + return false; +} + bool UICodeEditor::registerGutterSpace( UICodeEditorPlugin* plugin, const Float& pixels, int order ) { if ( gutterSpaceExists( plugin ) ) @@ -2140,7 +2162,7 @@ bool UICodeEditor::registerGutterSpace( UICodeEditorPlugin* plugin, const Float& mPluginGutterSpaces.push_back( { plugin, pixels, order } ); mPluginsGutterSpace += pixels; std::sort( mPluginGutterSpaces.begin(), mPluginGutterSpaces.end(), - []( const PluginGutterSpace& left, const PluginGutterSpace& right ) { + []( const PluginRequestedSpace& left, const PluginRequestedSpace& right ) { return left.order < right.order; } ); return true; @@ -2157,6 +2179,29 @@ bool UICodeEditor::unregisterGutterSpace( UICodeEditorPlugin* plugin ) { return false; } +bool UICodeEditor::registerTopSpace( UICodeEditorPlugin* plugin, const Float& pixels, int order ) { + if ( topSpaceExists( plugin ) ) + return false; + mPluginTopSpaces.push_back( { plugin, pixels, order } ); + mPluginsTopSpace += pixels; + std::sort( mPluginTopSpaces.begin(), mPluginTopSpaces.end(), + []( const PluginRequestedSpace& left, const PluginRequestedSpace& right ) { + return left.order < right.order; + } ); + return true; +} + +bool UICodeEditor::unregisterTopSpace( UICodeEditorPlugin* plugin ) { + for ( size_t i = 0; i < mPluginTopSpaces.size(); ++i ) { + if ( mPluginTopSpaces[i].plugin == plugin ) { + mPluginsTopSpace -= mPluginTopSpaces[i].space; + mPluginTopSpaces.erase( mPluginTopSpaces.begin() + i ); + return true; + } + } + return false; +} + Float UICodeEditor::getCharacterSize() const { return PixelDensity::dpToPx( mFontStyleConfig.getFontCharacterSize() ); } diff --git a/src/thirdparty/SOIL2 b/src/thirdparty/SOIL2 index 0b2407e78..957d538a5 160000 --- a/src/thirdparty/SOIL2 +++ b/src/thirdparty/SOIL2 @@ -1 +1 @@ -Subproject commit 0b2407e787495bd36c16d7de6302dc3a7c86ee24 +Subproject commit 957d538a5561f029a0760914979426693edc4c7e diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index 286c791fb..97b426001 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -127,7 +127,7 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath, pluginsEnabled[creator.first] = ini.getValueB( "plugins", creator.first, "autocomplete" == creator.first || "linter" == creator.first || - "autoformatter" == creator.first ); + "autoformatter" == creator.first || "lspclient" == creator.first ); pluginManager->setPluginsEnabled( pluginsEnabled ); iniInfo = FileInfo( ini.path() ); diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp index 5f6b985ee..553e4d56a 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp @@ -174,7 +174,7 @@ void LSPClientPlugin::load( PluginManager* pluginManager ) { path = pluginManager->getPluginsPath() + "lspclient.json"; if ( FileSystem::fileExists( path ) || FileSystem::fileWrite( - path, "{\n \"config\":{},\n \"keybindings\":{},\n \"formatters\":[]\n}\n" ) ) { + path, "{\n \"config\":{},\n \"keybindings\":{},\n \"servers\":[]\n}\n" ) ) { mConfigPath = path; paths.emplace_back( path ); } @@ -548,4 +548,12 @@ const LSPClientServerManager& LSPClientPlugin::getClientManager() const { return mClientManager; } +bool LSPClientPlugin::hasFileConfig() { + return !mConfigPath.empty(); +} + +std::string LSPClientPlugin::getFileConfigPath() { + return mConfigPath; +} + } // namespace ecode diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.hpp b/src/tools/ecode/plugins/lsp/lspclientplugin.hpp index 350cd494f..845246090 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.hpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.hpp @@ -66,6 +66,10 @@ class LSPClientPlugin : public UICodeEditorPlugin { const LSPClientServerManager& getClientManager() const; + bool hasFileConfig(); + + std::string getFileConfigPath(); + protected: PluginManager* mManager{ nullptr }; std::shared_ptr mThreadPool;