diff --git a/ml/commands/mark_logic_auto_complete.py b/ml/commands/mark_logic_auto_complete.py index 54118b8..a1c1c04 100644 --- a/ml/commands/mark_logic_auto_complete.py +++ b/ml/commands/mark_logic_auto_complete.py @@ -17,22 +17,19 @@ def __init__(self): def gen_dynamic_snippets(self): if (self.dynamic_snippets == None): self.dynamic_snippets = [] - snip_dir = sublime.packages_path() + "/MarkLogic/dynamic_snippets/" - for root, dirnames, filenames in os.walk(snip_dir): - for filename in fnmatch.filter(filenames, '*.json'): - fn = os.path.join(root, filename) - with open(fn, 'r') as f: - self.dynamic_snippets.append(self.create_snippet_object(json.load(f))) + snip_dir = "Packages/MarkLogic/dynamic_snippets/" + for filename in ["function.json"]: + f = MlUtils.load_resource(os.path.join(snip_dir, filename)) + self.dynamic_snippets.append(self.create_snippet_object(json.loads(f))) # load the builtin function snippets from disk def gen_function_snippets(self): if (self.function_snippets == None): self.function_snippets = [] - - functions_file = sublime.packages_path() + "/MarkLogic/marklogic_builtins/ml-functions.json" - with open(functions_file, 'r') as f: - for s in json.load(f): - self.function_snippets.append(self.create_snippet_object(s)) + functions_file = "Packages/MarkLogic/marklogic_builtins/ml-functions.json" + f = MlUtils.load_resource(functions_file) + for s in json.loads(f): + self.function_snippets.append(self.create_snippet_object(s)) # creates a snippet object for storing in a cache def create_snippet_object(self, snip): diff --git a/ml/ml_utils.py b/ml/ml_utils.py index ddb5355..a18764a 100644 --- a/ml/ml_utils.py +++ b/ml/ml_utils.py @@ -19,4 +19,12 @@ def debug(): @staticmethod def log(log_me): if (MlUtils.debug()): - print(log_me) \ No newline at end of file + print(log_me) + + @staticmethod + def load_resource(name): + if hasattr(sublime, 'load_resource'): + return sublime.load_resource(name) + else: + with open(os.path.join(sublime.packages_path(), name[9:])) as f: + return f.read()