alefragnani / vscode-bookmarks

Bookmarks Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks
GNU General Public License v3.0
1.65k stars 161 forks source link

[BUG?] - messes with language server? #724

Closed hmijail closed 6 days ago

hmijail commented 1 month ago

When I open the Bookmarks view, the Dafny extension / Language Server gets used in a way that causes a slow, ever-growing memory leak.

I guess this is more a heads-up than a bug report, because I am not sure if this is a bug in either of the extensions; but the memory leak only seems to happen in the Dafny LS when the Bookmarks view is activated. Worse, once triggered, closing the Bookmarks view doesn't help.

There was some chasing down of the problem in here.

If you can think I can help debug this let me know.

Environment/version

Steps to reproduce

  1. Open the bookmarks view
  2. See language servers get started, even if no files are open visibly to the user
  3. See the dotnet process of the Dafny LS leak memory
alefragnani commented 1 month ago

Hi @hmijail ,

I wonder why the extension would start the Dafny LS, simply by opening the Bookmarks View, unless the Dafny LS has a hook in the onDidOpenTextDocument event. To check that, use the Bookmarks: List from All Files command instead, and look if the same issue occurs.

What does these two commands execute in the extension? Under the hood, the same thing. Both will loop through all files that contains some bookmark (based on the .vscode/bookmarks.json or in the workspaceState Memento), open them using openTextDocument API, and read the content of the lines where a bookmark has been toggled. No change is made in your files, just reads, in order to display the line content. Based on the documentation, the openTextDocument API knows if a file has been previously opened, and won't do it twice.

I don't know Dafny, and I'm not sure why its LS would suffer from memory leak because another extension opened a file and read content from some of its lines. Maybe it doesn't expect "sharing" a file and ended up opening again.

Hope this helps

hmijail commented 1 month ago

Indeed, Bookmarks: List from All Files causes the same issue.

Looking at the Output tab, Extension Host channel, looks like that command causes extensions to activate because a bookmark in a file with language X will trigger an event of the type onLanguage:X. So this is activating e.g. the ms-dotnettools.csharp and golang.go extensions too, because I have bookmarks on C# and Go files too.

Interestingly, there's also an event for Java, but doesn't seem to have much effect because its extension/LS does a lot of eager-start startup configuration stuff anyway.

(I'm commenting this just FYI. I guess those onLanguage events are produced by the openTextDocument API you mentioned, not directly by Bookmarks)

alefragnani commented 1 month ago

Yes, that onDidOpenTextDocument event, and consequently on language:xyz is triggered whenever a file is opened.

Coincidentally, this post was raised recently in the VS Code Discussions forum (https://github.com/microsoft/vscode-discussions/discussions/1192), but had no comment/answer yet.