Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP features are not working on other half after "split tab" action. #4166

Open
veksha opened this issue Jun 7, 2022 · 17 comments
Open

LSP features are not working on other half after "split tab" action. #4166

veksha opened this issue Jun 7, 2022 · 17 comments
Labels

Comments

@veksha
Copy link
Contributor

veksha commented Jun 7, 2022

LSP features are not working on other half after "split tab" action.

  1. install and configure cuda_lsp addon
  2. open some file to test LSP features
  3. ensure they are working fine
  4. use "split tab: split horizontally" action in Command palette
  5. try to use any LSP features on other half
  6. fail
@Alexey-T Alexey-T added the bug label Jun 7, 2022
@Alexey-T
Copy link
Owner

Alexey-T commented Jun 7, 2022

Python IntelliSense plugin-- works ok in other half. so, it is the LSP plugin issue, not Cud's. I need to check it uses "ed" properly. "ed" object is always the focused editor.

@Alexey-T Alexey-T added plugins and removed bug labels Jun 7, 2022
@Alexey-T
Copy link
Owner

Alexey-T commented Jun 8, 2022

Related APIs:
ed.get_prop / ed.set_prop with PROP_HANDLE_SELF, PROP_HANDLE_PRIMARY, PROP_HANDLE_SECONDARY.

I searched the LSP plugin code but failed to find the reason. I just found that internal LSP-msg-handler is not called at all when we are in the secondary editor. This msg-handler calls the ed.complete_alt() API, only for primary editor.

@CudaText-addons
Copy link

handler is here:

file language.py, def _on_lsp_msg.

@veksha
Copy link
Contributor Author

veksha commented Jun 16, 2022

problem is in on_complete event.

@command
    def on_complete(self, ed_self):
        doc = self.book.get_doc(ed_self)
        if doc and doc.lang:
            return doc.lang.on_complete(doc)

book.get_doc will return None, because there is dictionary called docs where keys are the filenames and values are docs with ed member (editor associated with that doc).
since editor is not the same on the other half of split - it will return None instead of doc.

the simple solution I came up with looks like this:

diff --git a/lsp.py b/lsp.py
index c7660d9..3f93953 100644
--- a/lsp.py
+++ b/lsp.py
@@ -306,6 +306,7 @@ class Command:
                     lang.update_tree(doc)
 
     def on_focus(self, ed_self):
+        self._do_on_open(ed_self)
         doc = self.book.get_doc(ed_self)
         if doc and doc.lang and doc.lang.tree_enabled:
             doc.lang.update_tree(doc)

so every time we click on other half of split it will trigger _do_on_open where then doc will be created (new_doc) for this editor and replace old doc for this file in docs dictionary.

BUT...
then I see a memory leak when switching focus from half to half. and I don't know why.
i think it's because of text_document.dict() in did_open function of client.py (because replacing it wih None stops the leak)

image

but i'm not sure i know how to debug it correctly. maybe it's not fault of text_document.dict() and i'm looking in the wrong place? maybe it just sends notification (textDocument/didOpen) correctly and then leaks on response..?
puzzled.

do you have experience with debugging memory leaks like these?

PS: we can think of another way to fix this Cuda_LSP split tab issue as well.

@Alexey-T
Copy link
Owner

do you have experience with debugging memory leaks like these?

it's strange that Py script gives leak. all leaks must be handled by Py GC, no? if they are not, we need to write del <object>.

@Alexey-T
Copy link
Owner

@veksha
Copy link
Contributor Author

veksha commented Jun 16, 2022

it's programmers (mine) fault not python GC's.
because my fix actually looks like a hack:
we are doing on_open inside on_focus and not calling on_close anywhere afterwards.

must think of a different way to handle this situation.
(also we must not forget about differ plugin, it opens second half with different filename/filepath to compare.) so it will be two records in docs dictionary instead of one.

@Alexey-T
Copy link
Owner

for Differ plugin:

Editor.get_prop(PROP_EDITORS_LINKED, '') : enable sharing of the same text by primary/secondary editors in file tab.

@Alexey-T
Copy link
Owner

because my fix actually looks like a hack:
we are doing on_open inside on_focus and not calling on_close anywhere afterwards.

for me, your fix looks normal. API don't tell us to call any on_close.

@veksha
Copy link
Contributor Author

veksha commented Jun 16, 2022

it grows +150-300 kb everytime you switch focus between halfs. do you see that on linux?

@Alexey-T
Copy link
Owner

linux HTOP app cannot tell about +200kb

Screenshot_2022-06-16_23-17-03

@veksha
Copy link
Contributor Author

veksha commented Jun 16, 2022

RES column? 63004 bytes?

@Alexey-T
Copy link
Owner

VIRT column: 510M (includes LSP server mem)

@veksha
Copy link
Contributor Author

veksha commented Jun 16, 2022

"VIRT represents how much memory the program is able to access at the present moment. RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming."
https://stackoverflow.com/questions/6036154/detect-memory-leak-with-htop

@Alexey-T
Copy link
Owner

Alexey-T commented Jun 16, 2022

aha, sorry. ok, RES memory grows after on_focus on each half! by +20...+100.

@Alexey-T
Copy link
Owner

Alexey-T commented Feb 7, 2023

we cannot solve it, you didnt try more, @veksha ?

@veksha
Copy link
Contributor Author

veksha commented Feb 7, 2023

not tried.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants