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

feat: close markmap when watched buffer is closed #16

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

MarcoBuess
Copy link
Contributor

This was a late one for me. Let me know how you like it, or if you can spot major flaws right away. cheers and happy easter. :)

@Zeioth
Copy link
Owner

Zeioth commented Mar 31, 2024

I've been testing the solution and I like it but there is a problem I'm not sure it has solution:

  • Every time the user run :MarkmapWatch, it spawns a markmap process.
  • Those processes can accumulate infinitely until the user decides to close the buffer.

screenshot_2024-03-31_03-38-59_919832598

  • Every markmap process take 0.8% RAM on my machine, about 150Mb.

Advantages

  • Because this approach allow multiple processes to spawn, it makes possible to watch multiple files without having to run :MarkmapWatch every time you change to a different buffer, which is actually a better UX.

Disadvantages

  • A user might potentially spawn a unnecessary amount of processes that could easily take from 500Mb to few Gb in the worst case.

Failed solutions

  • Only allow one process per buffer → Not a viable solution. This would make impossible for the user to run :MarkmapWatch again if he closes the html page accidentally, as we don't currently implement a complex solution like RPC.

Potencially viable solutions

  • Updating the readme to describe precisely the new behavior.
  • A notification to inform the user the process will remain until he closes the buffer or run :MarkmapWatchStop (which also need changes).

Give me a bit more of time to think.

@MarcoBuess
Copy link
Contributor Author

MarcoBuess commented Mar 31, 2024

Only allow one process per buffer → Not a viable solution. This would make impossible for the user to run :MarkmapWatch again if he closes the html page accidentally, as we don't currently implement a complex solution like RPC.

You could relatively easily store the jobs by buffer in a table and make a simple lookup before spawning a new job. This would allow for watching of multiple buffers, but prevents launching a second one. You would have to rework WatchStop to stop on buffer basis and/or have lt gobally stop all jobs. I'm kinda suprised that this even works. During my tests (on windows) I was not able to launch a second mm instance, as it would always try and spawn on the same default port. I might have to take a closer look.

@MarcoBuess
Copy link
Contributor Author

MarcoBuess commented Apr 2, 2024

@Zeioth I added my suggestions in a couple (hopefully digestible) commits. Watching multiple buffers should now handle appropreatly. On windows, you will receive an error when you try to start multiple instances. Generally you will now receive an error if markmap cli reports to stderr, print the respective message and deregister the autocmd as well as take the affected buffer from the watch list.

MarkmapWatchStop now only handles the currently open buffer instance. We could either introduce a MarkmapWatchStopAll command or parameterize MarkmapWatchStop in case that kind of functionality is needed.

Let me know what you think.

@Zeioth
Copy link
Owner

Zeioth commented May 9, 2024

@MarcoBuess It doesn't seem to be working correctly currently:

Manual test

  • Open two .md files
  • Run :MarkmapWatch on one of them.
  • Close the buffer.
  • Run :MarkmapWatch on the other file.
  • Markmap seems to still be running.

screenshot_2024-05-09_19-27-49_195306704

Manual test 2

  • If we run :MarkmapWatch in the second file before closing the first file, it will cause the former error. This error is persistent in further attempts, meaning something is not ok.
  • But If I close the file first, and then I try to run MarkmapWatch on the second one, it will work as expected.

More info

  • It doesn't seem to be killing the existing markmap process correctly, as the process seem to still be running on background
  • Unless I'm wrong, there is no point in tracking grace_period per file because MarkmapWatch only allow tracking one file per port anyway.
  • The PR change lines that are not related with the PR.

@MarcoBuess
Copy link
Contributor Author

MarcoBuess commented May 16, 2024

@Zeioth Please try and update your node.js version. I had this issue happen with v18 on Windows and thought it was Windows specific. The Problem was gone after updating to v20+. v18 would not spawn another instance on a different port but rather tries to reuse port 3000 which will be blocked by the running node instance.

@Zeioth
Copy link
Owner

Zeioth commented Jun 9, 2024

still repro on nodejs 20 and also nodejs 22
screenshot_2024-06-09_22-11-29_743264094

@Zeioth
Copy link
Owner

Zeioth commented Jun 9, 2024

But that error come from markmap itself.
screenshot_2024-06-09_22-15-33_069407616

I'm gonna report it and see what happens

@Zeioth
Copy link
Owner

Zeioth commented Jun 9, 2024

Waiting for feedback: markmap/markmap#250

This was a late one for me. Let me know how you like it, or if you can
spot major flaws right away. cheers and happy easter. :)
removed `remove_trailing_seperators` option, which would prevent stylua
from formatting
To handle that windows can't have multiple instances of markmapcli
running I added a passthrough, so that I can handle appropreatly when
markmapcli errors. I deregister autocmds and take the buffer from the
watch list.
Looks like I've broken open and save after adding opts. This should
adress this. For some reason vim.fn.jobstart() can't handle an empty
table as opts. Maybe someone has a better solution that this, but this
works for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants