diff --git a/include/eepp/ui/doc/syntaxcolorscheme.hpp b/include/eepp/ui/doc/syntaxcolorscheme.hpp index a88d04f41..8d3f9a3b6 100644 --- a/include/eepp/ui/doc/syntaxcolorscheme.hpp +++ b/include/eepp/ui/doc/syntaxcolorscheme.hpp @@ -11,6 +11,181 @@ using namespace EE::System; namespace EE { namespace UI { namespace Doc { +using SyntaxStyleType = String::HashType; + +constexpr auto operator""_sst( const char* s, std::size_t ) noexcept { + if constexpr ( std::is_same_v ) + return s; + else if constexpr ( std::is_same_v ) + return String::hash( s ); + else + return SyntaxStyleType{}; +} + +class SyntaxStyleTypes { + public: + static constexpr auto Normal = "normal"_sst; + static constexpr auto Symbol = "symbol"_sst; + static constexpr auto Comment = "comment"_sst; + static constexpr auto Keyword = "keyword"_sst; + static constexpr auto Keyword2 = "keyword2"_sst; + static constexpr auto Keyword3 = "keyword3"_sst; + static constexpr auto Number = "number"_sst; + static constexpr auto Literal = "literal"_sst; + static constexpr auto String = "string"_sst; + static constexpr auto Operator = "operator"_sst; + static constexpr auto Function = "function"_sst; + static constexpr auto Link = "link"_sst; + static constexpr auto LinkHover = "link_hover"_sst; + static constexpr auto Background = "background"_sst; + static constexpr auto Text = "text"_sst; + static constexpr auto Caret = "caret"_sst; + static constexpr auto Selection = "selection"_sst; + static constexpr auto LineHighlight = "line_highlight"_sst; + static constexpr auto LineNumber = "line_number"_sst; + static constexpr auto LineNumber2 = "line_number2"_sst; + static constexpr auto GutterBackground = "gutter_background"_sst; + static constexpr auto Whitespace = "whitespace"_sst; + static constexpr auto LineBreakColumn = "line_break_column"_sst; + static constexpr auto MatchingBracket = "matching_bracket"_sst; + static constexpr auto MatchingSelection = "matching_selection"_sst; + static constexpr auto MatchingSearch = "matching_search"_sst; + static constexpr auto Suggestion = "suggestion"_sst; + static constexpr auto SuggestionScrollbar = "suggestion_scrollbar"_sst; + static constexpr auto SuggestionSelected = "suggestion_selected"_sst; + static constexpr auto Error = "error"_sst; + static constexpr auto Warning = "warning"_sst; + static constexpr auto Notice = "notice"_sst; + static constexpr auto SelectionRegion = "selection_region"_sst; + static constexpr auto MinimapBackground = "minimap_background"_sst; + static constexpr auto MinimapCurrentLine = "minimap_current_line"_sst; + static constexpr auto MinimapHover = "minimap_hover"_sst; + static constexpr auto MinimapSelection = "minimap_selection"_sst; + static constexpr auto MinimapHighlight = "minimap_highlight"_sst; + static constexpr auto MinimapVisibleArea = "minimap_visible_area"_sst; + + template static std::string toString( const Type& style ) { + if constexpr ( std::is_same_v ) { + return style; + } else if constexpr ( std::is_same_v ) { + switch ( style ) { + case SyntaxStyleTypes::Normal: + return "normal"; + case SyntaxStyleTypes::Symbol: + return "symbol"; + case SyntaxStyleTypes::Comment: + return "comment"; + case SyntaxStyleTypes::Keyword: + return "keyword"; + case SyntaxStyleTypes::Keyword2: + return "keyword2"; + case SyntaxStyleTypes::Keyword3: + return "keyword3"; + case SyntaxStyleTypes::Number: + return "number"; + case SyntaxStyleTypes::Literal: + return "literal"; + case SyntaxStyleTypes::String: + return "string"; + case SyntaxStyleTypes::Operator: + return "operator"; + case SyntaxStyleTypes::Function: + return "function"; + case SyntaxStyleTypes::Link: + return "link"; + case SyntaxStyleTypes::LinkHover: + return "link_hover"; + case SyntaxStyleTypes::Background: + return "background"; + case SyntaxStyleTypes::Text: + return "text"; + case SyntaxStyleTypes::Caret: + return "caret"; + case SyntaxStyleTypes::Selection: + return "selection"; + case SyntaxStyleTypes::LineHighlight: + return "line_highlight"; + case SyntaxStyleTypes::LineNumber: + return "line_number"; + case SyntaxStyleTypes::LineNumber2: + return "line_number2"; + case SyntaxStyleTypes::GutterBackground: + return "gutter_background"; + case SyntaxStyleTypes::Whitespace: + return "whitespace"; + case SyntaxStyleTypes::LineBreakColumn: + return "line_break_column"; + case SyntaxStyleTypes::MatchingBracket: + return "matching_bracket"; + case SyntaxStyleTypes::MatchingSelection: + return "matching_selection"; + case SyntaxStyleTypes::MatchingSearch: + return "matching_search"; + case SyntaxStyleTypes::Suggestion: + return "suggestion"; + case SyntaxStyleTypes::SuggestionScrollbar: + return "suggestion_scrollbar"; + case SyntaxStyleTypes::SuggestionSelected: + return "suggestion_selected"; + case SyntaxStyleTypes::Error: + return "error"; + case SyntaxStyleTypes::Warning: + return "warning"; + case SyntaxStyleTypes::Notice: + return "notice"; + case SyntaxStyleTypes::SelectionRegion: + return "selection_region"; + case SyntaxStyleTypes::MinimapBackground: + return "minimap_background"; + case SyntaxStyleTypes::MinimapCurrentLine: + return "minimap_current_line"; + case SyntaxStyleTypes::MinimapHover: + return "minimap_hover"; + case SyntaxStyleTypes::MinimapSelection: + return "minimap_selection"; + case SyntaxStyleTypes::MinimapHighlight: + return "minimap_highlight"; + case SyntaxStyleTypes::MinimapVisibleArea: + return "minimap_visible_area"; + default: + break; + } + } + return String::toString( style ); + } +}; + +template constexpr auto SyntaxStyleTypeHash( const Type& type ) noexcept { + if constexpr ( std::is_same_v ) + return String::hash( type ); + else if constexpr ( std::is_same_v ) + return type; + else + return SyntaxStyleType{}; +} + +template static auto toSyntaxStyleType( const T& s ) noexcept { + if constexpr ( std::is_same_v && std::is_same_v ) + return s; + else if constexpr ( std::is_same_v && + std::is_same_v ) + return String::hash( s ); + else if constexpr ( std::is_same_v && + std::is_same_v ) + return String::toString( s ); + else + return SyntaxStyleType{}; +} + +constexpr auto SyntaxStyleEmpty() { + if constexpr ( std::is_same_v ) + return ""; + else if constexpr ( std::is_same_v ) + return 0; + else + return SyntaxStyleType{}; +} + /** * Syntax colors types accepted/used are: * "normal", "symbol", "comment", "keyword", "keyword2", @@ -52,24 +227,24 @@ class EE_API SyntaxColorScheme { SyntaxColorScheme(); SyntaxColorScheme( const std::string& name, - const UnorderedMap& syntaxColors, - const UnorderedMap& editorColors ); + const UnorderedMap& syntaxColors, + const UnorderedMap& editorColors ); - const Style& getSyntaxStyle( const std::string& type ) const; + const Style& getSyntaxStyle( const SyntaxStyleType& type ) const; - bool hasSyntaxStyle( const std::string& type ) const; + bool hasSyntaxStyle( const SyntaxStyleType& type ) const; - void setSyntaxStyles( const UnorderedMap& styles ); + void setSyntaxStyles( const UnorderedMap& styles ); - void setSyntaxStyle( const std::string& type, const Style& style ); + void setSyntaxStyle( const SyntaxStyleType& type, const Style& style ); - const Style& getEditorSyntaxStyle( const std::string& type ) const; + const Style& getEditorSyntaxStyle( const SyntaxStyleType& type ) const; - const Color& getEditorColor( const std::string& type ) const; + const Color& getEditorColor( const SyntaxStyleType& type ) const; - void setEditorSyntaxStyles( const UnorderedMap& styles ); + void setEditorSyntaxStyles( const UnorderedMap& styles ); - void setEditorSyntaxStyle( const std::string& type, const Style& style ); + void setEditorSyntaxStyle( const SyntaxStyleType& type, const Style& style ); const std::string& getName() const; @@ -77,9 +252,9 @@ class EE_API SyntaxColorScheme { protected: std::string mName; - UnorderedMap mSyntaxColors; - UnorderedMap mEditorColors; - mutable UnorderedMap mStyleCache; + UnorderedMap mSyntaxColors; + UnorderedMap mEditorColors; + mutable UnorderedMap mStyleCache; }; }}} // namespace EE::UI::Doc diff --git a/include/eepp/ui/doc/syntaxdefinition.hpp b/include/eepp/ui/doc/syntaxdefinition.hpp index 37dce737c..18c2204e2 100644 --- a/include/eepp/ui/doc/syntaxdefinition.hpp +++ b/include/eepp/ui/doc/syntaxdefinition.hpp @@ -3,24 +3,50 @@ #include #include +#include +#include #include +#include #include #include namespace EE { namespace UI { namespace Doc { +template static auto toSyntaxStyleTypeV( const std::vector& s ) noexcept { + if constexpr ( std::is_same_v && + std::is_same_v ) { + return s; + } else if constexpr ( std::is_same_v && + std::is_same_v ) { + std::vector v; + v.reserve( s.size() ); + for ( const auto& sv : s ) + v.push_back( String::hash( sv ) ); + return v; + } else + return std::vector{}; +} + struct EE_API SyntaxPattern { std::vector patterns; - std::vector types; + std::vector types; + std::vector typesNames; + std::string syntax{ "" }; - SyntaxPattern( std::vector _patterns, std::string _type, - std::string _syntax = "" ) : - patterns( _patterns ), types( { _type } ), syntax( _syntax ) {} + SyntaxPattern( const std::vector& _patterns, const std::string& _type, + const std::string& _syntax = "" ) : + patterns( _patterns ), + types( toSyntaxStyleTypeV( std::vector{ _type } ) ), + typesNames( { _type } ), + syntax( _syntax ) {} - SyntaxPattern( std::vector _patterns, std::vector _types, - std::string _syntax = "" ) : - patterns( _patterns ), types( _types ), syntax( _syntax ) {} + SyntaxPattern( const std::vector& _patterns, + const std::vector& _types, const std::string& _syntax = "" ) : + patterns( _patterns ), + types( toSyntaxStyleTypeV( _types ) ), + typesNames( _types ), + syntax( _syntax ) {} }; class EE_API SyntaxDefinition { @@ -29,8 +55,7 @@ class EE_API SyntaxDefinition { SyntaxDefinition( const std::string& languageName, const std::vector& files, const std::vector& patterns, - const std::unordered_map& symbols = - std::unordered_map(), + const std::unordered_map& symbols = {}, const std::string& comment = "", const std::vector headers = {}, const std::string& lspName = "" ); @@ -48,9 +73,9 @@ class EE_API SyntaxDefinition { const std::string& getComment() const; - const std::unordered_map& getSymbols() const; + const std::unordered_map& getSymbols() const; - std::string getSymbol( const std::string& symbol ) const; + SyntaxStyleType getSymbol( const std::string& symbol ) const; /** Accepts lua patterns and file extensions. */ SyntaxDefinition& addFileType( const std::string& fileType ); @@ -63,10 +88,12 @@ class EE_API SyntaxDefinition { SyntaxDefinition& addPatternsToFront( const std::vector& patterns ); - SyntaxDefinition& addSymbol( const std::string& symbolName, const std::string& typeName ); + SyntaxDefinition& addSymbol( const std::string& symbolName, const SyntaxStyleType& typeName ); SyntaxDefinition& addSymbols( const std::vector& symbolNames, - const std::string& typeName ); + const SyntaxStyleType& typeName ); + + SyntaxDefinition& setSymbols( const std::unordered_map& symbols ); /** Sets the comment string used for auto-comment functionality. */ SyntaxDefinition& setComment( const std::string& comment ); @@ -93,7 +120,7 @@ class EE_API SyntaxDefinition { SyntaxDefinition& setLSPName( const std::string& lSPName ); - std::vector getPatternsOfType( const std::string& type ) const; + std::vector getPatternsOfType( const SyntaxStyleType& type ) const; SyntaxDefinition& setFileTypes( const std::vector& types ); @@ -101,12 +128,15 @@ class EE_API SyntaxDefinition { void setExtensionPriority( bool hasExtensionPriority ); + std::unordered_map getSymbolNames() const; + protected: std::string mLanguageName; String::HashType mLanguageId; std::vector mFiles; std::vector mPatterns; - std::unordered_map mSymbols; + std::unordered_map mSymbols; + std::unordered_map mSymbolNames; std::string mComment; std::vector mHeaders; std::string mLSPName; diff --git a/include/eepp/ui/doc/syntaxhighlighter.hpp b/include/eepp/ui/doc/syntaxhighlighter.hpp index 908a3ab68..a8694e0a1 100644 --- a/include/eepp/ui/doc/syntaxhighlighter.hpp +++ b/include/eepp/ui/doc/syntaxhighlighter.hpp @@ -39,7 +39,7 @@ class EE_API SyntaxHighlighter { const SyntaxDefinition& getSyntaxDefinitionFromTextPosition( const TextPosition& position ); - std::string getTokenTypeAt( const TextPosition& pos ); + SyntaxStyleType getTokenTypeAt( const TextPosition& pos ); SyntaxTokenPosition getTokenPositionAt( const TextPosition& pos ); diff --git a/include/eepp/ui/doc/syntaxtokenizer.hpp b/include/eepp/ui/doc/syntaxtokenizer.hpp index 30c543676..b5a6c5da5 100644 --- a/include/eepp/ui/doc/syntaxtokenizer.hpp +++ b/include/eepp/ui/doc/syntaxtokenizer.hpp @@ -14,21 +14,18 @@ using namespace EE::Graphics; namespace EE { namespace UI { namespace Doc { struct EE_API SyntaxToken { - std::string type; + SyntaxStyleType type; size_t len{ 0 }; }; struct EE_API SyntaxTokenPosition { - // TODO: type should be the hash of the name of the type. Using std::string takes at least - // 32 bytes per token vs 4 bytes. It's much easier to debug a string than a hash and that's - // the reason why we keep it for the moment. - std::string type; + SyntaxStyleType type; Int64 pos{ 0 }; size_t len{ 0 }; }; struct EE_API SyntaxTokenComplete { - std::string type; + SyntaxStyleType type; std::string text; size_t len{ 0 }; }; diff --git a/src/eepp/ui/doc/syntaxcolorscheme.cpp b/src/eepp/ui/doc/syntaxcolorscheme.cpp index bd943cfbe..141cc5dab 100644 --- a/src/eepp/ui/doc/syntaxcolorscheme.cpp +++ b/src/eepp/ui/doc/syntaxcolorscheme.cpp @@ -36,55 +36,56 @@ namespace EE { namespace UI { namespace Doc { // "minimap_visible_area" (Minimap visible area marker color) SyntaxColorScheme SyntaxColorScheme::getDefault() { - return { "eepp", - { - { "normal", Color( "#e1e1e6" ) }, - { "symbol", Color( "#e1e1e6" ) }, - { "comment", Color( "#cd8b00" ) }, - { "keyword", { Color( "#ff79c6" ), Color::Transparent, Text::Shadow } }, - { "keyword2", { Color( "#8be9fd" ), Color::Transparent, Text::Shadow } }, - { "keyword3", { Color( "#ffb86c" ), Color::Transparent, Text::Shadow } }, - { "number", Color( "#ffd24a" ) }, - { "literal", { Color( "#f1fa8c" ), Color::Transparent, Text::Shadow } }, - { "string", Color( "#ffcd8b" ) }, - { "operator", Color( "#51f0e7" ) }, - { "function", { Color( "#00dc7f" ), Color::Transparent, Text::Shadow } }, - { "link", { Color( "#6ae0f9" ), Color::Transparent, Text::Shadow } }, - { "link_hover", { Color::Transparent, Color::Transparent, Text::Underlined } }, - }, - { { "background", Color( "#282a36" ) }, - { "text", Color( "#e1e1e6" ) }, - { "caret", Color( "#93DDFA" ) }, - { "selection", Color( "#394484" ) }, - { "line_highlight", Color( "#2d303d" ) }, - { "line_number", Color( "#525259" ) }, - { "line_number2", Color( "#83838f" ) }, - // eepp colors - { "gutter_background", Color( "#282a36" ) }, - { "whitespace", Color( "#394484" ) }, - { "line_break_column", Color( "#54575b99" ) }, - { "matching_bracket", Color( "#FFFFFF33" ) }, - { "matching_selection", Color( "#3e596e" ) }, - { "matching_search", Color( "#181b1e" ) }, - { "suggestion", { Color( "#e1e1e6" ), Color( "#1d1f27" ), Text::Regular } }, - { "suggestion_scrollbar", { Color( "#3daee9" ) } }, - { "suggestion_selected", { Color( "#ffffff" ), Color( "#2f3240" ), Text::Regular } }, - { "error", { Color::Red } }, - { "warning", { Color::Yellow } }, - { "notice", Color( "#8abdff" ) }, - { "selection_region", Color( "#39448477" ) }, - // minimap colors - { "minimap_background", Color( "#282a36AA" ) }, - { "minimap_current_line", Color( "#93DDFA40" ) }, - { "minimap_hover", Color( "#FFFFFF1A" ) }, - { "minimap_selection", Color( "#8abdff80" ) }, - { "minimap_highlight", Color( "#FFFF0040" ) }, - { "minimap_visible_area", Color( "#FFFFFF0A" ) } } }; + return { + "eepp", + { + { "normal"_sst, Color( "#e1e1e6" ) }, + { "symbol"_sst, Color( "#e1e1e6" ) }, + { "comment"_sst, Color( "#cd8b00" ) }, + { "keyword"_sst, { Color( "#ff79c6" ), Color::Transparent, Text::Shadow } }, + { "keyword2"_sst, { Color( "#8be9fd" ), Color::Transparent, Text::Shadow } }, + { "keyword3"_sst, { Color( "#ffb86c" ), Color::Transparent, Text::Shadow } }, + { "number"_sst, Color( "#ffd24a" ) }, + { "literal"_sst, { Color( "#f1fa8c" ), Color::Transparent, Text::Shadow } }, + { "string"_sst, Color( "#ffcd8b" ) }, + { "operator"_sst, Color( "#51f0e7" ) }, + { "function"_sst, { Color( "#00dc7f" ), Color::Transparent, Text::Shadow } }, + { "link"_sst, { Color( "#6ae0f9" ), Color::Transparent, Text::Shadow } }, + { "link_hover"_sst, { Color::Transparent, Color::Transparent, Text::Underlined } }, + }, + { { "background"_sst, Color( "#282a36" ) }, + { "text"_sst, Color( "#e1e1e6" ) }, + { "caret"_sst, Color( "#93DDFA" ) }, + { "selection"_sst, Color( "#394484" ) }, + { "line_highlight"_sst, Color( "#2d303d" ) }, + { "line_number"_sst, Color( "#525259" ) }, + { "line_number2"_sst, Color( "#83838f" ) }, + // eepp colors + { "gutter_background"_sst, Color( "#282a36" ) }, + { "whitespace"_sst, Color( "#394484" ) }, + { "line_break_column"_sst, Color( "#54575b99" ) }, + { "matching_bracket"_sst, Color( "#FFFFFF33" ) }, + { "matching_selection"_sst, Color( "#3e596e" ) }, + { "matching_search"_sst, Color( "#181b1e" ) }, + { "suggestion"_sst, { Color( "#e1e1e6" ), Color( "#1d1f27" ), Text::Regular } }, + { "suggestion_scrollbar"_sst, { Color( "#3daee9" ) } }, + { "suggestion_selected"_sst, { Color( "#ffffff" ), Color( "#2f3240" ), Text::Regular } }, + { "error"_sst, { Color::Red } }, + { "warning"_sst, { Color::Yellow } }, + { "notice"_sst, Color( "#8abdff" ) }, + { "selection_region"_sst, Color( "#39448477" ) }, + // minimap colors + { "minimap_background"_sst, Color( "#282a36AA" ) }, + { "minimap_current_line"_sst, Color( "#93DDFA40" ) }, + { "minimap_hover"_sst, Color( "#FFFFFF1A" ) }, + { "minimap_selection"_sst, Color( "#8abdff80" ) }, + { "minimap_highlight"_sst, Color( "#FFFF0040" ) }, + { "minimap_visible_area"_sst, Color( "#FFFFFF0A" ) } } }; } -SyntaxColorScheme::Style parseStyle( - const std::string& value, bool* colorWasSet = nullptr, - const UnorderedMap* syntaxColors = nullptr ) { +SyntaxColorScheme::Style +parseStyle( const std::string& value, bool* colorWasSet = nullptr, + const UnorderedMap* syntaxColors = nullptr ) { auto values = String::split( value, ',' ); SyntaxColorScheme::Style style; bool colorSet = false; @@ -144,12 +145,12 @@ std::vector SyntaxColorScheme::loadFromStream( IOStream& stre std::string value( ini.getValue( keyIdx, valueIdx ) ); if ( !value.empty() ) { SyntaxColorScheme::Style style = parseStyle( value ); - if ( refColorScheme.mSyntaxColors.find( valueName ) != + if ( refColorScheme.mSyntaxColors.find( toSyntaxStyleType( valueName ) ) != refColorScheme.mSyntaxColors.end() ) { - colorScheme.setSyntaxStyle( valueName, style ); - } else if ( refColorScheme.mEditorColors.find( valueName ) != + colorScheme.setSyntaxStyle( toSyntaxStyleType( valueName ), style ); + } else if ( refColorScheme.mEditorColors.find( toSyntaxStyleType( valueName ) ) != refColorScheme.mEditorColors.end() ) { - colorScheme.setEditorSyntaxStyle( valueName, style ); + colorScheme.setEditorSyntaxStyle( toSyntaxStyleType( valueName ), style ); } } } @@ -192,98 +193,100 @@ std::vector SyntaxColorScheme::loadFromPack( Pack* pack, SyntaxColorScheme::SyntaxColorScheme() {} SyntaxColorScheme::SyntaxColorScheme( const std::string& name, - const UnorderedMap& syntaxColors, - const UnorderedMap& editorColors ) : + const UnorderedMap& syntaxColors, + const UnorderedMap& editorColors ) : mName( name ), mSyntaxColors( syntaxColors ), mEditorColors( editorColors ) {} static const SyntaxColorScheme::Style StyleEmpty = { Color::Transparent }; static const SyntaxColorScheme StyleDefault = SyntaxColorScheme::getDefault(); -const SyntaxColorScheme::Style& SyntaxColorScheme::getSyntaxStyle( const std::string& type ) const { +const SyntaxColorScheme::Style& +SyntaxColorScheme::getSyntaxStyle( const SyntaxStyleType& type ) const { auto it = mSyntaxColors.find( type ); if ( it != mSyntaxColors.end() ) return it->second; - else if ( type == "keyword3" ) - return getSyntaxStyle( "symbol" ); - else if ( type == "link" || type == "link_hover" ) - return getSyntaxStyle( "function" ); - else if ( type == "error" || type == "warning" || type == "notice" ) + else if ( type == "keyword3"_sst ) + return getSyntaxStyle( "symbol"_sst ); + else if ( type == "link"_sst || type == "link_hover"_sst ) + return getSyntaxStyle( "function"_sst ); + else if ( type == "error"_sst || type == "warning"_sst || type == "notice"_sst ) return getEditorSyntaxStyle( type ); else { auto foundIt = mStyleCache.find( type ); if ( foundIt != mStyleCache.end() ) return foundIt->second; - bool colorWasSet; + /*bool colorWasSet; mStyleCache[type] = parseStyle( type, &colorWasSet, &mSyntaxColors ); if ( !colorWasSet ) { - auto normalStyle = mSyntaxColors.find( "normal" ); + auto normalStyle = mSyntaxColors.find( "normal"_sst ); if ( normalStyle != mSyntaxColors.end() ) { mStyleCache[type].color = normalStyle->second.color; } } - return mStyleCache[type]; + return mStyleCache[type];*/ } return StyleEmpty; } -bool SyntaxColorScheme::hasSyntaxStyle( const std::string& type ) const { +bool SyntaxColorScheme::hasSyntaxStyle( const SyntaxStyleType& type ) const { return mSyntaxColors.find( type ) != mSyntaxColors.end(); } -void SyntaxColorScheme::setSyntaxStyles( const UnorderedMap& styles ) { +void SyntaxColorScheme::setSyntaxStyles( const UnorderedMap& styles ) { mSyntaxColors.insert( styles.begin(), styles.end() ); } -void SyntaxColorScheme::setSyntaxStyle( const std::string& type, +void SyntaxColorScheme::setSyntaxStyle( const SyntaxStyleType& type, const SyntaxColorScheme::Style& style ) { mSyntaxColors[type] = style; } const SyntaxColorScheme::Style& -SyntaxColorScheme::getEditorSyntaxStyle( const std::string& type ) const { +SyntaxColorScheme::getEditorSyntaxStyle( const SyntaxStyleType& type ) const { auto it = mEditorColors.find( type ); if ( it != mEditorColors.end() ) return it->second; - if ( type == "gutter_background" || type == "minimap_background" ) - return getEditorSyntaxStyle( "background" ); - else if ( type == "whitespace" || type == "line_break_column" || type == "matching_bracket" || - type == "matching_selection" || type == "selection_region" ) - return getEditorSyntaxStyle( "selection" ); - else if ( type == "suggestion" ) - return StyleDefault.getEditorSyntaxStyle( "suggestion" ); - else if ( type == "suggestion_selected" ) - return StyleDefault.getEditorSyntaxStyle( "suggestion_selected" ); - else if ( type == "error" ) - return StyleDefault.getEditorSyntaxStyle( "error" ); - else if ( type == "warning" ) - return StyleDefault.getEditorSyntaxStyle( "warning" ); - else if ( type == "notice" ) - return StyleDefault.getEditorSyntaxStyle( "notice" ); - else if ( type == "minimap_current_line" ) - return StyleDefault.getEditorSyntaxStyle( "minimap_current_line" ); - else if ( type == "minimap_hover" ) - return StyleDefault.getEditorSyntaxStyle( "minimap_hover" ); - else if ( type == "minimap_selection" ) - return StyleDefault.getEditorSyntaxStyle( "minimap_selection" ); - else if ( type == "minimap_highlight" ) - return StyleDefault.getEditorSyntaxStyle( "minimap_highlight" ); - else if ( type == "minimap_visible_area" ) - return StyleDefault.getEditorSyntaxStyle( "minimap_visible_area" ); - else if ( type == "suggestion_scrollbar" ) - return getEditorSyntaxStyle( "line_highlight" ); + if ( type == "gutter_background"_sst || type == "minimap_background"_sst ) + return getEditorSyntaxStyle( "background"_sst ); + else if ( type == "whitespace"_sst || type == "line_break_column"_sst || + type == "matching_bracket"_sst || type == "matching_selection"_sst || + type == "selection_region"_sst ) + return getEditorSyntaxStyle( "selection"_sst ); + else if ( type == "suggestion"_sst ) + return StyleDefault.getEditorSyntaxStyle( "suggestion"_sst ); + else if ( type == "suggestion_selected"_sst ) + return StyleDefault.getEditorSyntaxStyle( "suggestion_selected"_sst ); + else if ( type == "error"_sst ) + return StyleDefault.getEditorSyntaxStyle( "error"_sst ); + else if ( type == "warning"_sst ) + return StyleDefault.getEditorSyntaxStyle( "warning"_sst ); + else if ( type == "notice"_sst ) + return StyleDefault.getEditorSyntaxStyle( "notice"_sst ); + else if ( type == "minimap_current_line"_sst ) + return StyleDefault.getEditorSyntaxStyle( "minimap_current_line"_sst ); + else if ( type == "minimap_hover"_sst ) + return StyleDefault.getEditorSyntaxStyle( "minimap_hover"_sst ); + else if ( type == "minimap_selection"_sst ) + return StyleDefault.getEditorSyntaxStyle( "minimap_selection"_sst ); + else if ( type == "minimap_highlight"_sst ) + return StyleDefault.getEditorSyntaxStyle( "minimap_highlight"_sst ); + else if ( type == "minimap_visible_area"_sst ) + return StyleDefault.getEditorSyntaxStyle( "minimap_visible_area"_sst ); + else if ( type == "suggestion_scrollbar"_sst ) + return getEditorSyntaxStyle( "line_highlight"_sst ); return StyleEmpty; } -const Color& SyntaxColorScheme::getEditorColor( const std::string& type ) const { +const Color& SyntaxColorScheme::getEditorColor( const SyntaxStyleType& type ) const { return getEditorSyntaxStyle( type ).color; } void SyntaxColorScheme::setEditorSyntaxStyles( - const UnorderedMap& styles ) { + const EE::UnorderedMap& styles ) { mEditorColors.insert( styles.begin(), styles.end() ); } -void SyntaxColorScheme::setEditorSyntaxStyle( const std::string& type, +void SyntaxColorScheme::setEditorSyntaxStyle( const SyntaxStyleType& type, const SyntaxColorScheme::Style& style ) { mEditorColors[type] = style; } @@ -295,4 +298,5 @@ const std::string& SyntaxColorScheme::getName() const { void SyntaxColorScheme::setName( const std::string& name ) { mName = name; } + }}} // namespace EE::UI::Doc diff --git a/src/eepp/ui/doc/syntaxdefinition.cpp b/src/eepp/ui/doc/syntaxdefinition.cpp index 12e6917c0..54bea6ac1 100644 --- a/src/eepp/ui/doc/syntaxdefinition.cpp +++ b/src/eepp/ui/doc/syntaxdefinition.cpp @@ -17,10 +17,14 @@ SyntaxDefinition::SyntaxDefinition( const std::string& languageName, mLanguageId( String::hash( String::toLower( languageName ) ) ), mFiles( files ), mPatterns( patterns ), - mSymbols( symbols ), + mSymbolNames( symbols ), mComment( comment ), mHeaders( headers ), - mLSPName( lspName.empty() ? String::toLower( mLanguageName ) : lspName ) {} + mLSPName( lspName.empty() ? String::toLower( mLanguageName ) : lspName ) { + mSymbols.reserve( symbols.size() ); + for ( const auto& symbol : symbols ) + mSymbols.insert( { symbol.first, toSyntaxStyleType( symbol.second ) } ); +} const std::vector& SyntaxDefinition::getFiles() const { return mFiles; @@ -37,7 +41,8 @@ std::string SyntaxDefinition::getFileExtension() const { return ""; } -std::vector SyntaxDefinition::getPatternsOfType( const std::string& type ) const { +std::vector +SyntaxDefinition::getPatternsOfType( const SyntaxStyleType& type ) const { std::vector patterns; for ( const auto& pattern : mPatterns ) { if ( pattern.types.size() == 1 && pattern.types[0] == type ) @@ -59,6 +64,10 @@ void SyntaxDefinition::setExtensionPriority( bool hasExtensionPriority ) { mHasExtensionPriority = hasExtensionPriority; } +std::unordered_map SyntaxDefinition::getSymbolNames() const { + return mSymbolNames; +} + const std::vector& SyntaxDefinition::getPatterns() const { return mPatterns; } @@ -67,15 +76,15 @@ const std::string& SyntaxDefinition::getComment() const { return mComment; } -const std::unordered_map& SyntaxDefinition::getSymbols() const { +const std::unordered_map& SyntaxDefinition::getSymbols() const { return mSymbols; } -std::string SyntaxDefinition::getSymbol( const std::string& symbol ) const { +SyntaxStyleType SyntaxDefinition::getSymbol( const std::string& symbol ) const { auto it = mSymbols.find( symbol ); if ( it != mSymbols.end() ) return it->second; - return ""; + return SyntaxStyleEmpty(); } SyntaxDefinition& SyntaxDefinition::addFileType( const std::string& fileType ) { @@ -105,16 +114,21 @@ SyntaxDefinition::addPatternsToFront( const std::vector& patterns } SyntaxDefinition& SyntaxDefinition::addSymbol( const std::string& symbolName, - const std::string& typeName ) { + const SyntaxStyleType& typeName ) { mSymbols[symbolName] = typeName; return *this; } SyntaxDefinition& SyntaxDefinition::addSymbols( const std::vector& symbolNames, - const std::string& typeName ) { - for ( auto& symbol : symbolNames ) { + const SyntaxStyleType& typeName ) { + for ( auto& symbol : symbolNames ) addSymbol( symbol, typeName ); - } + return *this; +} + +SyntaxDefinition& +SyntaxDefinition::setSymbols( const std::unordered_map& symbols ) { + mSymbols = symbols; return *this; } diff --git a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp index fa04ee1a9..1101228d8 100644 --- a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp +++ b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp @@ -276,8 +276,9 @@ static void addTypeScript() { { { "[%a_][%w_$]*%f[(]" }, "function" }, { { "[%a_][%w_]*" }, "symbol" }, }, - ts.getSymbols(), + {}, "//" } ) + .setSymbols( ts.getSymbols() ) .setAutoCloseXMLTags( true ); ; } @@ -1781,7 +1782,7 @@ static json toJson( const SyntaxDefinition& def ) { } if ( !def.getSymbols().empty() ) { j["symbols"] = json::array(); - for ( const auto& sym : def.getSymbols() ) + for ( const auto& sym : def.getSymbolNames() ) j["symbols"].emplace_back( json{ json{ sym.first, sym.second } } ); } @@ -1879,12 +1880,12 @@ namespace EE { namespace UI { namespace Doc { namespace Language { // patterns buf += "{\n"; for ( const auto& pattern : def.getPatterns() ) - buf += "{ " + join( pattern.patterns ) + ", " + join( pattern.types, true, true ) + + buf += "{ " + join( pattern.patterns ) + ", " + join( pattern.typesNames, true, true ) + str( pattern.syntax, ", ", "", false ) + " },\n"; buf += "\n},\n"; // symbols buf += "{\n"; - for ( const auto& symbol : def.getSymbols() ) + for ( const auto& symbol : def.getSymbolNames() ) buf += "{ " + str( symbol.first ) + " , " + str( symbol.second ) + " },\n"; buf += "\n},\n"; buf += str( def.getComment(), "", "", true ) + ",\n"; diff --git a/src/eepp/ui/doc/syntaxhighlighter.cpp b/src/eepp/ui/doc/syntaxhighlighter.cpp index 13ac1ae3c..cb6a131aa 100644 --- a/src/eepp/ui/doc/syntaxhighlighter.cpp +++ b/src/eepp/ui/doc/syntaxhighlighter.cpp @@ -14,7 +14,7 @@ static constexpr void _hash( Uint64& signature, const String::HashType& val ) { Uint64 TokenizedLine::calcSignature( const std::vector& tokens ) { Uint64 signature = 5381; for ( const auto& token : tokens ) - _hash( signature, String::hash( token.type ) ); + _hash( signature, SyntaxStyleTypeHash( token.type ) ); return signature; } @@ -56,7 +56,7 @@ TokenizedLine SyntaxHighlighter::tokenizeLine( const size_t& line, const Uint64& while ( textSize > 0 ) { size_t chunkSize = textSize > mMaxTokenizationLength ? mMaxTokenizationLength : textSize; - SyntaxTokenPosition token{ "normal", pos, chunkSize }; + SyntaxTokenPosition token{ SyntaxStyleTypes::Normal, pos, chunkSize }; token.len = ln.size(); tokenizedLine.tokens.emplace_back( token ); textSize -= chunkSize; @@ -123,7 +123,7 @@ void SyntaxHighlighter::setMaxTokenizationLength( const Int64& maxTokenizationLe const std::vector& SyntaxHighlighter::getLine( const size_t& index ) { if ( mDoc->getSyntaxDefinition().getPatterns().empty() ) { - static std::vector noHighlightVector = { { "normal", 0 } }; + static std::vector noHighlightVector = { { SyntaxStyleTypes::Normal, 0 } }; noHighlightVector[0].len = mDoc->line( index ).size(); return noHighlightVector; } @@ -204,19 +204,19 @@ SyntaxHighlighter::getSyntaxDefinitionFromTextPosition( const TextPosition& posi return *state.currentSyntax; } -std::string SyntaxHighlighter::getTokenTypeAt( const TextPosition& pos ) { +SyntaxStyleType SyntaxHighlighter::getTokenTypeAt( const TextPosition& pos ) { if ( !pos.isValid() || pos.line() < 0 || pos.line() >= (Int64)mDoc->linesCount() ) - return "normal"; + return SyntaxStyleTypes::Normal; auto tokens = getLine( pos.line() ); if ( tokens.empty() ) - return "normal"; + return SyntaxStyleTypes::Normal; Int64 col = 0; for ( const auto& token : tokens ) { col += token.len; if ( col > pos.column() ) return token.type; } - return "normal"; + return SyntaxStyleTypes::Normal; } SyntaxTokenPosition SyntaxHighlighter::getTokenPositionAt( const TextPosition& pos ) { diff --git a/src/eepp/ui/doc/syntaxtokenizer.cpp b/src/eepp/ui/doc/syntaxtokenizer.cpp index 922f6cd44..24c547ffd 100644 --- a/src/eepp/ui/doc/syntaxtokenizer.cpp +++ b/src/eepp/ui/doc/syntaxtokenizer.cpp @@ -31,7 +31,8 @@ static int isInMultiByteCodePoint( const char* text, const size_t& textSize, con } template -static void pushToken( std::vector& tokens, const std::string& type, const std::string& text ) { +static void pushToken( std::vector& tokens, const SyntaxStyleType& type, + const std::string& text ) { if ( !tokens.empty() && ( tokens[tokens.size() - 1].type == type ) ) { size_t tpos = tokens.size() - 1; tokens[tpos].type = type; @@ -145,7 +146,7 @@ _tokenize( const SyntaxDefinition& syntax, const std::string& text, const Uint32 size_t numMatches; if ( syntax.getPatterns().empty() ) { - pushToken( tokens, "normal", text ); + pushToken( tokens, SyntaxStyleTypes::Normal, text ); return std::make_pair( std::move( tokens ), SYNTAX_TOKENIZER_STATE_NONE ); } @@ -278,13 +279,14 @@ _tokenize( const SyntaxDefinition& syntax, const std::string& text, const Uint32 } std::string patternText( text.substr( start, end - start ) ); - std::string type = curState.currentSyntax->getSymbol( patternText ); + SyntaxStyleType type = curState.currentSyntax->getSymbol( patternText ); if ( !skipSubSyntaxSeparator || pattern.syntax.empty() ) { pushToken( tokens, - type.empty() ? ( curMatch < pattern.types.size() - ? pattern.types[curMatch] - : pattern.types[0] ) - : type, + type == SyntaxStyleEmpty() + ? ( curMatch < pattern.types.size() + ? pattern.types[curMatch] + : pattern.types[0] ) + : type, patternText ); } @@ -322,13 +324,14 @@ _tokenize( const SyntaxDefinition& syntax, const std::string& text, const Uint32 end = start + ( strEnd - strStart ); } std::string patternText( text.substr( start, end - start ) ); - std::string type = curState.currentSyntax->getSymbol( patternText ); + SyntaxStyleType type = curState.currentSyntax->getSymbol( patternText ); if ( !skipSubSyntaxSeparator || pattern.syntax.empty() ) { pushToken( tokens, - type.empty() ? ( curMatch < pattern.types.size() - ? pattern.types[curMatch] - : pattern.types[0] ) - : type, + type == SyntaxStyleEmpty() + ? ( curMatch < pattern.types.size() + ? pattern.types[curMatch] + : pattern.types[0] ) + : type, patternText ); } if ( !pattern.syntax.empty() ) { @@ -350,7 +353,7 @@ _tokenize( const SyntaxDefinition& syntax, const std::string& text, const Uint32 String::utf8Next( strEnd ); int dist = strEnd - strStart; if ( dist > 0 ) { - pushToken( tokens, "normal", text.substr( i, dist ) ); + pushToken( tokens, SyntaxStyleTypes::Normal, text.substr( i, dist ) ); i += dist; } else { Log::error( "Error parsing \"%s\" using syntax: %s", text.c_str(), diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index 53571a889..c32e8eb32 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -532,7 +532,7 @@ TextDocument::LoadStatus TextDocument::reload() { } bool TextDocument::save( const std::string& path ) { - if ( path.empty() || mDefaultFileName == path || mSaving ) + if ( path.empty() || mDefaultFileName == path || mSaving ) return false; mSaving = true; if ( FileSystem::fileWrite( path, "" ) ) { @@ -2548,7 +2548,7 @@ static inline void changeDepth( SyntaxHighlighter* highlighter, int& depth, cons int dir ) { if ( highlighter ) { auto type = highlighter->getTokenTypeAt( pos ); - if ( type != "comment" && type != "string" ) + if ( type != "comment"_sst && type != "string"_sst ) depth += dir; } else { depth += dir; diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 27851003e..42810d8d4 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -286,7 +286,7 @@ void UICodeEditor::draw() { if ( mHighlightTextRange.isValid() && mHighlightTextRange.hasSelection() ) { drawTextRange( mHighlightTextRange, lineRange, startScroll, lineHeight, - mColorScheme.getEditorSyntaxStyle( "selection_region" ).color ); + mColorScheme.getEditorSyntaxStyle( "selection_region"_sst ).color ); } if ( mHighlightSelectionMatch && mDoc->hasSelection() && mDoc->getSelection().inSameLine() ) { @@ -783,24 +783,24 @@ const SyntaxColorScheme& UICodeEditor::getColorScheme() const { } void UICodeEditor::updateColorScheme() { - setBackgroundColor( mColorScheme.getEditorColor( "background" ) ); - setFontColor( mColorScheme.getEditorColor( "text" ) ); - mFontStyleConfig.setFontSelectionBackColor( mColorScheme.getEditorColor( "selection" ) ); - mLineNumberFontColor = mColorScheme.getEditorColor( "line_number" ); - mLineNumberActiveFontColor = mColorScheme.getEditorColor( "line_number2" ); - mLineNumberBackgroundColor = mColorScheme.getEditorColor( "gutter_background" ); - mCurrentLineBackgroundColor = mColorScheme.getEditorColor( "line_highlight" ); - mCaretColor = mColorScheme.getEditorColor( "caret" ); - mWhitespaceColor = mColorScheme.getEditorColor( "whitespace" ); - mLineBreakColumnColor = mColorScheme.getEditorColor( "line_break_column" ); - mMatchingBracketColor = mColorScheme.getEditorColor( "matching_bracket" ); - mSelectionMatchColor = mColorScheme.getEditorColor( "matching_selection" ); - mMinimapBackgroundColor = mColorScheme.getEditorColor( "minimap_background" ); - mMinimapVisibleAreaColor = mColorScheme.getEditorColor( "minimap_visible_area" ); - mMinimapCurrentLineColor = mColorScheme.getEditorColor( "minimap_current_line" ); - mMinimapHoverColor = mColorScheme.getEditorColor( "minimap_hover" ); - mMinimapHighlightColor = mColorScheme.getEditorColor( "minimap_highlight" ); - mMinimapSelectionColor = mColorScheme.getEditorColor( "minimap_selection" ); + setBackgroundColor( mColorScheme.getEditorColor( "background"_sst ) ); + setFontColor( mColorScheme.getEditorColor( "text"_sst ) ); + mFontStyleConfig.setFontSelectionBackColor( mColorScheme.getEditorColor( "selection"_sst ) ); + mLineNumberFontColor = mColorScheme.getEditorColor( "line_number"_sst ); + mLineNumberActiveFontColor = mColorScheme.getEditorColor( "line_number2"_sst ); + mLineNumberBackgroundColor = mColorScheme.getEditorColor( "gutter_background"_sst ); + mCurrentLineBackgroundColor = mColorScheme.getEditorColor( "line_highlight"_sst ); + mCaretColor = mColorScheme.getEditorColor( "caret"_sst ); + mWhitespaceColor = mColorScheme.getEditorColor( "whitespace"_sst ); + mLineBreakColumnColor = mColorScheme.getEditorColor( "line_break_column"_sst ); + mMatchingBracketColor = mColorScheme.getEditorColor( "matching_bracket"_sst ); + mSelectionMatchColor = mColorScheme.getEditorColor( "matching_selection"_sst ); + mMinimapBackgroundColor = mColorScheme.getEditorColor( "minimap_background"_sst ); + mMinimapVisibleAreaColor = mColorScheme.getEditorColor( "minimap_visible_area"_sst ); + mMinimapCurrentLineColor = mColorScheme.getEditorColor( "minimap_current_line"_sst ); + mMinimapHoverColor = mColorScheme.getEditorColor( "minimap_hover"_sst ); + mMinimapHighlightColor = mColorScheme.getEditorColor( "minimap_highlight"_sst ); + mMinimapSelectionColor = mColorScheme.getEditorColor( "minimap_selection"_sst ); } void UICodeEditor::setColorScheme( const SyntaxColorScheme& colorScheme ) { @@ -2909,8 +2909,8 @@ void UICodeEditor::drawLineText( const Int64& line, Vector2f position, const Flo SyntaxColorScheme::Style linkStyle = style; - if ( mColorScheme.hasSyntaxStyle( "link_hover" ) ) { - linkStyle = mColorScheme.getSyntaxStyle( "link_hover" ); + if ( mColorScheme.hasSyntaxStyle( "link_hover"_sst ) ) { + linkStyle = mColorScheme.getSyntaxStyle( "link_hover"_sst ); if ( linkStyle.color != Color::Transparent ) { fontStyle.FontColor = Color( linkStyle.color ).blendAlpha( mAlpha ); } @@ -3387,7 +3387,7 @@ Rectf UICodeEditor::getMinimapRect( const Vector2f& start ) const { Sizef( w, h ) ); } -static const std::string SYNTAX_NORMAL = "normal"; +static const SyntaxStyleType SYNTAX_NORMAL = SyntaxStyleTypes::Normal; void UICodeEditor::drawMinimap( const Vector2f& start, const std::pair& lineRange ) { @@ -3427,25 +3427,23 @@ void UICodeEditor::drawMinimap( const Vector2f& start, } BR->quadsSetColor( Color( mMinimapVisibleAreaColor ).blendAlpha( mAlpha ) ); - BR->batchQuad( - { { rect.Left, visibleY }, Sizef( rect.getWidth(), scrollerHeight ) } ); + BR->batchQuad( { { rect.Left, visibleY }, Sizef( rect.getWidth(), scrollerHeight ) } ); if ( mMinimapHover || mMinimapDragging ) { BR->quadsSetColor( Color( mMinimapHoverColor ).blendAlpha( mAlpha ) ); - BR->batchQuad( - { { rect.Left, visibleY }, Sizef( rect.getWidth(), scrollerHeight ) } ); + BR->batchQuad( { { rect.Left, visibleY }, Sizef( rect.getWidth(), scrollerHeight ) } ); } Float gutterWidth = PixelDensity::dpToPx( mMinimapConfig.gutterWidth ); Float lineY = rect.Top; - const std::string* batchSyntaxType = &SYNTAX_NORMAL; + const auto* batchSyntaxType = &SYNTAX_NORMAL; Color color = mColorScheme.getSyntaxStyle( *batchSyntaxType ).color; color.a *= 0.5f; Float batchWidth = 0; Float batchStart = rect.Left; Float minimapCutoffX = rect.Left + rect.getWidth(); Float widthScale = charSpacing / getGlyphWidth(); - auto flushBatch = [&]( const std::string& type ) { + auto flushBatch = [&]( const SyntaxStyleType& type ) { Color oldColor = color; color = mColorScheme.getSyntaxStyle( *batchSyntaxType ).color; if ( mMinimapConfig.syntaxHighlight && color != Color::Transparent ) { diff --git a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp index 4bb0d64f7..3c4675b53 100644 --- a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp +++ b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp @@ -615,9 +615,9 @@ void AutoCompletePlugin::drawSignatureHelp( UICodeEditor* editor, const Vector2f TextDocument& doc = editor->getDocument(); Primitives primitives; const SyntaxColorScheme& scheme = editor->getColorScheme(); - const auto& normalStyle = scheme.getEditorSyntaxStyle( "suggestion" ); - const auto& selectedStyle = scheme.getEditorSyntaxStyle( "suggestion_selected" ); - const auto& matchingSelection = scheme.getEditorSyntaxStyle( "matching_selection" ); + const auto& normalStyle = scheme.getEditorSyntaxStyle( "suggestion"_sst ); + const auto& selectedStyle = scheme.getEditorSyntaxStyle( "suggestion_selected"_sst ); + const auto& matchingSelection = scheme.getEditorSyntaxStyle( "matching_selection"_sst ); auto curSigIdx = mSignatureHelpSelected != -1 ? mSignatureHelpSelected : mSignatureHelp.activeSignature; @@ -707,8 +707,8 @@ void AutoCompletePlugin::postDraw( UICodeEditor* editor, const Vector2f& startSc TextPosition start = doc.startOfWord( editor->getDocument().startOfWord( cursor ) ); Primitives primitives; const SyntaxColorScheme& scheme = editor->getColorScheme(); - const auto& normalStyle = scheme.getEditorSyntaxStyle( "suggestion" ); - const auto& selectedStyle = scheme.getEditorSyntaxStyle( "suggestion_selected" ); + const auto& normalStyle = scheme.getEditorSyntaxStyle( "suggestion"_sst ); + const auto& selectedStyle = scheme.getEditorSyntaxStyle( "suggestion_selected"_sst ); bool drawUp = true; mRowHeight = lineHeight + mBoxPadding.Top + mBoxPadding.Bottom; @@ -729,7 +729,7 @@ void AutoCompletePlugin::postDraw( UICodeEditor* editor, const Vector2f& startSc size_t largestString = 0; size_t max = eemin( mSuggestionsMaxVisible, suggestions.size() ); - const auto& barStyle = scheme.getEditorSyntaxStyle( "suggestion_scrollbar" ); + const auto& barStyle = scheme.getEditorSyntaxStyle( "suggestion_scrollbar"_sst ); if ( cursorPos.y + mRowHeight * max > editor->getPixelsSize().getHeight() ) { cursorPos.y -= lineHeight + mRowHeight * max; drawUp = false; diff --git a/src/tools/ecode/plugins/linter/linterplugin.cpp b/src/tools/ecode/plugins/linter/linterplugin.cpp index 033e93502..f336dfe60 100644 --- a/src/tools/ecode/plugins/linter/linterplugin.cpp +++ b/src/tools/ecode/plugins/linter/linterplugin.cpp @@ -918,16 +918,16 @@ void LinterPlugin::runLinter( std::shared_ptr doc, const Linter& l } } -std::string LinterPlugin::getMatchString( const LinterType& type ) { +SyntaxStyleType LinterPlugin::getMatchString( const LinterType& type ) { switch ( type ) { case LinterType::Warning: - return "warning"; + return "warning"_sst; case LinterType::Notice: - return "notice"; + return "notice"_sst; default: break; } - return "error"; + return "error"_sst; } void LinterPlugin::drawAfterLineText( UICodeEditor* editor, const Int64& index, Vector2f position, @@ -991,7 +991,7 @@ void LinterPlugin::drawAfterLineText( UICodeEditor* editor, const Int64& index, if ( !quickFixRendered && doc->getSelection().start().line() == index && !match.diagnostic.codeActions.empty() ) { rLineWidth = editor->getLineWidth( index ); - Color wcolor( editor->getColorScheme().getEditorSyntaxStyle( "warning" ).color ); + Color wcolor( editor->getColorScheme().getEditorSyntaxStyle( "warning"_sst ).color ); if ( nullptr == mLightbulbIcon ) { mLightbulbIcon = editor->getUISceneNode()->getUIIconThemeManager()->findIcon( "lightbulb-autofix" ); diff --git a/src/tools/ecode/plugins/linter/linterplugin.hpp b/src/tools/ecode/plugins/linter/linterplugin.hpp index d70538b6f..e407ef071 100644 --- a/src/tools/ecode/plugins/linter/linterplugin.hpp +++ b/src/tools/ecode/plugins/linter/linterplugin.hpp @@ -151,7 +151,7 @@ class LinterPlugin : public Plugin { void invalidateEditors( TextDocument* doc ); - std::string getMatchString( const LinterType& type ); + SyntaxStyleType getMatchString( const LinterType& type ); void loadLinterConfig( const std::string& path, bool updateConfigFile ); diff --git a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp index 531256a37..ab4a42974 100644 --- a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp +++ b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp @@ -205,8 +205,8 @@ UISceneNode* LSPDocumentClient::getUISceneNode() { return server->getManager()->getPluginManager()->getUISceneNode(); } -static std::string semanticTokenTypeToSyntaxType( const std::string& type, - const SyntaxDefinition& ) { +static SyntaxStyleType semanticTokenTypeToSyntaxType( const std::string& type, + const SyntaxDefinition& ) { switch ( String::hash( type ) ) { case SemanticTokenTypes::Namespace: case SemanticTokenTypes::Type: @@ -215,40 +215,40 @@ static std::string semanticTokenTypeToSyntaxType( const std::string& type, case SemanticTokenTypes::Interface: case SemanticTokenTypes::Struct: case SemanticTokenTypes::TypeParameter: - return "keyword2"; + return "keyword2"_sst; case SemanticTokenTypes::Parameter: - return "keyword3"; + return "keyword3"_sst; case SemanticTokenTypes::Variable: - return "symbol"; + return "symbol"_sst; case SemanticTokenTypes::Property: - return "symbol"; + return "symbol"_sst; case SemanticTokenTypes::EnumMember: case SemanticTokenTypes::Event: - return "keyword2"; + return "keyword2"_sst; case SemanticTokenTypes::Function: case SemanticTokenTypes::Method: case SemanticTokenTypes::Member: - return "function"; + return "function"_sst; case SemanticTokenTypes::Macro: - return "keyword2"; + return "keyword2"_sst; case SemanticTokenTypes::Keyword: case SemanticTokenTypes::Modifier: - return "keyword"; + return "keyword"_sst; case SemanticTokenTypes::Comment: - return "comment"; + return "comment"_sst; case SemanticTokenTypes::Str: - return "string"; + return "string"_sst; case SemanticTokenTypes::Number: case SemanticTokenTypes::Regexp: - return "number"; + return "number"_sst; case SemanticTokenTypes::Operator: - return "operator"; + return "operator"_sst; case SemanticTokenTypes::Decorator: - return "literal"; + return "literal"_sst; case SemanticTokenTypes::Unknown: break; }; - return "normal"; + return SyntaxStyleTypes::Normal; } void LSPDocumentClient::processTokens( const LSPSemanticTokensDelta& tokens, @@ -326,7 +326,7 @@ void LSPDocumentClient::highlight() { { semanticTokenTypeToSyntaxType( ltype, mDoc->getSyntaxDefinition() ), start, len } ); } else { - line->tokens.push_back( { "normal", start, len } ); + line->tokens.push_back( { SyntaxStyleTypes::Normal, start, len } ); } line->hash = mDoc->line( currentLine ).getHash(); line->updateSignature(); diff --git a/src/tools/ecode/plugins/xmltools/xmltoolsplugin.cpp b/src/tools/ecode/plugins/xmltools/xmltoolsplugin.cpp index 981542ff4..86543f1d0 100644 --- a/src/tools/ecode/plugins/xmltools/xmltoolsplugin.cpp +++ b/src/tools/ecode/plugins/xmltools/xmltoolsplugin.cpp @@ -139,7 +139,7 @@ static bool isClosedTag( TextDocument* doc, TextPosition start ) { String::StringBaseType ch = doc->getChar( start ); if ( ch == '>' ) { auto tokenType = highlighter->getTokenTypeAt( start ); - if ( tokenType != "comment" && tokenType != "string" ) + if ( tokenType != "comment"_sst && tokenType != "string"_sst ) return prevChar == '/'; } start = doc->positionOffset( start, 1 ); @@ -328,7 +328,7 @@ void XMLToolsPlugin::drawBeforeLineText( UICodeEditor* editor, const Int64& inde if ( !isOverMatch( &editor->getDocument(), index ) ) return; Primitives p; - Color color( editor->getColorScheme().getEditorSyntaxStyle( "matching_bracket" ).color ); + Color color( editor->getColorScheme().getEditorSyntaxStyle( "matching_bracket"_sst ).color ); Color blendedColor( Color( color, 50 ) ); p.setColor( blendedColor ); @@ -349,7 +349,7 @@ void XMLToolsPlugin::minimapDrawAfterLineText( UICodeEditor* editor, const Int64 if ( !isOverMatch( &editor->getDocument(), index ) ) return; Primitives p; - Color color( editor->getColorScheme().getEditorSyntaxStyle( "matching_bracket" ).color ); + Color color( editor->getColorScheme().getEditorSyntaxStyle( "matching_bracket"_sst ).color ); Color blendedColor( Color( color, 50 ) ); p.setColor( blendedColor ); diff --git a/src/tools/ecode/uitreeviewglobalsearch.cpp b/src/tools/ecode/uitreeviewglobalsearch.cpp index 309383c84..0179d3058 100644 --- a/src/tools/ecode/uitreeviewglobalsearch.cpp +++ b/src/tools/ecode/uitreeviewglobalsearch.cpp @@ -197,7 +197,7 @@ void UITreeViewCellGlobalSearch::draw() { auto hspace = mTextBox->getFont()->getGlyph( L' ', mTextBox->getFontSize(), false, false ).advance; Primitives p; - p.setColor( pp->getColorScheme().getEditorSyntaxStyle( "selection" ).color ); + p.setColor( pp->getColorScheme().getEditorSyntaxStyle( "selection"_sst ).color ); Vector2f screenPos( mScreenPos ); if ( mTextBox->isType( UI_TYPE_CHECKBOX ) ) { UICheckBox* chk = mTextBox->asType();