diff --git a/include/eepp/ui/doc/syntaxhighlighter.hpp b/include/eepp/ui/doc/syntaxhighlighter.hpp index 54da12c6f..30b00d85a 100644 --- a/include/eepp/ui/doc/syntaxhighlighter.hpp +++ b/include/eepp/ui/doc/syntaxhighlighter.hpp @@ -12,7 +12,7 @@ struct EE_API TokenizedLine { String::HashType hash; std::vector tokens; Uint64 state{ SYNTAX_TOKENIZER_STATE_NONE }; - Uint64 signature { 0 }; + Uint64 signature{ 0 }; void updateSignature(); @@ -54,6 +54,8 @@ class EE_API SyntaxHighlighter { void moveHighlight( const Int64& fromLine, const Int64& numLines ); + Uint64 getTokenizedLineSignature( const size_t& index ); + protected: TextDocument* mDoc; std::unordered_map mLines; diff --git a/include/eepp/ui/uiconsole.hpp b/include/eepp/ui/uiconsole.hpp index 3f91721e1..c35838eb0 100644 --- a/include/eepp/ui/uiconsole.hpp +++ b/include/eepp/ui/uiconsole.hpp @@ -286,6 +286,9 @@ class EE_API UIConsole : public UIWidget, /** Add the GPU Extensions supported to the console */ void cmdGetGpuExtensions(); + /** Add command to grep the console log */ + void cmdGrep( const std::vector& params ); + void privPushText( const String& str ); void writeLog( const std::string& text ); diff --git a/src/eepp/ui/doc/syntaxhighlighter.cpp b/src/eepp/ui/doc/syntaxhighlighter.cpp index c2d2e88c8..8f4924e2b 100644 --- a/src/eepp/ui/doc/syntaxhighlighter.cpp +++ b/src/eepp/ui/doc/syntaxhighlighter.cpp @@ -89,6 +89,14 @@ void SyntaxHighlighter::moveHighlight( const Int64& fromLine, const Int64& numLi } } +Uint64 SyntaxHighlighter::getTokenizedLineSignature( const size_t& index ) { + Lock l( mLinesMutex ); + auto line = mLines.find( index ); + if ( line != mLines.end() ) + return line->second.signature; + return 0; +} + const std::vector& SyntaxHighlighter::getLine( const size_t& index ) { if ( mDoc->getSyntaxDefinition().getPatterns().empty() ) { static std::vector noHighlightVector = { { "normal", 0 } }; @@ -220,8 +228,9 @@ void SyntaxHighlighter::mergeLine( const size_t& line, const TokenizedLine& toke } } + size_t lastTokenPos = 0; for ( const auto& token : tokenization.tokens ) { - for ( size_t i = 0; i < tline.tokens.size(); ++i ) { + for ( size_t i = lastTokenPos; i < tline.tokens.size(); ++i ) { const auto ltoken = tline.tokens[i]; if ( token.pos >= ltoken.pos && token.pos + token.len <= ltoken.pos + ltoken.len ) { tline.tokens.erase( tline.tokens.begin() + i ); @@ -243,11 +252,13 @@ void SyntaxHighlighter::mergeLine( const size_t& line, const TokenizedLine& toke ( token.pos + token.len ) ) } ); } + lastTokenPos = i; break; } } } + tline.signature = tokenization.signature; Lock l( mLinesMutex ); mLines[line] = std::move( tline ); } diff --git a/src/eepp/ui/uiconsole.cpp b/src/eepp/ui/uiconsole.cpp index bb31bcf23..866751b32 100644 --- a/src/eepp/ui/uiconsole.cpp +++ b/src/eepp/ui/uiconsole.cpp @@ -487,6 +487,7 @@ void UIConsole::createDefaultCommands() { addCommand( "showfps", [&]( const auto& params ) { cmdShowFps( params ); } ); addCommand( "gettexturememory", [&]( const auto& ) { cmdGetTextureMemory(); } ); addCommand( "hide", [&]( const auto& ) { hide(); } ); + addCommand( "grep", [&]( const auto& params ) { cmdGrep( params ); } ); } void UIConsole::cmdClear() { @@ -552,6 +553,26 @@ void UIConsole::cmdGetGpuExtensions() { } } +void UIConsole::cmdGrep( const std::vector& params ) { + if ( params.empty() ) + return; + bool caseSensitive = !std::any_of( params.begin(), params.end(), + []( const auto& other ) { return "-i" == other; } ); + String search = params[params.size() - 1]; + + if ( caseSensitive ) { + for ( const auto& cmd : mCmdLog ) + if ( !cmd.log.empty() && cmd.log[0] != '>' && String::contains( cmd.log, search ) ) + privPushText( cmd.log ); + } else { + search.toLower(); + for ( const auto& cmd : mCmdLog ) + if ( !cmd.log.empty() && cmd.log[0] != '>' && + String::contains( String::toLower( cmd.log ), search ) ) + privPushText( cmd.log ); + } +} + void UIConsole::cmdSetGamma( const std::vector& params ) { if ( params.size() >= 2 ) { Float tFloat = 0.f; diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index ebdb8ae8c..0e0a0390e 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -781,7 +781,7 @@ void UISceneNode::updateDirtyLayouts() { mUpdatingLayouts = false; if ( mVerbose ) - Log::info( "Layout tree updated in %.2f ms", clock.getElapsedTime().asMilliseconds() ); + Log::debug( "Layout tree updated in %.2f ms", clock.getElapsedTime().asMilliseconds() ); } } diff --git a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp index 61eddce5d..6e48ad4e7 100644 --- a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp +++ b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp @@ -233,31 +233,6 @@ void LSPDocumentClient::processTokens( const LSPSemanticTokensDelta& tokens ) { mRunningSemanticTokens = false; } -void LSPDocumentClient::onDocumentLineMove( const Int64& fromLine, const Int64& numLines ) { - Int64 linesCount = mDoc->linesCount(); - if ( numLines > 0 ) { - for ( Int64 i = linesCount - 1; i >= fromLine; --i ) { - auto lineIt = mTokenizerLines.find( i - numLines ); - if ( lineIt != mTokenizerLines.end() && - lineIt->second.hash == mDoc->line( i ).getHash() ) { - auto nl = mTokenizerLines.extract( lineIt ); - nl.key() = i; - mTokenizerLines.insert( std::move( nl ) ); - } - } - } else if ( numLines < 0 ) { - for ( Int64 i = fromLine; i < linesCount; i++ ) { - auto lineIt = mTokenizerLines.find( i - numLines ); - if ( lineIt != mTokenizerLines.end() && - lineIt->second.hash == mDoc->line( i ).getHash() ) { - auto nl = mTokenizerLines.extract( lineIt ); - nl.key() = i; - mTokenizerLines[i] = std::move( nl.mapped() ); - } - } - } -} - void LSPDocumentClient::highlight() { if ( mShutdown ) return; @@ -275,6 +250,8 @@ void LSPDocumentClient::highlight() { std::unordered_map tokenizerLines; Int64 lastLine = 0; TokenizedLine* lastLinePtr = nullptr; + Time diff; + for ( size_t i = 0; i < data.size(); i += 5 ) { if ( mShutdown ) return; @@ -298,28 +275,28 @@ void LSPDocumentClient::highlight() { line.hash = mDoc->line( currentLine ).getHash(); line.updateSignature(); - if ( lastLine != currentLine && nullptr != lastLinePtr ) { - auto lastLineTokIt = mTokenizerLines.find( lastLine ); - if ( lastLineTokIt != mTokenizerLines.end() && - lastLinePtr->signature == lastLineTokIt->second.signature ) { - tokenizerLines.erase( lastLine ); - } + auto curSignature = mDoc->getHighlighter()->getTokenizedLineSignature( lastLine ); + if ( lastLinePtr && lastLinePtr->signature == curSignature ) { + tokenizerLines.erase( lastLine ); } lastLine = currentLine; lastLinePtr = &line; } + diff = clock.getElapsedTime(); + for ( auto& tline : tokenizerLines ) { if ( mShutdown ) return; mDoc->getHighlighter()->mergeLine( tline.first, tline.second ); - - mTokenizerLines[tline.first] = std::move( tline.second ); } - Log::debug( "LSPDocumentClient::highlight took: %.2f ms", - clock.getElapsedTime().asMilliseconds() ); + + Log::debug( "LSPDocumentClient::highlight took: %.2f ms. Diff analysis took: %.2f ms. Updated " + "%lld elements", + clock.getElapsedTime().asMilliseconds(), diff.asMilliseconds(), + tokenizerLines.size() ); } void LSPDocumentClient::notifyOpen() { diff --git a/src/tools/ecode/plugins/lsp/lspdocumentclient.hpp b/src/tools/ecode/plugins/lsp/lspdocumentclient.hpp index adc780a21..41efad9b9 100644 --- a/src/tools/ecode/plugins/lsp/lspdocumentclient.hpp +++ b/src/tools/ecode/plugins/lsp/lspdocumentclient.hpp @@ -37,7 +37,6 @@ class LSPDocumentClient : public TextDocument::Client { virtual void onDocumentDirtyOnFileSystem( TextDocument* ); virtual void onDocumentMoved( TextDocument* ); virtual void onDocumentReloaded( TextDocument* ); - virtual void onDocumentLineMove( const Int64& fromLine, const Int64& numLines ); void notifyOpen(); @@ -59,7 +58,6 @@ class LSPDocumentClient : public TextDocument::Client { LSPSemanticTokensDelta mSemanticTokens; bool mRunningSemanticTokens{ false }; bool mShutdown{ false }; - std::unordered_map mTokenizerLines; void refreshTag();