mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
Refactor ctags.py to print tags with indentation.
This commit is contained in:
parent
7d45b918fc
commit
cceb7c3bef
1 changed files with 33 additions and 20 deletions
|
@ -1,26 +1,26 @@
|
|||
import os
|
||||
import json
|
||||
import sys
|
||||
|
||||
from aider.dump import dump
|
||||
|
||||
def print_tags_info(filename):
|
||||
last = None
|
||||
tags = sorted(get_tags(filename))
|
||||
|
||||
last = [None] * len(tags[0])
|
||||
tab = ' '
|
||||
for tag in tags:
|
||||
if last is None:
|
||||
show = tag
|
||||
else:
|
||||
show = []
|
||||
for lst, tg in zip(last, tag):
|
||||
if lst == tg:
|
||||
show.append("")
|
||||
else:
|
||||
show.append(tg)
|
||||
|
||||
if not show[-1]:
|
||||
show = show[:-1]
|
||||
show = "\t".join(show)
|
||||
print(show)
|
||||
tag = list(tag)
|
||||
common_prefix = [
|
||||
tag_i for tag_i,last_i in zip(tag,last)
|
||||
if tag_i == last_i
|
||||
]
|
||||
num_common = len(common_prefix)
|
||||
indent = tab * num_common
|
||||
rest = tag[num_common:]
|
||||
for item in rest:
|
||||
print(indent + item)
|
||||
indent += tab
|
||||
last = tag
|
||||
|
||||
|
||||
|
@ -28,11 +28,24 @@ def get_tags(filename):
|
|||
with open(filename, "r") as tags_file:
|
||||
for line in tags_file:
|
||||
tag = json.loads(line)
|
||||
scope = tag.get("scope", "(top)")
|
||||
kind = tag.get("kind", "")
|
||||
name = tag.get("name", "")
|
||||
signature = tag.get("signature", "")
|
||||
yield (scope, kind, name, signature)
|
||||
path = tag.get("path")
|
||||
scope = tag.get("scope")
|
||||
kind = tag.get("kind")
|
||||
name = tag.get("name")
|
||||
signature = tag.get("signature")
|
||||
|
||||
last = name
|
||||
if signature:
|
||||
last += ' ' + signature
|
||||
|
||||
path = os.path.relpath(path, os.getcwd())
|
||||
|
||||
res = []
|
||||
if scope:
|
||||
res.append(scope)
|
||||
res += [kind, last]
|
||||
|
||||
yield res
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue