Skip to content

Commit 9466db0

Browse files
committed
Single Manager, cached environments, better calltips
1 parent 22625a3 commit 9466db0

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

python_codeintel.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def on_modified(self, view):
137137
view.run_command('auto_complete')
138138
elif calltips is not None:
139139
# Triger a tooltip
140-
calltip(view, calltips[0])
140+
calltip(view, 'Tip: ' + calltips[0])
141141

142142
def on_selection_modified(self, view):
143143
lineno = view.rowcol(view.sel()[0].end())[0]
@@ -169,19 +169,23 @@ def run(self, edit, block=False):
169169
window.open_file(path, sublime.ENCODED_POSITION)
170170

171171

172-
_codeintel_ = {}
172+
_ci_mgr_ = None
173+
_ci_envs_ = {}
173174
_ci_db_base_dir_ = None
174175
_ci_db_catalog_dirs_ = []
175176
_ci_db_import_everything_langs = None
176177
_ci_extra_module_dirs_ = None
177178

178179
def codeintel_cleanup(path):
179-
if path in _codeintel_:
180-
mgr, env = _codeintel_[path]
181-
mgr.finalize()
182-
del _codeintel_[path]
180+
global _ci_mgr_
181+
if path in _ci_envs_:
182+
del _ci_envs_[path]
183+
if not _ci_envs_:
184+
_ci_mgr_.finalize()
185+
_ci_mgr_ = None
183186

184187
def codeintel(view, path, content, lang, pos, forms):
188+
global _ci_mgr_
185189
cplns = None
186190
calltips = None
187191
defns = None
@@ -194,13 +198,12 @@ def codeintel(view, path, content, lang, pos, forms):
194198
encoding = None
195199

196200
try:
197-
mgr, env = _codeintel_[path]
198-
print 'reused!'
201+
env = _ci_envs_[path]
202+
mgr = _ci_mgr_
199203
except KeyError:
200-
print 'created!'
201204
calltip(view, "About to update indexes. The first time this can take a while. Do not despair!", delay=1000)
202205

203-
mgr = Manager(
206+
mgr = _ci_mgr_ or Manager(
204207
extra_module_dirs = _ci_extra_module_dirs_,
205208
db_base_dir = _ci_db_base_dir_,
206209
db_catalog_dirs = _ci_db_catalog_dirs_,
@@ -229,14 +232,17 @@ def codeintel(view, path, content, lang, pos, forms):
229232

230233
env = SimplePrefsEnvironment(**config)
231234

232-
mgr.env = env
233-
mgr.upgrade()
234-
mgr.initialize()
235+
if not _ci_mgr_:
236+
mgr.upgrade()
237+
mgr.initialize()
238+
_ci_mgr_ = mgr
235239

236-
_codeintel_[path] = (mgr, env)
240+
_ci_envs_[path] = env
237241

238242
calltip(view, "")
239243

244+
mgr.env = env
245+
240246
buf = mgr.buf_from_content(content, lang, env, path, encoding)
241247
if not isinstance(buf, CitadelBuffer):
242248
logger(view, "Error", "`%s' (%s) is not a language that uses CIX" % (path, buf.lang))

0 commit comments

Comments
 (0)