Added more clear error messages when universal-ctags is disabled per issue #31

This commit is contained in:
Paul Gauthier 2023-07-03 10:30:45 -07:00
parent e98db7dfce
commit 1f16b15f92
3 changed files with 27 additions and 3 deletions

View file

@ -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 * 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. 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 ## Usage

View file

@ -178,7 +178,8 @@ class Coder:
self.io.tool_output(f"Repo-map: universal-ctags using {map_tokens} tokens") self.io.tool_output(f"Repo-map: universal-ctags using {map_tokens} tokens")
elif not self.repo_map.has_ctags and map_tokens > 0: elif not self.repo_map.has_ctags and map_tokens > 0:
self.io.tool_output( 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: else:
self.io.tool_output("Repo-map: disabled because map_tokens == 0") self.io.tool_output("Repo-map: disabled because map_tokens == 0")

View file

@ -65,6 +65,8 @@ class RepoMap:
IDENT_CACHE_DIR = f".aider.ident.cache.v{CACHE_VERSION}" IDENT_CACHE_DIR = f".aider.ident.cache.v{CACHE_VERSION}"
TAGS_CACHE_DIR = f".aider.tags.cache.v{CACHE_VERSION}" TAGS_CACHE_DIR = f".aider.tags.cache.v{CACHE_VERSION}"
ctags_disabled_reason = "ctags not initialized"
def __init__( def __init__(
self, self,
map_tokens=1024, map_tokens=1024,
@ -180,13 +182,32 @@ class RepoMap:
def check_for_ctags(self): def check_for_ctags(self):
try: 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: with tempfile.TemporaryDirectory() as tempdir:
hello_py = os.path.join(tempdir, "hello.py") hello_py = os.path.join(tempdir, "hello.py")
with open(hello_py, "w") as f: with open(hello_py, "w") as f:
f.write("def hello():\n print('Hello, world!')\n") f.write("def hello():\n print('Hello, world!')\n")
self.run_ctags(hello_py) self.run_ctags(hello_py)
except Exception: except FileNotFoundError:
return False 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 return True
def load_tags_cache(self): def load_tags_cache(self):