From f5c6667de3b92307a6737633e6d284c6ba6fba62 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 19 May 2023 08:42:09 -0700 Subject: [PATCH] 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. --- aider/ctags.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/aider/ctags.py b/aider/ctags.py index fd82ae7d6..c029d1a59 100644 --- a/aider/ctags.py +++ b/aider/ctags.py @@ -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")