From fde4cc2605558ea6d538a08c8d0304af9d7b2f8d Mon Sep 17 00:00:00 2001 From: S1M0N38 Date: Sat, 14 Sep 2024 13:44:41 +0200 Subject: [PATCH 1/4] feat: add callback and utility functions for chat completion - Added `callbacks.lua` with functions to handle chat completion, completion chunks, and exit events. - Refactored `init.lua` to use the new callback functions and utility functions. - Added `utils.lua` with helper functions for buffer operations and placeholder replacements. --- lua/dante/callbacks.lua | 63 ++++++++++++ lua/dante/init.lua | 212 +++++++++++++++------------------------- lua/dante/utils.lua | 80 +++++++++++++++ 3 files changed, 221 insertions(+), 134 deletions(-) create mode 100644 lua/dante/callbacks.lua create mode 100644 lua/dante/utils.lua diff --git a/lua/dante/callbacks.lua b/lua/dante/callbacks.lua new file mode 100644 index 0000000..114c0ba --- /dev/null +++ b/lua/dante/callbacks.lua @@ -0,0 +1,63 @@ +local M = {} + +---Callback function to handle the completion of a chat request. +---@param res table +---@param opts Options +---@return function +M.on_chat_completion = function(res, opts) + return function(obj) + local finish_reason = obj.choices[1].finish_reason + local content = obj.choices[1].message.content + if finish_reason == "stop" then + local lines = vim.split(content, "\n", { plain = true, trimempty = false }) + vim.api.nvim_buf_set_lines(res.buf, -2, -1, true, lines) + if opts.verbose and obj.usage then + vim.notify("usage = " .. vim.inspect(obj.usage), vim.log.levels.INFO) + end + vim.notify("Done.", vim.log.levels.INFO) + else + vim.notify("An error occured during text genereation.", vim.log.levels.ERROR) + end + end +end + +---Callback function to handle the completion chunk of a chat request. +---@param res table +---@param opts Options +---@return function +M.on_chat_completion_chunk = function(res, opts) + return function(obj) + local finish_reason = obj.choices[1].finish_reason + local content = obj.choices[1].delta.content + if finish_reason == vim.NIL then + local lines = vim.split(content, "\n", { plain = true, trimempty = false }) + local last_line, last_column = require("dante.utils").last(res.buf) + vim.api.nvim_buf_set_text(res.buf, last_line, last_column, last_line, last_column, lines) + if opts.verbose and obj.usage then + vim.notify("usage = " .. vim.inspect(obj.usage), vim.log.levels.INFO) + end + elseif finish_reason == "stop" then + vim.notify("Done.", vim.log.levels.INFO) + else + vim.notify("An error occured during text genereation.", vim.log.levels.ERROR) + end + end +end + +---Callback function to handle the exit of a chat request. +---@param res table +---@param req table +---@param opts Options +---@param after_lines string[] +---@return function +M.on_exit = function(res, req, opts, after_lines) + return function() + vim.api.nvim_buf_set_lines(res.buf, -1, -1, true, after_lines) + vim.api.nvim_set_current_win(res.win) + vim.cmd("diffthis") + vim.api.nvim_set_current_win(req.win) + vim.cmd("diffthis") + end +end + +return M diff --git a/lua/dante/init.lua b/lua/dante/init.lua index 4dc147b..e38e31d 100644 --- a/lua/dante/init.lua +++ b/lua/dante/init.lua @@ -1,168 +1,112 @@ local ai = require("ai") +local utils = require("dante.utils") +local callbacks = require("dante.callbacks") local dante = {} ----Setup global options for Dante ----@param options Options: global optoins for Dante. +--- Setup global options for Dante +---@param options Options: global options for Dante function dante.setup(options) require("dante.config").setup(options) end ----Replace all placeholders in the content string ----@param content string: The content string to be formatted ----@param start_line integer: The start line of the selected text ----@param end_line integer: The end line of the selected text ----@param buf integer: The buffer number of the selected text ----@return string: The formatted content string -function dante.format(content, start_line, end_line, buf) - local result = "" - local last_end = 1 - - -- Function to get the replacement for a placeholder - local function get_replacement(placeholder) - if placeholder == "{{SELECTED_LINES}}" then - local range_lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false) - return table.concat(range_lines, "\n") - elseif placeholder == "{{NOW}}" then - return os.date("Today is %a, %d %b %Y %H:%M:%S %z") - -- Add other placeholders here... - else - -- If not recognized, keep the original placeholder - vim.notify("Unrecognized placeholder: " .. placeholder, vim.log.levels.WARN) - return placeholder - end - end +--- Setup the UI for Dante +---@param opts Options: The options for Dante +local function setup_ui(opts) + -- Diff options + local diff = { + "internal", + "filler", + "closeoff", + "followwrap", + "iblank", + } + vim.cmd("set diffopt=" .. table.concat(diff, ",")) + + -- Request + local req = { + name = vim.api.nvim_buf_get_name(0), + buf = vim.api.nvim_get_current_buf(), + win = vim.api.nvim_get_current_win(), + } + + local buf_opts = { + ft = vim.bo.filetype, + } + + local win_opts = { + wrap = vim.wo.wrap, + lbr = vim.wo.linebreak, + bri = vim.wo.breakindent, + } - -- Find and replace all placeholders - for placeholder_start, placeholder_end in content:gmatch("(){{.-}}()") do - local placeholder = content:sub(placeholder_start, placeholder_end - 1) - result = result .. content:sub(last_end, placeholder_start - 1) - result = result .. get_replacement(placeholder) - last_end = placeholder_end + -- Response + local res = { + buf = vim.api.nvim_create_buf(false, true), + name = utils.generate_buf_name(), + } + vim.api.nvim_buf_set_name(res.buf, res.name) + for opt, value in pairs(buf_opts) do + vim.api.nvim_set_option_value(opt, value, { buf = res.buf }) end - -- Append any remaining content after the last placeholder - result = result .. content:sub(last_end) - - return result -end - ----Get the last line, column and line count in the chat buffer ----Thanks to Oli Morris for this function ----https://github.com/olimorris/codecompanion.nvim/blob/ ---- f8db284e1197a8cc4235afa30dcc3e8d4f3f45a5 ---- /lua/codecompanion/strategies/chat.lua#L987 ----@param buf integer: The buffer number ----@return integer: number of the last line ----@return integer: number of columns in the last line -local function last(buf) - local line_count = vim.api.nvim_buf_line_count(buf) - local last_line = line_count - 1 - if last_line < 0 then - return 0, 0 - end - local last_line_content = vim.api.nvim_buf_get_lines(buf, -2, -1, false) - if not last_line_content or #last_line_content == 0 then - return last_line, 0 + -- TODO: do not open the window if overlay | vertical | horizontal + res.win = vim.api.nvim_open_win(res.buf, true, { split = "right", win = req.win }) + for opt, value in pairs(win_opts) do + vim.api.nvim_set_option_value(opt, value, { win = res.win }) end - local last_column = #last_line_content[1] - return last_line, last_column + + return req, res end ----Represents a chat completion request to be sent to the model. ----Reference: https://platform.openai.com/docs/api-reference/chat/create +--- Represents a chat completion request to be sent to the model. +--- Reference: https://platform.openai.com/docs/api-reference/chat/create ----@alias RequestObject table (already defined in ai.nvim) ----Run Dante with the given preset ----@param preset_key string: One of the preset from options +--- Run Dante with the given preset +---@param preset_key string: One of the presets from options ---@param start_line integer: The start line of the selected text ---@param end_line integer: The end line of the selected text ---@return integer: Job id of the running job (curl request) function dante.main(preset_key, start_line, end_line) + local opts = require("dante.config").options + -- LLM Client - local options = require("dante.config").options - local preset = vim.deepcopy(options.presets[preset_key]) + local preset = vim.deepcopy(opts.presets[preset_key]) local client = ai.Client:new(preset.client.base_url, preset.client.api_key) -- Format the messages content (e.g. substitute selected text) for _, message in ipairs(preset.request.messages) do - message.content = dante.format(message.content, start_line, end_line) + message.content = utils.format(message.content, start_line, end_line) end - -- Request UI - local req_win = vim.api.nvim_get_current_win() - local req_buf = vim.api.nvim_get_current_buf() - local filetype = vim.bo.filetype - local wrap = vim.wo.wrap - local linebreak = vim.wo.linebreak - local breakindent = vim.wo.breakindent - vim.cmd("set diffopt=internal,filler,closeoff,followwrap,iblank") - - -- Generate a unique buffer name - local current_time = os.time() - local hex_time = string.format("%x", current_time) - local res_buf_name = "[Dante] " .. hex_time - - -- Response - vim.cmd("vsplit") - local res_win = vim.api.nvim_get_current_win() - local res_buf = vim.api.nvim_create_buf(false, true) - vim.api.nvim_win_set_buf(res_win, res_buf) - vim.api.nvim_buf_set_name(res_buf, res_buf_name) - vim.api.nvim_set_option_value("filetype", filetype, { buf = res_buf }) - vim.api.nvim_set_option_value("wrap", wrap, { win = res_win }) - vim.api.nvim_set_option_value("linebreak", linebreak, { win = res_win }) - vim.api.nvim_set_option_value("breakindent", breakindent, { win = res_win }) + local req, res = setup_ui(opts) -- Partition request buffer - local before_lines = vim.api.nvim_buf_get_lines(req_buf, 0, start_line - 1, true) - local after_lines = vim.api.nvim_buf_get_lines(req_buf, end_line, -1, true) + local before_lines = vim.api.nvim_buf_get_lines(req.buf, 0, start_line - 1, true) + local after_lines = vim.api.nvim_buf_get_lines(req.buf, end_line, -1, true) -- Add line before the response - vim.api.nvim_buf_set_lines(res_buf, 0, 0, true, before_lines) - vim.api.nvim_win_set_cursor(res_win, { start_line, 0 }) - - local function on_chat_completion(obj) - local finish_reason = obj.choices[1].finish_reason - local content = obj.choices[1].message.content - if finish_reason == "stop" then - local lines = vim.split(content, "\n", { plain = true, trimempty = false }) - vim.api.nvim_buf_set_lines(res_buf, -2, -1, true, lines) - if options.verbose and obj.usage then - vim.notify("usage = " .. vim.inspect(obj.usage), vim.log.levels.INFO) - end - vim.notify("Done.", vim.log.levels.INFO) - else - vim.notify("An error occured during text genereation.", vim.log.levels.ERROR) - end - end - - local function on_chat_completion_chunk(obj) - local finish_reason = obj.choices[1].finish_reason - local content = obj.choices[1].delta.content - if finish_reason == vim.NIL then - local lines = vim.split(content, "\n", { plain = true, trimempty = false }) - local last_line, last_column = last(res_buf) - vim.api.nvim_buf_set_text(res_buf, last_line, last_column, last_line, last_column, lines) - if options.verbose and obj.usage then - vim.notify("usage = " .. vim.inspect(obj.usage), vim.log.levels.INFO) - end - elseif finish_reason == "stop" then - vim.notify("Done.", vim.log.levels.INFO) - else - vim.notify("An error occured during text genereation.", vim.log.levels.ERROR) - end - end - - local function on_exit() - vim.api.nvim_buf_set_lines(res_buf, -1, -1, true, after_lines) - vim.api.nvim_set_current_win(res_win) - vim.cmd("diffthis") - vim.api.nvim_set_current_win(req_win) - vim.cmd("diffthis") - end - - return client:chat_completion_create(preset.request, on_chat_completion, on_chat_completion_chunk, nil, nil, on_exit) + vim.api.nvim_buf_set_lines(res.buf, 0, 0, true, before_lines) + + -- NOTE: maybe remove this + -- vim.api.nvim_win_set_cursor(res_win, { start_line, 0 }) + + local on_chat_completion = callbacks.on_chat_completion(res, opts) + local on_chat_completion_chunk = callbacks.on_chat_completion_chunk(res, opts) + + local on_stdout = nil -- use ai.nvim on_stdout + local on_stderr = nil -- use ai.nvim on_stderr + local on_exit = callbacks.on_exit(res, req, opts, after_lines) + + return client:chat_completion_create( + preset.request, + on_chat_completion, + on_chat_completion_chunk, + on_stdout, + on_stderr, + on_exit + ) end return dante diff --git a/lua/dante/utils.lua b/lua/dante/utils.lua new file mode 100644 index 0000000..cc32eea --- /dev/null +++ b/lua/dante/utils.lua @@ -0,0 +1,80 @@ +local M = {} + +---Get the last line, column and line count in the chat buffer +---Thanks to Oli Morris for this function +---https://github.com/olimorris/codecompanion.nvim/blob/ +--- f8db284e1197a8cc4235afa30dcc3e8d4f3f45a5 +--- /lua/codecompanion/strategies/chat.lua#L987 +---@param buf integer: The buffer number +---@return integer: number of the last line +---@return integer: number of columns in the last line +M.last = function(buf) + local line_count = vim.api.nvim_buf_line_count(buf) + local last_line = line_count - 1 + if last_line < 0 then + return 0, 0 + end + local last_line_content = vim.api.nvim_buf_get_lines(buf, -2, -1, false) + if not last_line_content or #last_line_content == 0 then + return last_line, 0 + end + local last_column = #last_line_content[1] + return last_line, last_column +end + +---Generate a unique buffer name. +---It uses the current time in hexadecimal format prefixed with "[Dante] ". +---@return string: The generated buffer name +M.generate_buf_name = function() + -- Generate a unique buffer name + local current_time = os.time() + local hex_time = string.format("%x", current_time) + local res_buf_name = "[Dante] " .. hex_time + return res_buf_name +end + +---Replace all placeholders in the content string +---This is the core function that enable the user specify how to add context in LLM requests. +---Supported place holders are: +--- - `{{SELECTED_LINES}}`: The selected lines in the editor from VISUAL mode +--- - `{{NOW}}`: The current date and time +---@param content string: The content string to be formatted +---@param start_line integer: The start line of the selected text +---@param end_line integer: The end line of the selected text +---@return string: The formatted content string +M.format = function(content, start_line, end_line) + local result = "" + local last_end = 1 + + ---Function to get the replacement for a placeholder + ---@param placeholder string: The placeholder to be replaced + ---@return string + local function get_replacement(placeholder) + if placeholder == "{{SELECTED_LINES}}" then + local range_lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false) + return table.concat(range_lines, "\n") + elseif placeholder == "{{NOW}}" then + return tostring(os.date("Today is %a, %d %b %Y %H:%M:%S %z")) + -- Add other placeholders here... + else + -- If not recognized, keep the original placeholder + vim.notify("Unrecognized placeholder: " .. placeholder, vim.log.levels.WARN) + return placeholder + end + end + + -- Find and replace all placeholders + for placeholder_start, placeholder_end in content:gmatch("(){{.-}}()") do + ---@diagnostic disable-next-line: param-type-mismatch + local placeholder = content:sub(placeholder_start, placeholder_end - 1) + result = result .. content:sub(last_end, placeholder_start - 1) + result = result .. get_replacement(placeholder) + last_end = placeholder_end + end + + -- Append any remaining content after the last placeholder + result = result .. content:sub(last_end) + return result +end + +return M From 7178882f9f115108316c381832aad3d735b05757 Mon Sep 17 00:00:00 2001 From: S1M0N38 Date: Sat, 14 Sep 2024 13:58:00 +0200 Subject: [PATCH 2/4] docs: update README.md for improved clarity and installation instructions Use `:%Dante README.md` on readme to enhance README.md --- README.md | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index fa2ce44..35a2500 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,7 @@ ______________________________________________________________________ > [!IMPORTANT] -> This is a heavily refactored version of the original dante.nvim plugin. If you want -> use the previous version, stick to the `a6955468391665d6465b371e81d1a80eac4cf0f1` commit. +> **Note on Version Compatibility**: This is a heavily refactored version of the original dante.nvim plugin. If you want to use the previous version, stick to the `a6955468391665d6465b371e81d1a80eac4cf0f1` commit. ## ⚡️ Requirements @@ -29,11 +28,13 @@ ______________________________________________________________________ ## 📦 Installation +You can install dante.nvim using your preferred plugin manager. Here's an example configuration for lazy.nvim: ```lua -- using lazy.nvim { "S1M0N38/dante.nvim", cmd = "Dante", + version = "*", opts = { presets = { ["default"] = { @@ -54,27 +55,19 @@ For a more complex configuration, check [my own config](https://github.com/S1M0N ## 🚀 Usage -Read the documentation with [`:help dante`](https://github.com/S1M0N38/dante.nvim/blob/main/doc/dante.txt) +To get started with dante.nvim, read the documentation with [`:help dante`](https://github.com/S1M0N38/dante.nvim/blob/main/doc/dante.txt). This will provide you with a comprehensive overview of the plugin's features and usage. > [!NOTE] -> Vim/Neovim plugins are usually shipped with :help documentation. Learning how -> to navigate it is a valuable skill. If you are not familiar with it, -> start with `:help` and read the first 20 lines. +> **Learning Vim/Neovim Documentation**: Vim/Neovim plugins are usually shipped with :help documentation. Learning how to navigate it is a valuable skill. If you are not familiar with it, start with `:help` and read the first 20 lines. > [!TIP] -> This plugin ships with a bare minimum configuration. The idea is that the -> user can define their own presets to interact with different LLM providers -> and customize the requests down to the last LLM parameter. The downside is -> that the opts table could become quite large and verbose, but in Neovim, -> configuration == code, so you can simplify it with utility functions. +> **Customizing Configuration**: This plugin ships with a bare minimum configuration. The idea is that the user can define their own presets to interact with different LLM providers and customize the requests down to the last LLM parameter. The downside is that the opts table could become quite large and verbose, but in Neovim, configuration == code, so you can simplify it with utility functions. ## 🙏 Acknowledgments -This plugin was inspired by: +This plugin was inspired by the following projects: -- [jackMort/ChatGPT.nvim](https://github.com/jackMort/ChatGPT.nvim) -- [David-Kunz/gen.nvim](https://github.com/David-Kunz/gen.nvim) -- [Bryley/neoai.nvim](https://github.com/Bryley/neoai.nvim) -- [olimorris/codecompanion.nvim](https://github.com/olimorris/codecompanion.nvim) - -This README is a copycat of [lazy.nvim](https://github.com/folke/lazy.nvim)'s README. +* [jackMort/ChatGPT.nvim](https://github.com/jackMort/ChatGPT.nvim) +* [David-Kunz/gen.nvim](https://github.com/David-Kunz/gen.nvim) +* [Bryley/neoai.nvim](https://github.com/Bryley/neoai.nvim) +* [olimorris/codecompanion.nvim](https://github.com/olimorris/codecompanion.nvim) From cd488cdcaaf06e90c2785d236ffab9ea54ce536c Mon Sep 17 00:00:00 2001 From: S1M0N38 Date: Sat, 14 Sep 2024 14:08:23 +0200 Subject: [PATCH 3/4] docs: update README and documentation for dante.nvim - Add `lazy = true` to the installation example in README.md. - Update the version specification in the installation example in doc/dante.txt. - Improve clarity and consistency in the documentation. - Reformat and simplify explanations for better readability. --- README.md | 2 ++ doc/dante.txt | 62 ++++++++++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 35a2500..bfca7ff 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,12 @@ ______________________________________________________________________ ## 📦 Installation You can install dante.nvim using your preferred plugin manager. Here's an example configuration for lazy.nvim: + ```lua -- using lazy.nvim { "S1M0N38/dante.nvim", + lazy = true, cmd = "Dante", version = "*", opts = { diff --git a/doc/dante.txt b/doc/dante.txt index 9a3b063..e2cbb11 100644 --- a/doc/dante.txt +++ b/doc/dante.txt @@ -20,6 +20,7 @@ example, using `lazy.nvim`: "S1M0N38/dante.nvim", lazy = true, cmd = "Dante", + version = "*", opts = { presets = { ["default"] = { @@ -31,10 +32,7 @@ example, using `lazy.nvim`: } } dependencies = { - { - "S1M0N38/ai.nvim", - version=">=1.1.0", - }, + { "S1M0N38/ai.nvim", version=">=1.1.0" }, } } < @@ -43,11 +41,11 @@ Usually, in the installation example, the plugin author provides the bare minimum setup. However, dante.nvim has very few options, so it makes sense to discuss them here. Here is a breakdown of the previous example: -- `S1M0N38/dante.nvim`: Where to download the plugin hosted on GitHub. +- `S1M0N38/dante.nvim`: The plugin's GitHub repository. - `cmd`: Load this plugin only when the `:Dante` command is called. - `opts`: A table with plugin options. See |dante.setup()|. -So, with this configuration, when the command `:Dante` is called: +When the `:Dante` command is called: 1. The `dante.nvim` plugin is loaded 2. |dante.setup()| is called with the `opts` table @@ -57,16 +55,16 @@ So, with this configuration, when the command `:Dante` is called: *dante.setup()* dante.setup({opts}) ~ - The `dante.setup()` function is a convention used by many plugins to set up - options provided by the user. It's so common that `lazy.nvim` automatically - calls the `dante.setup()` function using the `opts` table. + The `dante.setup()` function sets up options provided by the user. It's so + common that `lazy.nvim` automatically calls the `dante.setup()` function + using the `opts` table. The table `opts` that you specify will be merged with the default options, which are: >lua { - -- Notify with extra information + -- Enable verbose notifications verbose = false, presets = { @@ -108,18 +106,17 @@ dante.setup({opts}) ~ - `verbose`: If `true`, the plugin will notify you with extra information on completion. - - `presets`: This is a list of presets. The preset `default` is the only - preset available at the moment. The idea is that you can craft various - presets for various situations (e.g., just fix typos, refine an email, add - emojis to a readme, reformat a doc, etc.). Presets can differ in provider, - model, generation parameters, stream and messages. + - `presets`: A list of presets. The preset `default` is the only preset + available at the moment. You can craft various presets for various + situations (e.g., just fix typos, refine an email, add emojis to a readme, + reformat a doc, etc.). Presets can differ in provider, model, generation + parameters, stream, and messages. - - `client`: The client options are used to connect to the provider's API. + - `client`: Client options for connecting to the provider's API. - `base_url`: The base URL to connect to the provider's API - `api_key`: The API key to authenticate with the provider's API. - - `request`: This is a request object which follows the same schema as the - OpenAI request object + - `request`: A request object following the OpenAI request object schema (https://platform.openai.com/docs/api-reference/chat). OpenAI implements plenty of options, but not all compatible APIs support all of them, only the most common. @@ -127,20 +124,19 @@ dante.setup({opts}) ~ ================================================================================ PLACEHOLDERS *dante-placeholders* -Placeholders are used to inject context in request messages. They have the -form `{{PLACEHOLDER_NAME}}`. The following placeholders are supported: +Placeholders inject context into request messages and have the form +`{{PLACEHOLDER_NAME}}`. The following placeholders are supported: -- `{{SELECTED_LINES}}`: The selected lines in the buffer. This selection is - obtained from the range given while using the `Dante` command. See - |dante-commands|. +- `{{SELECTED_LINES}}`: The selected lines in the buffer, obtained from the + range given while using the `Dante` command. See |dante-commands|. -- `{{NOW}}`: It will be replaced by the current date and time. For example: - "Today is Wed, 04 Sep 2024 08:22:32 +0200" +- `{{NOW}}`: Replaced by the current date and time, e.g., "Today is Wed, 04 + Sep 2024 08:22:32 +0200" -The placeholders are processed as such only if they are defined in the preset. -If valid placeholders are present in the selected lines, they are not -processed and kept as they are. This choice helps keep the plugin simple and -avoid infinite loops. +Placeholders are processed only if defined in the preset. If valid +placeholders are present in the selected lines, they are not processed and +kept as they are. This choice keeps the plugin simple and avoids infinite +loops. ================================================================================ COMMANDS *dante-commands* @@ -148,10 +144,10 @@ COMMANDS *dante-commands* There is only one command provided by the plugin: :{range}Dante [preset] ~ - The `Dante` command requires a range to work. It will substitute the - placeholder `{{SELECTED_LINES}}` with the selected lines in the buffer and - query the LLM provider with the specified preset. If no preset is given, it - will use the default preset. + The `Dante` command requires a range to work. It substitutes the placeholder + `{{SELECTED_LINES}}` with the selected lines in the buffer and queries the + LLM provider with the specified preset. If no preset is given, it uses the + default preset. The range can be specified in the following ways: - `:'<,'>Dante` Run the command in visual mode to use the selected lines. From 1971d5e842de18d2c4d1798a7d05e715d2e2bebd Mon Sep 17 00:00:00 2001 From: S1M0N38 Date: Sat, 14 Sep 2024 14:14:17 +0200 Subject: [PATCH 4/4] chore: suppress unused-local diagnostic warnings - Added `---@diagnostic disable-next-line: unused-local` to suppress warnings for unused local variables in `callbacks.lua` and `init.lua`. --- lua/dante/callbacks.lua | 1 + lua/dante/init.lua | 1 + 2 files changed, 2 insertions(+) diff --git a/lua/dante/callbacks.lua b/lua/dante/callbacks.lua index 114c0ba..0c7b367 100644 --- a/lua/dante/callbacks.lua +++ b/lua/dante/callbacks.lua @@ -50,6 +50,7 @@ end ---@param opts Options ---@param after_lines string[] ---@return function +---@diagnostic disable-next-line: unused-local M.on_exit = function(res, req, opts, after_lines) return function() vim.api.nvim_buf_set_lines(res.buf, -1, -1, true, after_lines) diff --git a/lua/dante/init.lua b/lua/dante/init.lua index e38e31d..d7a5305 100644 --- a/lua/dante/init.lua +++ b/lua/dante/init.lua @@ -12,6 +12,7 @@ end --- Setup the UI for Dante ---@param opts Options: The options for Dante +---@diagnostic disable-next-line: unused-local local function setup_ui(opts) -- Diff options local diff = {