enable ctags if present

This commit is contained in:
Paul Gauthier 2023-05-26 16:03:24 -07:00
parent ae087287c7
commit 43413654bd

View file

@ -50,16 +50,18 @@ def fname_to_components(fname, with_colon):
class RepoMap:
ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"]
def __init__(self, use_ctags=True, root=None, main_model="gpt-4"):
if not self.check_for_ctags():
use_ctags = False
def __init__(self, use_ctags=None, root=None, main_model="gpt-4"):
if not root:
root = os.getcwd()
self.use_ctags = use_ctags
self.tokenizer = tiktoken.encoding_for_model(main_model)
self.root = root
if use_ctags is None:
self.use_ctags = self.check_for_ctags()
else:
self.use_ctags = use_ctags
self.tokenizer = tiktoken.encoding_for_model(main_model)
def get_repo_map(self, chat_files, other_files):
res = self.choose_files_listing(other_files)
if not res:
@ -164,6 +166,7 @@ class RepoMap:
# Update the cache
TAGS_CACHE[cache_key] = {"mtime": file_mtime, "tags": tags}
return tags
def check_for_ctags(self):
try:
@ -176,6 +179,7 @@ class RepoMap:
return False
return True
if __name__ == "__main__":
rm = RepoMap()
res = rm.get_tags_map(sys.argv[1:])