mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 18:54:59 +00:00
refac
This commit is contained in:
parent
60031ecd29
commit
3ecf008478
1 changed files with 14 additions and 8 deletions
|
@ -124,23 +124,32 @@ class RepoMap:
|
||||||
path = os.path.relpath(path, self.root)
|
path = os.path.relpath(path, self.root)
|
||||||
return fname_to_components(path, True)
|
return fname_to_components(path, True)
|
||||||
|
|
||||||
def get_tags(self, filename):
|
def run_ctags(self, filename):
|
||||||
# Check if the file is in the cache and if the modification time has not changed
|
# Check if the file is in the cache and if the modification time has not changed
|
||||||
file_mtime = os.path.getmtime(filename)
|
file_mtime = os.path.getmtime(filename)
|
||||||
cache_key = filename
|
cache_key = filename
|
||||||
if cache_key in TAGS_CACHE and TAGS_CACHE[cache_key]["mtime"] == file_mtime:
|
if cache_key in TAGS_CACHE and TAGS_CACHE[cache_key]["mtime"] == file_mtime:
|
||||||
return TAGS_CACHE[cache_key]["tags"]
|
return TAGS_CACHE[cache_key]["data"]
|
||||||
|
|
||||||
cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json", filename]
|
cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json", filename]
|
||||||
output = subprocess.check_output(cmd).decode("utf-8")
|
output = subprocess.check_output(cmd).decode("utf-8")
|
||||||
output = output.splitlines()
|
output = output.splitlines()
|
||||||
|
|
||||||
|
data = [json.loads(line) for line in output]
|
||||||
|
|
||||||
|
# Update the cache
|
||||||
|
TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data}
|
||||||
|
return data
|
||||||
|
|
||||||
|
def get_tags(self, filename):
|
||||||
|
data = self.run_ctags(filename)
|
||||||
|
|
||||||
tags = []
|
tags = []
|
||||||
if not output:
|
|
||||||
|
if not data:
|
||||||
tags.append(self.split_path(filename))
|
tags.append(self.split_path(filename))
|
||||||
|
|
||||||
for line in output:
|
for tag in data:
|
||||||
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")
|
||||||
|
@ -157,9 +166,6 @@ class RepoMap:
|
||||||
res += [kind, last]
|
res += [kind, last]
|
||||||
tags.append(res)
|
tags.append(res)
|
||||||
|
|
||||||
# Update the cache
|
|
||||||
TAGS_CACHE[cache_key] = {"mtime": file_mtime, "tags": tags}
|
|
||||||
|
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue