mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 09:14:59 +00:00
refac
This commit is contained in:
parent
4a1e252bfc
commit
a7ca584859
1 changed files with 13 additions and 16 deletions
|
@ -207,34 +207,30 @@ class RepoMap:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_name_identifiers(self, fname, uniq=True):
|
def get_name_identifiers(self, fname, uniq=True):
|
||||||
cached = self.IDENT_CACHE.get(fname)
|
idents = self.IDENT_CACHE.get(fname)
|
||||||
if cached is not None:
|
if idents is None:
|
||||||
if uniq:
|
idents = self.get_name_identifiers_uncached(fname)
|
||||||
cached = set(cached)
|
self.IDENT_CACHE[fname] = idents
|
||||||
return cached
|
|
||||||
|
|
||||||
|
if uniq:
|
||||||
|
idents = set(idents)
|
||||||
|
return idents
|
||||||
|
|
||||||
|
def get_name_identifiers_uncached(self, fname):
|
||||||
try:
|
try:
|
||||||
with open(fname, "r") as f:
|
with open(fname, "r") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
self.IDENT_CACHE[fname] = list()
|
|
||||||
return list()
|
return list()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lexer = guess_lexer_for_filename(fname, content)
|
lexer = guess_lexer_for_filename(fname, content)
|
||||||
except ClassNotFound:
|
except ClassNotFound:
|
||||||
self.IDENT_CACHE[fname] = list()
|
|
||||||
return list()
|
return list()
|
||||||
|
|
||||||
# lexer.get_tokens_unprocessed() returns (char position in file, token type, token string)
|
# lexer.get_tokens_unprocessed() returns (char position in file, token type, token string)
|
||||||
tokens = list(lexer.get_tokens_unprocessed(content))
|
tokens = list(lexer.get_tokens_unprocessed(content))
|
||||||
res = [token[2] for token in tokens if token[1] in Token.Name]
|
res = [token[2] for token in tokens if token[1] in Token.Name]
|
||||||
|
|
||||||
self.IDENT_CACHE[fname] = res
|
|
||||||
|
|
||||||
if uniq:
|
|
||||||
res = set(res)
|
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
@ -257,13 +253,11 @@ def call_map():
|
||||||
|
|
||||||
fnames = sys.argv[1:]
|
fnames = sys.argv[1:]
|
||||||
|
|
||||||
"""
|
|
||||||
fnames = []
|
fnames = []
|
||||||
for dname in sys.argv[1:]:
|
for dname in sys.argv[1:]:
|
||||||
fnames += find_py_files(dname)
|
fnames += find_py_files(dname)
|
||||||
|
|
||||||
fnames = sorted(fnames)
|
fnames = sorted(fnames)
|
||||||
"""
|
|
||||||
|
|
||||||
rm = RepoMap()
|
rm = RepoMap()
|
||||||
|
|
||||||
|
@ -276,7 +270,10 @@ def call_map():
|
||||||
root = os.path.commonpath(fnames)
|
root = os.path.commonpath(fnames)
|
||||||
|
|
||||||
show_fnames = set()
|
show_fnames = set()
|
||||||
for fname in fnames:
|
for fname in sorted(fnames):
|
||||||
|
from .dump import dump
|
||||||
|
|
||||||
|
dump(fname)
|
||||||
show_fname = os.path.relpath(fname, root)
|
show_fname = os.path.relpath(fname, root)
|
||||||
show_fnames.add(show_fname)
|
show_fnames.add(show_fname)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue