From 2a88bac8a1fcaf5891dbad5d7b0af0e65e74544a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 2 Apr 2025 20:24:45 -0300 Subject: [PATCH] Performance improvements due to not debouncing some function calls. Adjust JSX and TS syntax definitions. --- bin/assets/plugins/aiassistant.json | 2 +- src/eepp/ui/doc/textdocument.cpp | 5 +- .../src/eepp/ui/doc/languages/jsx.cpp | 101 +++++++++--------- .../src/eepp/ui/doc/languages/typescript.cpp | 4 +- .../ecode/plugins/lsp/lspclientplugin.cpp | 13 +-- .../ecode/plugins/lsp/lspclientserver.cpp | 4 +- .../ecode/plugins/lsp/lspdocumentclient.cpp | 6 +- 7 files changed, 68 insertions(+), 67 deletions(-) diff --git a/bin/assets/plugins/aiassistant.json b/bin/assets/plugins/aiassistant.json index 2ca5ba9d7..77b26da23 100644 --- a/bin/assets/plugins/aiassistant.json +++ b/bin/assets/plugins/aiassistant.json @@ -128,7 +128,7 @@ }, { "name": "gemini-2.5-pro-exp-03-25", - "display_name": "Gemini 2.5 Pro Experimental 03-25", + "display_name": "Gemini 2.5 Pro Experimental", "max_tokens": 1000000 } ] diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index c8202f93f..9bccc9acf 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -2417,9 +2417,12 @@ void TextDocument::setIndentType( const IndentType& indentType ) { void TextDocument::undo() { setRunningTransaction( true ); + bool stackWasFull = mUndoStack.getMaxStackSize() == mUndoStack.getUndoStackContainer().size(); mUndoStack.undo(); setRunningTransaction( false ); notifyUndoRedo( UndoRedo::Undo ); + if ( stackWasFull ) + setDirtyUntilSave(); } void TextDocument::redo() { @@ -2960,7 +2963,7 @@ TextDocument::SearchResults TextDocument::findAll( const String& text, bool case do { found = find( text, from, caseSensitive, wholeWord, type, restrictRange ); if ( found.isValid() ) { - if ( !all.empty() && all.back().operator==(found) ) + if ( !all.empty() && all.back().operator==( found ) ) break; from = found.result.end(); all.push_back( found ); diff --git a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/jsx.cpp b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/jsx.cpp index fa7219073..6de8c4005 100644 --- a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/jsx.cpp +++ b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/jsx.cpp @@ -5,57 +5,56 @@ namespace EE { namespace UI { namespace Doc { namespace Language { void addJSX() { - auto& sd = SyntaxDefinitionManager::instance() - ->add( { "JSX", - { "%.jsx$" }, - { - { { "//.-\n" }, "comment" }, - { { "/%*", "%*/" }, "comment" }, - { { "\"", "\"", "\\" }, "string" }, - { { "'", "'", "\\" }, "string" }, - { { "`", "`", "\\" }, "string" }, - { { "/[%+%-%*%^%!%=%&%|%?%:%;%,%(%[%{%<%>%\\%\"].*%f[/]", - "/[igmsuyd\n]?[igmsuyd\n]?[igmsuyd\n]?", "\\" }, - "string" }, - { { "%f[^<]![%a_][%w%_%-]*" }, "keyword2" }, - { { "%f[^<][%a_][%w%_%-]*" }, "function" }, - { { "%f[^<]/[%a_][%w%_%-]*" }, "function" }, - { { "([%a_-][%w-_]*)(%\?\?)(=)%f[%{%\"]" }, - { "normal", "keyword", "normal", "operator" } }, - { { "[%+%-=/%*%^%%<>!~|&]" }, "operator" }, - { { "0x[%da-fA-F]+" }, "number" }, - { { "-?%d+[%d%.eE]*" }, "number" }, - { { "-?%.?%d+" }, "number" }, - { { "[%a_][%w_]*%f[(]" }, "function" }, - { { "[%a_][%w_]*" }, "symbol" }, - }, - { - { "async", "keyword" }, { "await", "keyword" }, - { "break", "keyword" }, { "case", "keyword" }, - { "catch", "keyword" }, { "class", "keyword" }, - { "const", "keyword" }, { "continue", "keyword" }, - { "debugger", "keyword" }, { "default", "keyword" }, - { "delete", "keyword" }, { "do", "keyword" }, - { "else", "keyword" }, { "export", "keyword" }, - { "extends", "keyword" }, { "finally", "keyword" }, - { "for", "keyword" }, { "function", "keyword" }, - { "get", "keyword" }, { "if", "keyword" }, - { "import", "keyword" }, { "in", "keyword" }, - { "instanceof", "keyword" }, { "let", "keyword" }, - { "new", "keyword" }, { "return", "keyword" }, - { "set", "keyword" }, { "static", "keyword" }, - { "super", "keyword" }, { "switch", "keyword" }, - { "throw", "keyword" }, { "try", "keyword" }, - { "typeof", "keyword" }, { "var", "keyword" }, - { "void", "keyword" }, { "while", "keyword" }, - { "with", "keyword" }, { "yield", "keyword" }, - { "true", "literal" }, { "false", "literal" }, - { "null", "literal" }, { "undefined", "literal" }, - { "arguments", "keyword2" }, { "Infinity", "keyword2" }, - { "NaN", "keyword2" }, { "this", "keyword2" }, - }, - "//" } ) - .setLSPName( "javascriptreact" ); + auto& sd = + SyntaxDefinitionManager::instance() + ->add( { "JSX", + { "%.jsx$" }, + { + { { "//.-\n" }, "comment" }, + { { "/%*", "%*/" }, "comment" }, + { { "\"", "\"", "\\" }, "string" }, + { { "'", "'", "\\" }, "string" }, + { { "`", "`", "\\" }, "string" }, + { { "/[%+%-%*%^%!%=%&%|%?%:%;%,%(%[%{%<%>%\\%\"].*%f[/]", + "/[igmsuyd\n]?[igmsuyd\n]?[igmsuyd\n]?", "\\" }, + "string" }, + { { "%f[^<]![%a_][%w%_%-]*" }, "keyword2" }, + { { "%f[^<][%a_][%w%_%-]*" }, "function" }, + { { "%f[^<]/[%a_][%w%_%-]*" }, "function" }, + { { "([%a_-][%w-_]*)(%\?\?)(=)%f[%{%\"]" }, + { "normal", "keyword", "normal", "operator" } }, + { { "[%+%-=/%*%^%%<>!~|&]" }, "operator" }, + { { "js_number_parser" }, "number", "", SyntaxPatternMatchType::Parser }, + { { "[%a_][%w_]*%f[(]" }, "function" }, + { { "[%a_][%w_]*" }, "symbol" }, + }, + { + { "async", "keyword" }, { "await", "keyword" }, + { "break", "keyword" }, { "case", "keyword" }, + { "catch", "keyword" }, { "class", "keyword" }, + { "const", "keyword" }, { "continue", "keyword" }, + { "debugger", "keyword" }, { "default", "keyword" }, + { "delete", "keyword" }, { "do", "keyword" }, + { "else", "keyword" }, { "export", "keyword" }, + { "extends", "keyword" }, { "finally", "keyword" }, + { "for", "keyword" }, { "function", "keyword" }, + { "get", "keyword" }, { "if", "keyword" }, + { "import", "keyword" }, { "in", "keyword" }, + { "instanceof", "keyword" }, { "let", "keyword" }, + { "new", "keyword" }, { "return", "keyword" }, + { "set", "keyword" }, { "static", "keyword" }, + { "super", "keyword" }, { "switch", "keyword" }, + { "throw", "keyword" }, { "try", "keyword" }, + { "typeof", "keyword" }, { "var", "keyword" }, + { "void", "keyword" }, { "while", "keyword" }, + { "with", "keyword" }, { "yield", "keyword" }, + { "true", "literal" }, { "false", "literal" }, + { "null", "literal" }, { "undefined", "literal" }, + { "arguments", "keyword2" }, { "Infinity", "keyword2" }, + { "NaN", "keyword2" }, { "this", "keyword2" }, + }, + "//" } ) + .setLSPName( "javascriptreact" ); sd.setFoldRangeType( FoldRangeType::Braces ).setFoldBraces( { { '{', '}' } } ); } diff --git a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/typescript.cpp b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/typescript.cpp index 9f8d70d92..b387cc815 100644 --- a/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/typescript.cpp +++ b/src/modules/languages-syntax-highlighting/src/eepp/ui/doc/languages/typescript.cpp @@ -90,9 +90,7 @@ void addTypeScript() { { { "([%a_-][%w-_]*)(%\?\?)(=)%f[%{%\"]" }, { "normal", "keyword", "normal", "operator" } }, { { "[%+%-=/%*%^%%<>!~|&]" }, "operator" }, - { { "0x[%da-fA-F]+" }, "number" }, - { { "-?%d+[%d%.eE]*" }, "number" }, - { { "-?%.?%d+" }, "number" }, + { { "js_number_parser" }, "number", "", SyntaxPatternMatchType::Parser }, { { "(interface%s)([%a_][%w_]*)" }, { "normal", "keyword", "keyword2" } }, { { "(type%s)([%a_][%w_]*)" }, { "normal", "keyword", "keyword2" } }, { { "[%a_][%w_$]*%f[(]" }, "function" }, diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp index ff521ca0a..d8d0168a7 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp @@ -1,5 +1,5 @@ -#include "../../version.hpp" #include "lspclientplugin.hpp" +#include "../../version.hpp" #include #include #include @@ -562,11 +562,12 @@ bool LSPClientPlugin::processDocumentFormattingResponse( const URI& uri, auto doc = mManager->getSplitter()->findDocFromURI( uri ); if ( !doc ) { - mManager->getLoadFileFn()( uri.getFSPath(), [this, edits]( UICodeEditor* editor, auto ) { - auto documentRef = editor->getDocumentRef(); - mManager->getSplitter()->getUISceneNode()->runOnMainThread( - [documentRef, edits]() { processFormattingResponse( documentRef, edits ); } ); - } ); + mManager->getLoadFileFn()( + uri.getFSPath(), [this, edits = std::move( edits )]( UICodeEditor* editor, auto ) { + auto documentRef = editor->getDocumentRef(); + mManager->getSplitter()->getUISceneNode()->runOnMainThread( + [documentRef, edits]() { processFormattingResponse( documentRef, edits ); } ); + } ); return false; } diff --git a/src/tools/ecode/plugins/lsp/lspclientserver.cpp b/src/tools/ecode/plugins/lsp/lspclientserver.cpp index 636202ffd..80fabcd91 100644 --- a/src/tools/ecode/plugins/lsp/lspclientserver.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientserver.cpp @@ -1,5 +1,5 @@ -#include "lspclientplugin.hpp" #include "lspclientserver.hpp" +#include "lspclientplugin.hpp" #include "lspclientservermanager.hpp" #include #include @@ -752,7 +752,7 @@ static LSPMarkupContent parseMarkupContent( const json& v ) { static LSPHover parseHover( const json& result ) { LSPHover ret; - if ( result.is_null() ) + if ( result.is_null() || !result.contains( "contains" ) ) return ret; if ( result.contains( MEMBER_RANGE ) ) diff --git a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp index e5522b2c2..b2ed6a96f 100644 --- a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp +++ b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp @@ -195,8 +195,8 @@ void LSPDocumentClient::requestSemanticHighlightingDelayed( bool reqFull ) { if ( sceneNode ) { mWaitingSemanticTokensResponse = true; sceneNode->removeActionsByTag( mTagSemanticTokens ); - sceneNode->runOnMainThread( [this, reqFull]() { requestSemanticHighlighting( reqFull ); }, - Seconds( 0.5f ), mTagSemanticTokens ); + sceneNode->debounce( [this, reqFull]() { requestSemanticHighlighting( reqFull ); }, + Seconds( 0.5f ), mTagSemanticTokens ); } } @@ -451,7 +451,7 @@ void LSPDocumentClient::requestSymbolsDelayed() { LSPDocumentClient* docClient = this; URI uri = mDoc->getURI(); LSPClientServer* server = mServer; - sceneNode->runOnMainThread( + sceneNode->debounce( [docClient, server, uri]() { if ( server->hasDocument( uri ) ) docClient->requestSymbols();