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

Worksheets on scratch buffers #238

Open
domaspoliakas opened this issue Oct 5, 2021 · 1 comment
Open

Worksheets on scratch buffers #238

domaspoliakas opened this issue Oct 5, 2021 · 1 comment

Comments

@domaspoliakas
Copy link

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

if exists then
api.nvim_buf_set_lines(exists, 0, -1, false, lines)
api.nvim_win_set_buf(0, exists)
else
local new_buffer = api.nvim_create_buf(true, true)
api.nvim_buf_set_lines(new_buffer, 0, -1, false, lines)
api.nvim_buf_set_name(new_buffer, name)
-- TODO we should probably do something better for this case, but java is
-- a bit nicer syntax for these than scala
if decoder == "javap" then
api.nvim_buf_set_option(new_buffer, "syntax", "java")
else
api.nvim_buf_set_option(new_buffer, "syntax", "scala")
end
api.nvim_win_set_buf(0, new_buffer)
end
end
end

Additional context

N/A

Search terms

Worksheets worksheet scratch buffer disk

@ckipp01
Copy link
Member

ckipp01 commented Oct 5, 2021

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.

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

No branches or pull requests

2 participants