Mercurial > vim-crosoft
changeset 5:bac97082e229
Add more caching to listing solution files.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 24 Oct 2019 11:16:11 -0700 |
parents | ae0fb567f459 |
children | 376f3371c311 |
files | autoload/vimcrosoft/fzf.vim scripts/list_sln_files.py |
diffstat | 2 files changed, 40 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/autoload/vimcrosoft/fzf.vim Thu Oct 24 11:15:37 2019 -0700 +++ b/autoload/vimcrosoft/fzf.vim Thu Oct 24 11:16:11 2019 -0700 @@ -12,8 +12,10 @@ function! s:build_file_list_command(slnpath) abort let l:scriptpath = vimcrosoft#get_script_path('list_sln_files.py') + let l:list_cache_path = vimcrosoft#get_sln_cache_file('fzffilelist.txt') return 'python '.shellescape(l:scriptpath). - \' '.shellescape(a:slnpath) - \.' --cache '.shellescape(g:vimcrosoft_current_sln_cache) + \' '.shellescape(a:slnpath). + \' --cache '.shellescape(g:vimcrosoft_current_sln_cache). + \' --list-cache '.shellescape(l:list_cache_path) endfunction
--- a/scripts/list_sln_files.py Thu Oct 24 11:15:37 2019 -0700 +++ b/scripts/list_sln_files.py Thu Oct 24 11:16:11 2019 -0700 @@ -2,7 +2,7 @@ import logging import os.path from logutil import setup_logging -from vsutil import SolutionCache +from vsutil import SolutionCache, ITEM_TYPE_SOURCE_FILES logger = logging.getLogger(__name__) @@ -12,17 +12,39 @@ parser = argparse.ArgumentParser() parser.add_argument('solution', help="The path to the Visual Studio solution file.") + parser.add_argument('-c', '--cache', + help="The solution cache file to load.") + parser.add_argument('--list-cache', + help=("If the solution cache is valid, use this " + "pre-saved file list. Otherwise, compute the " + "file list and save it to the given path.")) parser.add_argument('-p', '--project', help="Only list files in the named project.") - parser.add_argument('-c', '--cache', - help="Use a cache file to store the file list.") + parser.add_argument('-t', '--type', + action='append', + help="The type(s) of items to list.") parser.add_argument('-v', '--verbose', action='store_true', help="Show verbose information.") args = parser.parse_args(args) setup_logging(args.verbose) - cache, _ = SolutionCache.load_or_rebuild(args.solution, args.cache) + cache, loaded = SolutionCache.load_or_rebuild(args.solution, args.cache) + if loaded and args.list_cache: + cache_dt = os.path.getmtime(args.cache) + list_cache_dt = os.path.getmtime(args.list_cache) + if list_cache_dt > cache_dt: + logger.debug("Solution cache was valid, re-using the file list cache.") + try: + with open(args.list_cache, 'r') as fp: + print(fp.read()) + return + except OSError: + logger.debug("File list cache unreachable, recomputing it.") + else: + logger.debug("Solution cache was valid but file list cache was older, " + "recomputing it.") + slnobj = cache.slnobj projs = slnobj.projects @@ -30,11 +52,20 @@ projs = [slnobj.find_project_by_name(args.project)] projs = list(filter(lambda p: not p.is_folder, projs)) + itemtypes = args.type or ITEM_TYPE_SOURCE_FILES + items = [] + for p in projs: ig = p.defaultitemgroup() - for i in ig.get_source_items(): + for i in ig.get_items_of_types(itemtypes): file_path = os.path.abspath(os.path.join(p.absdirpath, i.include)) print(file_path) + items.append(file_path + '\n') + + if args.list_cache: + logger.debug("Writing file list cache: %s" % args.list_cache) + with open(args.list_cache, 'w') as fp: + fp.writelines(items) if __name__ == '__main__':