Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #38

  • Loading branch information...
commit f716abeddbdb67163e6b828ca9b6b5f55ad3cf6a 1 parent 2bbfe6d
@mvoidex mvoidex authored
View
42 autocomplete.py
@@ -266,9 +266,8 @@ def get_current_module_completions(self):
cabal = current_cabal()
- with self.database.cabal_modules as cabal_modules:
- if cabal in cabal_modules:
- completions.extend(list(cabal_modules[cabal].keys()))
+ with self.database.get_cabal_modules() as cabal_modules:
+ completions.extend(list(cabal_modules.keys()))
if self.current_filename:
(project_path, _) = get_cabal_project_dir_and_name_of_file(self.current_filename)
@@ -407,11 +406,9 @@ def run(self, edit, filename = None, module_name = None, decl = None):
return
if decl and module_name:
- cur_cabal = current_cabal()
- with autocompletion.database.cabal_modules as cabal_modules:
- modules = cabal_modules[cur_cabal]
- if module_name in modules:
- m = modules[module_name]
+ with autocompletion.database.get_cabal_modules() as cabal_modules:
+ if module_name in cabal_modules:
+ m = cabal_modules[module_name]
if decl in m.declarations:
self.show_symbol_info(m.declarations[decl])
else:
@@ -585,16 +582,14 @@ def run(self, module_name = None, filename = None):
self.window.show_quick_panel([[decl.brief(), decl.docs.splitlines()[0]] if decl.docs else [decl.brief()] for decl in decls], self.on_symbol_selected)
return
- cur_cabal = current_cabal()
-
self.candidates = []
with autocompletion.database.files as files:
for fname, m in files.items():
self.candidates.append([m.name, fname])
- with autocompletion.database.cabal_modules as cabal_modules:
- for m in cabal_modules[cur_cabal].values():
+ with autocompletion.database.get_cabal_modules() as cabal_modules:
+ for m in cabal_modules.values():
self.candidates.append([m.name])
self.candidates.sort(key = lambda c: c[0])
@@ -838,23 +833,26 @@ def _load_standard_module(self, module_name, cabal = None):
if not cabal:
cabal = current_cabal()
- if module_name not in autocompletion.database.get_cabal_modules(cabal):
- try:
- m = util.browse_module(module_name, cabal = cabal)
- if m:
- autocompletion.database.add_module(m)
+ with autocompletion.database.get_cabal_modules(cabal) as cabal_modules:
+ if module_name in cabal_modules:
+ return
- except Exception as e:
- log('Inspecting in-cabal module {0} failed: {1}'.format(module_name, e))
+ try:
+ m = util.browse_module(module_name, cabal = cabal)
+ if m:
+ autocompletion.database.add_module(m)
+
+ except Exception as e:
+ log('Inspecting in-cabal module {0} failed: {1}'.format(module_name, e))
def _load_standard_module_docs(self, module_name, cabal = None):
if not cabal:
cabal = current_cabal()
- with autocompletion.database.cabal_modules as cabal_modules:
- if module_name in cabal_modules[cabal]:
+ with autocompletion.database.get_cabal_modules(cabal) as cabal_modules:
+ if module_name in cabal_modules:
try:
- hdocs.load_module_docs(cabal_modules[cabal][module_name])
+ hdocs.load_module_docs(cabal_modules[module_name])
except Exception as e:
log('Loading docs for in-cabal module {0} failed: {1}'.format(module_name, e))
View
15 cache.py
@@ -56,10 +56,10 @@ def symbol_serializers():
symbols.Module: ('module', ['name', 'exports', 'imports', 'declarations', 'location', 'cabal']),
symbols.Declaration: ('declaration', ['name', 'what', 'docs', 'location']),
symbols.Function: ('function', ['name', 'type', 'docs', 'location']),
- symbols.TypeBase: ('typebase', ['name', 'what', 'context', 'args', 'docs', 'location']),
- symbols.Type: ('type', ['name', 'context', 'args', 'docs', 'location']),
- symbols.Newtype: ('newtype', ['name', 'context', 'args', 'docs', 'location']),
- symbols.Data: ('data', ['name', 'context', 'args', 'docs', 'location']),
+ symbols.TypeBase: ('typebase', ['name', 'what', 'context', 'args', 'definition', 'docs', 'location']),
+ symbols.Type: ('type', ['name', 'context', 'args', 'definition', 'docs', 'location']),
+ symbols.Newtype: ('newtype', ['name', 'context', 'args', 'definition', 'docs', 'location']),
+ symbols.Data: ('data', ['name', 'context', 'args', 'definition', 'docs', 'location']),
symbols.Class: ('class', ['name', 'context', 'args', 'docs', 'location']) }
def encode_json(obj, **kwargs):
@@ -84,8 +84,7 @@ def dump_cabal_cache(database, cabal_name = None):
if not cabal_name:
cabal_name = current_cabal()
formatted_json = None
- cabal_modules = database.get_cabal_modules(cabal_name)
- with database.cabal_modules:
+ with database.get_cabal_modules(cabal_name) as cabal_modules:
cabal_path = escape_path(cabal_name) if cabal_name != 'cabal' else 'cabal'
cabal_json = os.path.join(CABAL_CACHE_PATH, cabal_path + '.json')
formatted_json = encode_json(cabal_modules, indent = 2)
@@ -139,7 +138,11 @@ def plugin_loaded():
if not os.path.exists(CACHE_PATH):
os.mkdir(CACHE_PATH)
+
+ if not os.path.exists(CABAL_CACHE_PATH):
os.mkdir(CABAL_CACHE_PATH)
+
+ if not os.path.exists(PROJECTS_CACHE_PATH):
os.mkdir(PROJECTS_CACHE_PATH)
if int(sublime.version()) < 3000:
View
4 sublime_haskell_common.py
@@ -674,8 +674,8 @@ class LockedObject(object):
v...
"""
- def __init__(self, obj):
- self.object_lock = threading.Lock()
+ def __init__(self, obj, lock = None):
+ self.object_lock = lock if lock else threading.Lock()
self.object = obj
def __enter__(self):
View
8 symbols.py
@@ -259,7 +259,7 @@ def get_cabal_modules(self, cabal = None):
with self.cabal_modules as cabal_modules:
if cabal not in cabal_modules:
cabal_modules[cabal] = {}
- return cabal_modules[cabal]
+ return LockedObject(self.cabal_modules.object[cabal], self.cabal_modules.object_lock)
def get_project_modules(self, project_name):
with self.files as files:
@@ -305,7 +305,11 @@ def add_module(self, new_module, cabal = None):
Adds module and updates indexes
"""
if not cabal:
- cabal = current_cabal()
+ if new_module.cabal:
+ cabal = new_module.cabal
+ else:
+ cabal = current_cabal()
+ new_module.cabal = cabal
with self.cabal_modules as cabal_modules:
if cabal not in cabal_modules:
Please sign in to comment.
Something went wrong with that request. Please try again.