Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
chore: sync the change from CopilotC-Nvim#9
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Jan 3, 2024
1 parent 97fcd70 commit 4943f94
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions rplugin/python3/copilot-plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,33 @@ def copilotChat(self, args: list[str]):
# Set filetype as markdown and wrap with linebreaks
self.nvim.command("setlocal filetype=markdown wrap linebreak")

# if self.nvim.current.line != "":
# Go to end of file and insert a new line
self.nvim.command("normal Go")
self.nvim.current.line += "### User"
self.nvim.command("normal o")
# TODO: How to handle the case with the large text in from neovim command
self.nvim.current.line += prompt
self.nvim.command("normal o")
self.nvim.current.line += "### Copilot"
self.nvim.command("normal o")
# Get the current buffer
buf = self.nvim.current.buffer

# Add start separator
start_separator = f"""### User
{prompt}
### Copilot
"""
buf.append(start_separator.split("\n"), -1)

# Add chat messages
for token in self.copilot.ask(prompt, code, language=file_type):
if "\n" not in token:
self.nvim.current.line += token
continue
lines = token.split("\n")
for i in range(len(lines)):
self.nvim.current.line += lines[i]
if i != len(lines) - 1:
self.nvim.command("normal o")

self.nvim.command("normal o")
self.nvim.current.line += ""
self.nvim.command("normal o")
self.nvim.current.line += "---"
buffer_lines = self.nvim.api.buf_get_lines(buf, 0, -1, 0)
last_line_row = len(buffer_lines) - 1
last_line_col = len(buffer_lines[-1])

self.nvim.api.buf_set_text(
buf,
last_line_row,
last_line_col,
last_line_row,
last_line_col,
token.split("\n"),
)

# Add end separator
end_separator = "\n---\n"
buf.append(end_separator.split("\n"), -1)

0 comments on commit 4943f94

Please sign in to comment.