include files with no tags

This commit is contained in:
Paul Gauthier 2023-05-19 08:47:17 -07:00
parent dfd2c495ea
commit f8d8a3528b

View file

@ -3,11 +3,13 @@ import json
import sys import sys
import subprocess import subprocess
# from aider.dump import dump from aider.dump import dump
def print_tags_info(filename): def print_tags_info(filename):
tags = sorted(get_tags(filename)) tags = sorted(get_tags(filename))
if not tags:
return
last = [None] * len(tags[0]) last = [None] * len(tags[0])
tab = " " tab = " "
@ -23,32 +25,39 @@ def print_tags_info(filename):
last = tag last = tag
def split_path(path):
path = os.path.relpath(path, os.getcwd())
path_components = path.split(os.sep)
res = [pc + os.sep for pc in path_components[:-1]]
res.append(path_components[-1])
return res
def get_tags(filename): def get_tags(filename):
yield split_path(filename)
cmd = ["ctags", "--fields=+S", "--output-format=json", filename] cmd = ["ctags", "--fields=+S", "--output-format=json", filename]
output = subprocess.check_output(cmd).decode("utf-8") output = subprocess.check_output(cmd).decode("utf-8")
for line in output.splitlines(): output = output.splitlines()
for line in output:
tag = json.loads(line) tag = json.loads(line)
path = tag.get("path") path = tag.get("path")
scope = tag.get("scope") scope = tag.get("scope")
kind = tag.get("kind") kind = tag.get("kind")
name = tag.get("name") name = tag.get("name")
signature = tag.get("signature") signature = tag.get("signature")
last = name last = name
if signature: if signature:
last += " " + signature last += " " + signature
path = os.path.relpath(path, os.getcwd()) res = split_path(path)
path_components = path.split(os.sep) if scope:
res.append(scope)
res += [kind, last]
res = [pc + os.sep for pc in path_components[:-1]] yield res
res.append(path_components[-1])
if scope:
res.append(scope)
res += [kind, last]
yield res
if __name__ == "__main__": if __name__ == "__main__":