From 7dfec2af0a00c3d9bc839ec1aa72164afae53ad5 Mon Sep 17 00:00:00 2001 From: Deepak Seeni Date: Tue, 18 Feb 2025 07:15:14 -0800 Subject: [PATCH] Fix: Backwards compatible Nvim v7 file encoding query --- lua/copilot/suggestion.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lua/copilot/suggestion.lua b/lua/copilot/suggestion.lua index 36378998..78045769 100644 --- a/lua/copilot/suggestion.lua +++ b/lua/copilot/suggestion.lua @@ -487,9 +487,16 @@ function mod.accept(modifier) vim.schedule_wrap(function() vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "n", false) local bufnr = vim.api.nvim_get_current_buf() - local encoding = vim.api.nvim_get_option_value("fileencoding", { buf = bufnr }) ~= "" - and vim.api.nvim_get_option_value("fileencoding", { buf = bufnr }) - or vim.api.nvim_get_option_value("encoding", { scope = "global" }) + local encoding = nil + if vim.version().minor == 7 then + encoding = vim.api.nvim_buf_get_option(bufnr, "fileencoding") ~= "" + and vim.api.nvim_buf_get_option(bufnr, "fileencoding") + or vim.api.nvim_get_option_value("encoding", { scope = "global" }) + else + encoding = vim.api.nvim_get_option_value("fileencoding", { buf = bufnr }) ~= "" + and vim.api.nvim_get_option_value("fileencoding", { buf = bufnr }) + or vim.api.nvim_get_option_value("encoding", { scope = "global" }) + end vim.lsp.util.apply_text_edits({ { range = range, newText = newText } }, bufnr, encoding) -- Put cursor at the end of current line. local cursor_keys = ""