aider: Modified get_tags to run ctags command and capture JSON output.

# Context:
USER: in get_tags, run `ctags --fields=+S --output-format=json $f` on the filename and collect the json output instead of reading json from filename. use that json data for the rest of the func
ASSISTANT: To modify the `get_tags` function in `aider/ctags.py` to run `ctags --fields=+S --output-format=json $f` on the filename and collect the JSON output, we will need to use the `subprocess` module to run the command and capture the output. Here are the changes:

```python
aider/ctags.py
<<<<<<< ORIGINAL
def get_tags(filename):
    with open(filename, "r") as tags_file:
        for line in tags_file:
            tag = json.loads(line)
=======
import subprocess

def get_tags(filename):
    cmd = ["ctags", "--fields=+S", "--output-format=json", filename]
    output = subprocess.check_output(cmd).decode("utf-8")
    for line in output.splitlines():
        tag = json.loads(line)
>>>>>>> UPDATED
```

This change imports the `subprocess` module, replaces the `with open(filename, "r")` block with a `subprocess.check_output` call to run the `ctags` command, and iterates over the output lines instead of the file lines.
This commit is contained in:
Paul Gauthier 2023-05-19 08:42:09 -07:00
parent efe05b6d8a
commit f5c6667de3

View file

@ -22,10 +22,13 @@ def print_tags_info(filename):
last = tag
import subprocess
def get_tags(filename):
with open(filename, "r") as tags_file:
for line in tags_file:
tag = json.loads(line)
cmd = ["ctags", "--fields=+S", "--output-format=json", filename]
output = subprocess.check_output(cmd).decode("utf-8")
for line in output.splitlines():
tag = json.loads(line)
path = tag.get("path")
scope = tag.get("scope")
kind = tag.get("kind")