scalameta / nvim-metals

A Metals plugin for Neovim
https://scalameta.org/metals/
Apache License 2.0
455 stars 74 forks source link

Worksheets on scratch buffers #238

Open domaspoliakas opened 2 years ago

domaspoliakas commented 2 years ago

Describe the feature

Worksheets that use a scratch buffer instead of being saved on disk.

Potential ways to implement?

From discord:

for example just add a "Create scratch worksheet" command in here https://github.com/scalameta/nvim-metals/blob/main/lua/metals/commands.lua and then add a function in here that it can call https://github.com/scalameta/nvim-metals/blob/main/lua/metals.lua and you can see here as an example how I create a scratch buffer https://github.com/scalameta/nvim-metals/blob/22a0f9f22e8ab19292fd2171b6ccb0f2461a8d58/lua/metals/decoder.lua#L40-L57

Additional context

N/A

Search terms

Worksheets worksheet scratch buffer disk

ckipp01 commented 2 years ago

Thanks for the request @domaspoliakas! Thinking about and playing around with this a bit we hit on a snag right away that you can't really save a scratch buffer which means you can't get the didSave notification sent to the server to both get diagnostics and results of the worksheet. You can try to hack around this but it might be messy.

Another idea would be to just create either a tmp file or like a .metals/scratch.worksheet.sc. Then a quick worksheet command could always just open that up if it exists or create a new one.