diff --git a/pyls/plugins/importmagic_lint.py b/pyls/plugins/importmagic_lint.py index 82596339..15eb4f40 100644 --- a/pyls/plugins/importmagic_lint.py +++ b/pyls/plugins/importmagic_lint.py @@ -16,7 +16,7 @@ UNRES_RE = re.compile(r"Unresolved import '(?P[\w.]+)'") UNREF_RE = re.compile(r"Unreferenced import '(?P[\w.]+)'") -_index_cache = None +_index_cache = {} def _build_index(paths): @@ -30,9 +30,8 @@ def _build_index(paths): def _cache_index_callback(future): - global _index_cache # Cache the index - _index_cache = future.result() + _index_cache['default'] = future.result() def _get_index(): @@ -40,13 +39,14 @@ def _get_index(): Return an empty index if not built yet. """ # Index haven't been built yet - if _index_cache is None: + index = _index_cache.get('default') + if index is None: return importmagic.SymbolIndex() # Index project files # TODO(youben) index project files - #index.build_index(paths=[]) - return _index_cache + # index.build_index(paths=[]) + return _index_cache['default'] def _get_imports_list(source, index=None): diff --git a/test/plugins/test_importmagic_lint.py b/test/plugins/test_importmagic_lint.py index f444bbf3..99f3068c 100644 --- a/test/plugins/test_importmagic_lint.py +++ b/test/plugins/test_importmagic_lint.py @@ -42,7 +42,7 @@ def test_importmagic_actions(config): try: importmagic_lint.pyls_initialize() name, doc = temp_document(DOC) - while importmagic_lint._index_cache is None: + while importmagic_lint._index_cache.get('default') is None: # wait for the index to be ready sleep(1) actions = importmagic_lint.pyls_code_actions(config, doc)