-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split the clean_buffer helper for lean3, simplifying it.
- Loading branch information
Showing
22 changed files
with
147 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
globals = { | ||
"_clean_buffer_count", | ||
"vim", | ||
"lean_nvim_default_filetype", | ||
"describe", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
local helpers = { _clean_buffer_counter = 1 } | ||
|
||
-- Even though we can delete a buffer, so should be able to reuse names, | ||
-- we do this to ensure if a test fails, future ones still get new "files". | ||
local function set_unique_name_so_we_always_have_a_separate_fake_file(bufnr) | ||
local counter = helpers._clean_buffer_counter | ||
helpers._clean_buffer_counter = helpers._clean_buffer_counter + 1 | ||
local unique_name = string.format('unittest-%d.lean', counter) | ||
vim.api.nvim_buf_set_name(bufnr, unique_name) | ||
end | ||
|
||
--- Create a clean Lean buffer with the given contents. | ||
-- | ||
-- Waits for the LSP to be ready before proceeding with a given callback. | ||
-- | ||
-- Yes c(lean) may be a double entendre, and no I don't feel bad. | ||
function helpers.clean_buffer(contents, callback) | ||
if callback == nil then | ||
callback = contents | ||
contents = '' | ||
end | ||
|
||
return function() | ||
local bufnr = vim.api.nvim_create_buf(false, false) | ||
set_unique_name_so_we_always_have_a_separate_fake_file(bufnr) | ||
-- apparently necessary to trigger BufWinEnter | ||
vim.api.nvim_set_current_buf(bufnr) | ||
vim.opt_local.bufhidden = 'hide' | ||
vim.opt_local.swapfile = false | ||
vim.opt.filetype = 'lean3' | ||
|
||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, vim.split(contents, '\n')) | ||
vim.api.nvim_buf_call(bufnr, function() callback{ source_file = { bufnr = bufnr } } end) | ||
end | ||
end | ||
|
||
return helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.