Skip to content

Commit 4f2cea1

Browse files
committed
Added Dump Import Directories command
1 parent 093ff3f commit 4f2cea1

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Default.sublime-commands

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@
3333
"caption": "SublimeCodeIntel: Disable Live Autocompletion for Current Language",
3434
"command": "sublimecodeintel_disable_live_lang",
3535
"args": {"action": "lang-off"}
36+
},
37+
{
38+
"caption": "SublimeCodeIntel: Dump Import Directories",
39+
"command": "sublimecodeintel_dump_import_dirs"
3640
}
3741
]

SublimeCodeIntel.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,45 @@ def run(self, edit, block=False):
16381638
window.open_file(previous_location, sublime.ENCODED_POSITION)
16391639

16401640

1641+
class SublimecodeintelDumpImportDirs(sublime_plugin.WindowCommand):
1642+
def run(self):
1643+
settings_manager.update()
1644+
if not codeintel_enabled():
1645+
return
1646+
1647+
codeintel_database_dir = os.path.expanduser(settings_manager.get('codeintel_database_dir'))
1648+
db_dir = os.path.join(codeintel_database_dir, 'db')
1649+
1650+
stat_dir = os.path.join(codeintel_database_dir, 'import_dir_stats')
1651+
if not os.path.exists(stat_dir):
1652+
os.makedirs(stat_dir)
1653+
1654+
def get_immediate_subdirectories(a_dir):
1655+
for subdirname in os.listdir(a_dir):
1656+
dirname = os.path.join(a_dir, subdirname)
1657+
if os.path.isdir(dirname):
1658+
yield (dirname, subdirname)
1659+
1660+
for lib_dir in [lib_dir for lib_dir in get_immediate_subdirectories(db_dir)]:
1661+
if lib_dir[1] != 'stdlibs':
1662+
lang = lib_dir[1]
1663+
import_dirs = []
1664+
hash_map = {}
1665+
for lib_dir_entry in get_immediate_subdirectories(lib_dir[0]):
1666+
try:
1667+
pathfile_path = os.path.join(lib_dir_entry[0], 'path')
1668+
path_file = open(pathfile_path)
1669+
import_dir = path_file.read()
1670+
import_dirs.append(import_dir)
1671+
hash_map[import_dir] = lib_dir_entry[1]
1672+
except:
1673+
pass
1674+
1675+
stat_file = open(os.path.join(stat_dir, lang), 'w')
1676+
for item in sorted(import_dirs, key=str.lower):
1677+
stat_file.write("%s %s\n" % (hash_map[item], item))
1678+
1679+
16411680
class CodeintelCommand(sublime_plugin.TextCommand):
16421681
"""command to interact with codeintel"""
16431682

0 commit comments

Comments
 (0)