aider: Added line numbers to the output of the get_quoted_file function.

# Context:
USER: git get_files_content prefix each line with a line number, starting at 1, padded out like '  1'
ASSISTANT: To add line numbers to the `get_files_content` method, we will modify the method in the `aider/coder.py` file. We will read the file content line by line and add the line number with padding to each line.

Here's the change:

```python
aider/coder.py
<<<<<<< ORIGINAL
    def get_files_content(self, fnames=None):
        if not fnames:
            fnames = self.abs_fnames

        prompt = ""
        for fname in fnames:
            relative_fname = self.get_rel_fname(fname)
            prompt += utils.quoted_file(fname, relative_fname)
        return prompt
=======
    def get_files_content(self, fnames=None):

^C KeyboardInterrupt
USER: sorry, in get_quoted_file prefix each line with a line number, starting at 1, padded out like '  1'
ASSISTANT:
^C KeyboardInterrupt
USER: Please note that I shared content of these additional files: aider/utils.py
ASSISTANT: To add line
^C KeyboardInterrupt
USER: in get_quoted_file prefix each line with a line number, starting at 1, padded out like '  1'
ASSISTANT: To add line numbers to the `get_quoted_file` function in the `aider/utils.py` file, we will read the file content line by line and add the line number with padding to each line.

Here's the change:

```python
aider/utils.py
<<<<<<< ORIGINAL
def quoted_file(fname, display_fname):
    prompt = "\n"
    prompt += display_fname
    prompt += "\n```\n"
    prompt += Path(fname).read_text()
    prompt += "\n```\n"
    return prompt
=======
def quoted_file(fname, display_fname):
    prompt = "\n"
    prompt += display_fname
    prompt += "\n```\n"
    file_content = Path(fname).read_text()
    lines = file_content.splitlines()
    for i, line in enumerate(lines, start=1):
        prompt += f"{i:3d} {line}\n"
    prompt += "```\n"
    return prompt
>>>>>>> UPDATED
```

This change will add line numbers to the output of the `get_quoted_file` function, starting at 1 and padded out like '  1'.
This commit is contained in:
Paul Gauthier 2023-05-18 07:00:50 -07:00
parent 8913eb5066
commit 891d5b2263

View file

@ -118,8 +118,11 @@ def quoted_file(fname, display_fname):
prompt = "\n"
prompt += display_fname
prompt += "\n```\n"
prompt += Path(fname).read_text()
prompt += "\n```\n"
file_content = Path(fname).read_text()
lines = file_content.splitlines()
for i, line in enumerate(lines, start=1):
prompt += f"{i:3d} {line}\n"
prompt += "```\n"
return prompt