diff --git a/README.md b/README.md index 0f9ed9e4..49c1969f 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ require('copilot').setup({ copilot_node_command = 'node', -- Node.js version must be > 20 workspace_folders = {}, copilot_model = "", + disable_limit_reached_message = false, -- Set to `true` to suppress completion limit reached popup root_dir = function() return vim.fs.dirname(vim.fs.find(".git", { upward = true })[1]) end, diff --git a/lua/copilot/client/handlers.lua b/lua/copilot/client/handlers.lua index b8b1c65f..65c42d3e 100644 --- a/lua/copilot/client/handlers.lua +++ b/lua/copilot/client/handlers.lua @@ -35,6 +35,19 @@ function M.get_handlers() }) end + if config.disable_limit_reached_message then + handlers["window/showMessageRequest"] = (function(overridden) + return function(err, params, ctx) + if params.message:match([[^You've reached.*limit.*Upgrade.*$]]) then + -- ignore + logger.trace("API limited:", params.message) + return vim.NIL + end + return overridden(err, params, ctx) + end + end)(vim.lsp.handlers["window/showMessageRequest"]) + end + return handlers end diff --git a/lua/copilot/config/init.lua b/lua/copilot/config/init.lua index 9e864205..a15ecf61 100644 --- a/lua/copilot/config/init.lua +++ b/lua/copilot/config/init.lua @@ -13,6 +13,7 @@ local logger = require("copilot.logger") ---@field root_dir RootDirFuncOrString Root directory for the project, defaults to the nearest .git directory ---@field should_attach ShouldAttachFunc Function to determine if Copilot should attach to the buffer ---@field copilot_node_command string Path to the Node.js executable, defaults to "node" +---@field disable_limit_reached_message boolean Disable the limit reached message, defaults to false local initialized = false @@ -30,6 +31,7 @@ local M = { server_opts_overrides = {}, copilot_model = nil, copilot_node_command = "node", + disable_limit_reached_message = false, } ---@param user_configs CopilotConfig