mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 18:54:59 +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 json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from aider.dump import dump
|
||||||
|
|
||||||
def print_tags_info(filename):
|
def print_tags_info(filename):
|
||||||
last = None
|
|
||||||
tags = sorted(get_tags(filename))
|
tags = sorted(get_tags(filename))
|
||||||
|
|
||||||
|
last = [None] * len(tags[0])
|
||||||
|
tab = ' '
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
if last is None:
|
tag = list(tag)
|
||||||
show = tag
|
common_prefix = [
|
||||||
else:
|
tag_i for tag_i,last_i in zip(tag,last)
|
||||||
show = []
|
if tag_i == last_i
|
||||||
for lst, tg in zip(last, tag):
|
]
|
||||||
if lst == tg:
|
num_common = len(common_prefix)
|
||||||
show.append("")
|
indent = tab * num_common
|
||||||
else:
|
rest = tag[num_common:]
|
||||||
show.append(tg)
|
for item in rest:
|
||||||
|
print(indent + item)
|
||||||
if not show[-1]:
|
indent += tab
|
||||||
show = show[:-1]
|
|
||||||
show = "\t".join(show)
|
|
||||||
print(show)
|
|
||||||
last = tag
|
last = tag
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,11 +28,24 @@ def get_tags(filename):
|
||||||
with open(filename, "r") as tags_file:
|
with open(filename, "r") as tags_file:
|
||||||
for line in tags_file:
|
for line in tags_file:
|
||||||
tag = json.loads(line)
|
tag = json.loads(line)
|
||||||
scope = tag.get("scope", "(top)")
|
path = tag.get("path")
|
||||||
kind = tag.get("kind", "")
|
scope = tag.get("scope")
|
||||||
name = tag.get("name", "")
|
kind = tag.get("kind")
|
||||||
signature = tag.get("signature", "")
|
name = tag.get("name")
|
||||||
yield (scope, kind, name, signature)
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue