diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fb88ce0..98a1032a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,9 @@ ## [1.0.1](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.0.0...v1.0.1) (2024-02-08) - ### Bug Fixes -* multi-byte languages by manually tracking last_line_col for buf_set_text ([20a4234](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/20a4234a542deef1a128aca4d0dd7e8d429a1f2a)) +- multi-byte languages by manually tracking last_line_col for buf_set_text ([20a4234](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/20a4234a542deef1a128aca4d0dd7e8d429a1f2a)) ## 1.0.0 (2024-02-06) diff --git a/README.md b/README.md index 8ccf84a2..05958b6d 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ return { show_help = "yes", -- Show help text for CopilotChatInPlace, default: yes debug = false, -- Enable or disable debug mode, the log file will be in ~/.local/state/nvim/CopilotChat.nvim.log disable_extra_info = 'no', -- Disable extra information (e.g: system prompt) in the response. + -- proxy = "socks5://127.0.0.1:3000", -- Proxies requests via https or socks. }, build = function() vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.") diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index 9fe5f325..08b2de8d 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -18,6 +18,7 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {} M.setup = function(options) vim.g.copilot_chat_show_help = options and options.show_help or 'yes' vim.g.copilot_chat_disable_separators = options and options.disable_extra_info or 'yes' + vim.g.copilot_chat_proxy = options and options.proxy or '' local debug = options and options.debug or false _COPILOT_CHAT_GLOBAL_CONFIG.debug = debug diff --git a/rplugin/python3/copilot.py b/rplugin/python3/copilot.py index 4a86ae26..25dbba67 100644 --- a/rplugin/python3/copilot.py +++ b/rplugin/python3/copilot.py @@ -22,7 +22,7 @@ class Copilot: - def __init__(self, token: str = None): + def __init__(self, token: str = None, proxy: str = None): if token is None: token = utilities.get_cached_token() self.github_token = token @@ -33,6 +33,9 @@ def __init__(self, token: str = None): self.session = requests.Session() + if proxy: + self.session.proxies = {"https": proxy} + def request_auth(self): url = "https://github.com/login/device/code" diff --git a/rplugin/python3/handlers/chat_handler.py b/rplugin/python3/handlers/chat_handler.py index 2d9ade76..d585bddd 100644 --- a/rplugin/python3/handlers/chat_handler.py +++ b/rplugin/python3/handlers/chat_handler.py @@ -24,6 +24,7 @@ def __init__(self, nvim: MyNvim, buffer: MyBuffer): self.nvim: MyNvim = nvim self.copilot: Copilot = None self.buffer: MyBuffer = buffer + self.proxy: str = None # public @@ -41,6 +42,10 @@ def chat( disable_separators = ( self.nvim.eval("g:copilot_chat_disable_separators") == "yes" ) + self.proxy = self.nvim.eval("g:copilot_chat_proxy") + if "://" not in self.proxy: + self.proxy = None + if system_prompt is None: system_prompt = self._construct_system_prompt(prompt) # Start the spinner @@ -201,7 +206,7 @@ def _add_chat_messages( self, system_prompt: str, prompt: str, code: str, file_type: str, model: str ): if self.copilot is None: - self.copilot = Copilot() + self.copilot = Copilot(proxy=self.proxy) if self.copilot.github_token is None: req = self.copilot.request_auth() self.nvim.out_write(