Skip to content

Commit

Permalink
store cache as dict
Browse files Browse the repository at this point in the history
  • Loading branch information
youben11 committed Nov 14, 2019
1 parent f99d33e commit 6812993
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions pyls/plugins/importmagic_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
UNRES_RE = re.compile(r"Unresolved import '(?P<unresolved>[\w.]+)'")
UNREF_RE = re.compile(r"Unreferenced import '(?P<unreferenced>[\w.]+)'")

_index_cache = None
_index_cache = {}


def _build_index(paths):
Expand All @@ -30,23 +30,23 @@ 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():
"""Get the cached index if built and index project files on each call.
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):
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/test_importmagic_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6812993

Please sign in to comment.