From 6c94ea50d9883b2ad61ab52b6e113095fa36e88e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 10 Mar 2024 13:07:21 -0300 Subject: [PATCH] Fix bug in LSP Plugin when opening a same document in a split and then closing the original document, keybinds were lost after that. --- src/tools/ecode/plugins/git/gitplugin.hpp | 2 +- src/tools/ecode/plugins/lsp/lspclientplugin.cpp | 10 ++++++++++ src/tools/ecode/plugins/lsp/lspclientplugin.hpp | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tools/ecode/plugins/git/gitplugin.hpp b/src/tools/ecode/plugins/git/gitplugin.hpp index 446fddeb7..736a9c7e8 100644 --- a/src/tools/ecode/plugins/git/gitplugin.hpp +++ b/src/tools/ecode/plugins/git/gitplugin.hpp @@ -36,7 +36,7 @@ static constexpr const char* GIT_STASH = "git-stash"; class GitPlugin : public PluginBase { public: static PluginDefinition Definition() { - return { "git", "Git", "Git integration", GitPlugin::New, { 0, 0, 1 }, GitPlugin::NewSync }; + return { "git", "Git", "Git integration", GitPlugin::New, { 0, 1, 0 }, GitPlugin::NewSync }; } static Plugin* New( PluginManager* pluginManager ); diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp index 463340720..1fd66b0e2 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp @@ -1236,6 +1236,7 @@ void LSPClientPlugin::onRegister( UICodeEditor* editor ) { listeners.push_back( editor->addEventListener( Event::OnDocumentLoaded, [this, editor]( const Event* ) { + mEditorDocs[editor] = editor->getDocumentRef().get(); mClientManager.run( editor->getDocumentRef() ); } ) ); @@ -1245,6 +1246,15 @@ void LSPClientPlugin::onRegister( UICodeEditor* editor ) { hideTooltip( editor ); } ) ); + listeners.push_back( + editor->addEventListener( Event::OnDocumentChanged, [this, editor]( const Event* ) { + TextDocument* oldDoc = mEditorDocs[editor]; + TextDocument* newDoc = editor->getDocumentRef().get(); + Lock l( mDocMutex ); + mDocs.erase( oldDoc ); + mEditorDocs[editor] = newDoc; + } ) ); + mEditors.insert( { editor, listeners } ); mEditorsTags.insert( { editor, UnorderedSet{} } ); mEditorDocs[editor] = editor->getDocumentRef().get(); diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.hpp b/src/tools/ecode/plugins/lsp/lspclientplugin.hpp index bf80a8d7e..5bc89da62 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.hpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.hpp @@ -25,7 +25,7 @@ class LSPClientPlugin : public Plugin { public: static PluginDefinition Definition() { return { "lspclient", "LSP Client", "Language Server Protocol Client.", - LSPClientPlugin::New, { 0, 2, 3 }, LSPClientPlugin::NewSync }; + LSPClientPlugin::New, { 0, 2, 4 }, LSPClientPlugin::NewSync }; } static Plugin* New( PluginManager* pluginManager );