mirror of
				https://github.com/tiyn/tidy.nvim.git
				synced 2025-10-31 11:11:23 +01:00 
			
		
		
		
	refactor: replace custom util with api fn
I was using a function that turns list-like tables into sets to quickly search the filetype_exclude table. This commit replaces that tool with one from vim.api and adds error handling to ensure that filetype_exclude is a list-like table.
This commit is contained in:
		| @@ -12,21 +12,9 @@ function M.toggle() | |||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
| local function list_to_set(list) |  | ||||||
|   local set = {} |  | ||||||
|  |  | ||||||
|   for _, item in ipairs(list) do |  | ||||||
|     set[item] = true |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   return set |  | ||||||
| end |  | ||||||
|  |  | ||||||
| local function is_excluded_ft(opts) | local function is_excluded_ft(opts) | ||||||
|   local ft = vim.api.nvim_buf_get_option(0, "filetype") |   local ft = vim.api.nvim_buf_get_option(0, "filetype") | ||||||
|   local ft_set = list_to_set(opts.filetype_exclude) |   return vim.list_contains(opts.filetype_exclude, ft) | ||||||
|  |  | ||||||
|   return ft_set[ft] |  | ||||||
| end | end | ||||||
|  |  | ||||||
| local function reset_cursor_pos(pos) | local function reset_cursor_pos(pos) | ||||||
| @@ -55,6 +43,14 @@ function M.setup(opts) | |||||||
|  |  | ||||||
|   opts = vim.tbl_extend("force", defaults, opts or {}) |   opts = vim.tbl_extend("force", defaults, opts or {}) | ||||||
|  |  | ||||||
|  | 	if not vim.tbl_islist(opts.filetype_exclude) then | ||||||
|  | 		vim.notify( | ||||||
|  | 			"tidy.nvim: filetype_exclude option must be a list-like table...", | ||||||
|  | 			vim.log.levels.ERROR, | ||||||
|  | 			{ title = "Tidy" } | ||||||
|  | 		) | ||||||
|  | 	end | ||||||
|  |  | ||||||
|   local tidy_grp = vim.api.nvim_create_augroup("tidy", { clear = true }) |   local tidy_grp = vim.api.nvim_create_augroup("tidy", { clear = true }) | ||||||
|  |  | ||||||
| 	vim.api.nvim_create_autocmd("BufWritePre", { | 	vim.api.nvim_create_autocmd("BufWritePre", { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user