From 1f16b15f92dfe446136282c320d2607b49990af7 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 3 Jul 2023 10:30:45 -0700 Subject: [PATCH] Added more clear error messages when universal-ctags is disabled per issue #31 --- README.md | 2 ++ aider/coders/base_coder.py | 3 ++- aider/repomap.py | 25 +++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 374076161..e48cdc033 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ You can find more chat transcripts on the [examples page](https://aider.chat/exa * Or, by including `openai-api-key: sk-...` in an `.aider.config.yml` file 3. Optionally, install [universal ctags](https://github.com/universal-ctags/ctags). This is helpful if you plan to use aider and GPT-4 with repositories that have more than a handful of files. This allows aider to build a [map of your entire git repo](https://aider.chat/docs/ctags.html) and share it with GPT to help it better understand and modify large codebases. + * The `ctags` command needs to be on your shell path so that it will run by default when aider invokes `ctags ...`. + * You need a build which includes the json feature. You can check by running `ctags --version` and looking for `+json` in the `Optional compiled features` list. ## Usage diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 2fbe55666..ebeacc0e9 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -178,7 +178,8 @@ class Coder: self.io.tool_output(f"Repo-map: universal-ctags using {map_tokens} tokens") elif not self.repo_map.has_ctags and map_tokens > 0: self.io.tool_output( - f"Repo-map: basic using {map_tokens} tokens (universal-ctags not found)" + f"Repo-map: basic using {map_tokens} tokens" + f" ({self.repo_map.ctags_disabled_reason})" ) else: self.io.tool_output("Repo-map: disabled because map_tokens == 0") diff --git a/aider/repomap.py b/aider/repomap.py index 2e0459091..fab94ec27 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -65,6 +65,8 @@ class RepoMap: IDENT_CACHE_DIR = f".aider.ident.cache.v{CACHE_VERSION}" TAGS_CACHE_DIR = f".aider.tags.cache.v{CACHE_VERSION}" + ctags_disabled_reason = "ctags not initialized" + def __init__( self, map_tokens=1024, @@ -180,13 +182,32 @@ class RepoMap: def check_for_ctags(self): try: + executable = self.ctags_cmd[0] + cmd = [executable, "--version"] + output = subprocess.check_output(cmd, stderr=subprocess.PIPE).decode("utf-8") + output = output.lower() + + cmd = " ".join(cmd) + + if "universal ctags" not in output: + self.ctags_disabled_reason = f"{cmd} does not claim to be universal ctags" + return + if "+json" not in output: + self.ctags_disabled_reason = f"{cmd} does not list +json support" + return + with tempfile.TemporaryDirectory() as tempdir: hello_py = os.path.join(tempdir, "hello.py") with open(hello_py, "w") as f: f.write("def hello():\n print('Hello, world!')\n") self.run_ctags(hello_py) - except Exception: - return False + except FileNotFoundError: + self.ctags_disabled_reason = f"{executable} executable not found" + return + except Exception as err: + self.ctags_disabled_reason = f"error running universal-ctags: {err}" + return + return True def load_tags_cache(self):