diff --git a/rplugin/python3/copilot-agent.py b/rplugin/python3/copilot-agent.py index 3ac008df..b8480870 100644 --- a/rplugin/python3/copilot-agent.py +++ b/rplugin/python3/copilot-agent.py @@ -33,7 +33,7 @@ def copilot_agent_visual_cmd(self, args: list[str], range: list[int]): self.init_vsplit_chat_handler() if self.vsplit_chat_handler: file_type = self.nvim.current.buffer.options["filetype"] - code_lines = self.nvim.current.buffer[range[0] - 1 : range[1]] + code_lines = self.nvim.current.buffer[range[0] - 1: range[1]] code = "\n".join(code_lines) self.vsplit_chat_handler.vsplit() self.vsplit_chat_handler.chat(args[0], file_type, code) @@ -58,7 +58,7 @@ def inplace_cmd(self, args: list[str], range: list[int]): self.init_inplace_chat_handler() if self.inplace_chat_handler: file_type = self.nvim.current.buffer.options["filetype"] - code_lines = self.nvim.current.buffer[range[0] - 1 : range[1]] + code_lines = self.nvim.current.buffer[range[0] - 1: range[1]] code = "\n".join(code_lines) user_buffer = self.nvim.current.buffer self.inplace_chat_handler.mount(code, file_type, range, user_buffer) diff --git a/rplugin/python3/copilot.py b/rplugin/python3/copilot.py index 3b849637..ef35415d 100644 --- a/rplugin/python3/copilot.py +++ b/rplugin/python3/copilot.py @@ -9,7 +9,6 @@ from prompt_toolkit.history import InMemoryHistory import utilities import typings -import prompts from typing import List, Dict LOGIN_HEADERS = { @@ -88,6 +87,8 @@ def authenticate(self): self.token = self.session.get(url, headers=headers).json() def ask(self, system_prompt: str, prompt: str, code: str, language: str = ""): + if not self.token: + self.authenticate() # If expired, reauthenticate if self.token.get("expires_at") <= round(time.time()): self.authenticate()