From 060e4f4450389c8da3d163ec5c6863c03ec72309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 3 Sep 2024 19:17:08 -0300 Subject: [PATCH] Fix crash on LSP reload. Fix document symbols not being sorted (some LSPs do not sort the symbols for some reason). Update efsw. --- src/thirdparty/efsw | 2 +- src/tools/ecode/plugins/lsp/lspclientplugin.cpp | 4 +++- src/tools/ecode/plugins/lsp/lspclientserver.cpp | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/thirdparty/efsw b/src/thirdparty/efsw index 2f90a4410..998c16ebc 160000 --- a/src/thirdparty/efsw +++ b/src/thirdparty/efsw @@ -1 +1 @@ -Subproject commit 2f90a44104d33b873e9e374b1dbb6c6b73073528 +Subproject commit 998c16ebc1ab95cc2c41289942d300f68a6dc78a diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp index 4d4fcd3d8..a9b9cad24 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 @@ -260,6 +260,8 @@ LSPClientPlugin::~LSPClientPlugin() { } for ( auto listener : editor.second ) editor.first->removeEventListener( listener ); + if ( mBreadcrumb ) + editor.first->unregisterTopSpace( this ); editor.first->unregisterPlugin( this ); } if ( nullptr == mManager->getSplitter() ) diff --git a/src/tools/ecode/plugins/lsp/lspclientserver.cpp b/src/tools/ecode/plugins/lsp/lspclientserver.cpp index 21dcb2c67..7bbdfe858 100644 --- a/src/tools/ecode/plugins/lsp/lspclientserver.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientserver.cpp @@ -428,6 +428,16 @@ struct LSPSymbolInformationTmp { } }; +static void sortRecursive( std::list& symbols ) { + symbols.sort( []( const LSPSymbolInformationTmp& left, const LSPSymbolInformationTmp& right ) { + return left.range < right.range; + } ); + + for ( auto& symbol : symbols ) + if ( !symbol.children.empty() ) + sortRecursive( symbol.children ); +} + static LSPSymbolInformationList parseDocumentSymbols( const json& result, bool isSilent ) { // TODO: Optimize this Clock clock; @@ -482,6 +492,8 @@ static LSPSymbolInformationList parseDocumentSymbols( const json& result, bool i for ( const auto& info : symInfos ) parseSymbol( info, nullptr ); + sortRecursive( ret ); + LSPSymbolInformationList rret; for ( const auto& r : ret ) rret.push_back( LSPSymbolInformationTmp::fromTmp( r ) );