Performance improvements due to not debouncing some function calls.

Adjust JSX and TS syntax definitions.
This commit is contained in:
Martín Lucas Golini
2025-04-02 20:24:45 -03:00
parent 577f2e3dbb
commit 2a88bac8a1
7 changed files with 68 additions and 67 deletions

View File

@@ -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 );

View File

@@ -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( { { '{', '}' } } );
}

View File

@@ -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" },

View File

@@ -1,5 +1,5 @@
#include "../../version.hpp"
#include "lspclientplugin.hpp"
#include "../../version.hpp"
#include <eepp/graphics/primitives.hpp>
#include <eepp/system/filesystem.hpp>
#include <eepp/system/lock.hpp>
@@ -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;
}

View File

@@ -1,5 +1,5 @@
#include "lspclientplugin.hpp"
#include "lspclientserver.hpp"
#include "lspclientplugin.hpp"
#include "lspclientservermanager.hpp"
#include <algorithm>
#include <eepp/system/filesystem.hpp>
@@ -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 ) )

View File

@@ -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();