aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/api/options.c8
-rw-r--r--test/functional/lua/filetype_spec.lua12
2 files changed, 20 insertions, 0 deletions
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c
index bbfd00f2ea..3289daeb6f 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -165,6 +165,14 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err)
buf_T *ftbuf = do_ft_buf(filetype, &aco, err);
if (ERROR_SET(err)) {
+ if (ftbuf != NULL) {
+ // restore curwin/curbuf and a few other things
+ aucmd_restbuf(&aco);
+
+ assert(curbuf != ftbuf); // safety check
+ wipe_buffer(ftbuf, false);
+ }
+
return (Object)OBJECT_INIT;
}
diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua
index 574c837f92..b6011d5268 100644
--- a/test/functional/lua/filetype_spec.lua
+++ b/test/functional/lua/filetype_spec.lua
@@ -161,6 +161,18 @@ describe('vim.filetype', function()
end
end
end)
+
+ it('.get_option() cleans up buffer on error', function()
+ api.nvim_create_autocmd('FileType', { pattern = 'foo', command = 'lua error()' })
+
+ local buf = api.nvim_get_current_buf()
+
+ exec_lua(function()
+ pcall(vim.filetype.get_option, 'foo', 'lisp')
+ end)
+
+ eq(buf, api.nvim_get_current_buf())
+ end)
end)
describe('filetype.lua', function()