From 65e2feabeb9bd17a076206d98dadb93515e9b612 Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Sat, 4 Mar 2023 22:05:57 +0900 Subject: docs(editorconfig): number → integer (#22514) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/lua/editorconfig.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/editorconfig.lua') diff --git a/runtime/lua/editorconfig.lua b/runtime/lua/editorconfig.lua index 2079006234..5b09126788 100644 --- a/runtime/lua/editorconfig.lua +++ b/runtime/lua/editorconfig.lua @@ -202,7 +202,7 @@ end --- Configure the given buffer with options from an .editorconfig file --- ----@param bufnr number Buffer number to configure +---@param bufnr integer Buffer number to configure --- ---@private function M.config(bufnr) -- cgit From 4d04feb6629cb049cb2a13ba35f0c8d3c6b67ff4 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 14 Apr 2023 10:39:57 +0200 Subject: feat(lua): vim.tbl_contains supports general tables and predicates (#23040) * feat(lua): vim.tbl_contains supports general tables and predicates Problem: `vim.tbl_contains` only works for list-like tables (integer keys without gaps) and primitive values (in particular, not for nested tables). Solution: Rename `vim.tbl_contains` to `vim.list_contains` and add new `vim.tbl_contains` that works for general tables and optionally allows `value` to be a predicate function that is checked for every key. --- runtime/lua/editorconfig.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/editorconfig.lua') diff --git a/runtime/lua/editorconfig.lua b/runtime/lua/editorconfig.lua index 5b09126788..5188c13284 100644 --- a/runtime/lua/editorconfig.lua +++ b/runtime/lua/editorconfig.lua @@ -26,7 +26,7 @@ end function M.properties.charset(bufnr, val) assert( - vim.tbl_contains({ 'utf-8', 'utf-8-bom', 'latin1', 'utf-16be', 'utf-16le' }, val), + vim.list_contains({ 'utf-8', 'utf-8-bom', 'latin1', 'utf-16be', 'utf-16le' }, val), 'charset must be one of "utf-8", "utf-8-bom", "latin1", "utf-16be", or "utf-16le"' ) if val == 'utf-8' or val == 'utf-8-bom' then -- cgit From 143a1783328074a5167d9619aff2a8ee9c2ca481 Mon Sep 17 00:00:00 2001 From: Bogdan Grigoruță <43993819+krady21@users.noreply.github.com> Date: Wed, 3 May 2023 21:26:40 +0300 Subject: fix(editorconfig): add missing root validation (#23462) --- runtime/lua/editorconfig.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'runtime/lua/editorconfig.lua') diff --git a/runtime/lua/editorconfig.lua b/runtime/lua/editorconfig.lua index 5188c13284..a4024e5e7a 100644 --- a/runtime/lua/editorconfig.lua +++ b/runtime/lua/editorconfig.lua @@ -189,6 +189,7 @@ local function parse(filepath, dir) end elseif key ~= nil and val ~= nil then if key == 'root' then + assert(val == 'true' or val == 'false', 'root must be either "true" or "false"') opts.root = val == 'true' elseif pat and pat:match_str(filepath) then opts[key] = val -- cgit From cbbda3bcd77595eeabcc0fb70cee513e473833e6 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Mon, 5 Jun 2023 11:53:13 -0500 Subject: fix(editorconfig): check that buffer is valid (#23922) Fixes: https://github.com/neovim/neovim/issues/23921 --- runtime/lua/editorconfig.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'runtime/lua/editorconfig.lua') diff --git a/runtime/lua/editorconfig.lua b/runtime/lua/editorconfig.lua index a4024e5e7a..7311cccbe7 100644 --- a/runtime/lua/editorconfig.lua +++ b/runtime/lua/editorconfig.lua @@ -208,6 +208,10 @@ end ---@private function M.config(bufnr) bufnr = bufnr or vim.api.nvim_get_current_buf() + if not vim.api.nvim_buf_is_valid(bufnr) then + return + end + local path = vim.fs.normalize(vim.api.nvim_buf_get_name(bufnr)) if vim.bo[bufnr].buftype ~= '' or not vim.bo[bufnr].modifiable or path == '' then return -- cgit From dc45fb4655f5ce56c0bbcb179ef1c38149491d9f Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 23 Aug 2023 11:22:10 +0100 Subject: fix(editorconfig): only warn once on errors --- runtime/lua/editorconfig.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'runtime/lua/editorconfig.lua') diff --git a/runtime/lua/editorconfig.lua b/runtime/lua/editorconfig.lua index 7311cccbe7..48faa54d97 100644 --- a/runtime/lua/editorconfig.lua +++ b/runtime/lua/editorconfig.lua @@ -1,5 +1,6 @@ local M = {} +--- @type table M.properties = {} --- Modified version of the builtin assert that does not include error position information @@ -19,7 +20,7 @@ end --- ---@private local function warn(msg, ...) - vim.notify(string.format(msg, ...), vim.log.levels.WARN, { + vim.notify_once(string.format(msg, ...), vim.log.levels.WARN, { title = 'editorconfig', }) end @@ -168,12 +169,12 @@ end --- ---@param filepath string File path of the file to apply EditorConfig settings to ---@param dir string Current directory ----@return table Table of options to apply to the given file +---@return table Table of options to apply to the given file --- ---@private local function parse(filepath, dir) - local pat = nil - local opts = {} + local pat --- @type vim.regex? + local opts = {} --- @type table local f = io.open(dir .. '/.editorconfig') if f then for line in f:lines() do @@ -217,7 +218,7 @@ function M.config(bufnr) return end - local opts = {} + local opts = {} --- @type table for parent in vim.fs.parents(path) do for k, v in pairs(parse(path, parent)) do if opts[k] == nil then @@ -230,7 +231,7 @@ function M.config(bufnr) end end - local applied = {} + local applied = {} --- @type table for opt, val in pairs(opts) do if val ~= 'unset' then local func = M.properties[opt] -- cgit From abb8c2c453d1e084f8ab3e9bbaa8b27515c81a9f Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 25 Aug 2023 12:23:05 +0100 Subject: fix(editorconfig): do not set 'endofline' Problem: 'endofline' can be used to detect if a file ends of , however editorconfig can break this. Solution: Set 'endofline' during BufWritePre Fixes: #24869 --- runtime/lua/editorconfig.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'runtime/lua/editorconfig.lua') diff --git a/runtime/lua/editorconfig.lua b/runtime/lua/editorconfig.lua index 48faa54d97..49d63807a6 100644 --- a/runtime/lua/editorconfig.lua +++ b/runtime/lua/editorconfig.lua @@ -112,7 +112,20 @@ end function M.properties.insert_final_newline(bufnr, val) assert(val == 'true' or val == 'false', 'insert_final_newline must be either "true" or "false"') vim.bo[bufnr].fixendofline = val == 'true' - vim.bo[bufnr].endofline = val == 'true' + + -- 'endofline' can be read to detect if the file contains a final newline, + -- so only change 'endofline' right before writing the file + local endofline = val == 'true' + if vim.bo[bufnr].endofline ~= endofline then + vim.api.nvim_create_autocmd('BufWritePre', { + group = 'editorconfig', + buffer = bufnr, + once = true, + callback = function() + vim.bo[bufnr].endofline = endofline + end, + }) + end end --- Modified version of |glob2regpat()| that does not match path separators on *. -- cgit