def on_query_completions(self, view, prefix, locations): #if view.is_dirty(): # view.run_command("save") if not view.match_selector(locations[0], "source.scala") and not view.match_selector( locations[0], "source.java"): return [] env = ensime_environment.ensime_env if env.client() is None: print("Ensime Server doesn't appear to be started") return [] data = env.client().complete_member(view.file_name(), locations[0]) if data is None: print("Returned data was None") return [] print("Got data for completion:%s", data) friend = sexp.sexp_to_key_map(data[1][1]) comps = friend[":completions"] if ":completions" in friend else [] comp_list = [ ensime_completion(sexp.sexp_to_key_map(p)) for p in friend[":completions"] ] return ([(p.name + "\t" + p.signature, p.name) for p in comp_list], sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS)
def on_query_completions(self, view, prefix, locations): if not view.match_selector(locations[0], "source.scala") and not view.match_selector(locations[0], "source.java"): return [] data = ensime_environment.ensime_env.client().complete_member(view.file_name(), locations[0]) friend = sexp.sexp_to_key_map(data[1][1]) comps = friend[":completions"] if ":completions" in friend else [] comp_list = [ensime_completion(sexp.sexp_to_key_map(p)) for p in friend[":completions"]] return ([(p.name + "\t" + p.signature, p.name) for p in comp_list], sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS)
def select_subproject(conf, window, on_complete): """If more than one subproject is described in the given config sexp, prompt the user. Otherwise, return the sole subproject name.""" m = sexp.sexp_to_key_map(conf) subprojects = [sexp.sexp_to_key_map(p) for p in m.get(":subprojects", [])] names = [p[":name"] for p in subprojects] if len(names) > 1: window.show_quick_panel(names, lambda i: on_complete(names[i])) elif len(names) == 1: sublime.set_timeout(functools.partial(on_complete, names[0]), 0) else: sublime.set_timeout(functools.partial(on_complete, None), 0)
def initialize_project(self, on_complete): conf = self.project_config() m = sexp.sexp_to_key_map(conf) subprojects = [sexp.sexp_to_key_map(p) for p in m[":subprojects"]] names = [p[":name"] for p in subprojects] if len(names) > 1: self.window.show_quick_panel( names, lambda i: self.__initialize_project(conf,names[i],on_complete)) elif len(names) == 1: self.__initialize_project(conf,names[0],on_complete) else: self.__initialize_project(conf,"NA",on_complete)
def select_subproject(conf, window, on_complete): """If more than one subproject is described in the given config sexp, prompt the user. Otherwise, return the sole subproject name.""" m = sexp.sexp_to_key_map(conf) subprojects = [sexp.sexp_to_key_map(p) for p in m.get(":subprojects", [])] names = [p[":module-name"] for p in subprojects] if len(names) > 1: window.show_quick_panel(names, lambda i: on_complete(names[i]) if i != -1 else on_complete(None)) elif len(names) == 1: sublime.set_timeout(functools.partial(on_complete, names[0]), 0) else: sublime.set_timeout(functools.partial(on_complete, None), 0)
def initialize_project(self, on_complete): conf = self.project_config() m = sexp.sexp_to_key_map(conf) subprojects = [sexp.sexp_to_key_map(p) for p in m[":subprojects"]] names = [p[":name"] for p in subprojects] if len(names) > 1: self.window.show_quick_panel( names, lambda i: self.__initialize_project( conf, names[i], on_complete)) elif len(names) == 1: self.__initialize_project(conf, names[0], on_complete) else: self.__initialize_project(conf, "NA", on_complete)
def parse(cls, raw): if not raw: return None m = sexp.sexp_to_key_map(raw) self = cls() populate = getattr(self, "populate") populate(m) return self
def parse_list(cls, raw): if not raw: return [] if type(raw[0]) == type(key(":key")): m = sexp.sexp_to_key_map(raw) field = ":" + cls.__name__.lower() + "s" return [cls.parse(raw) for raw in (m[field] if field in m else [])] else: return [cls.parse(raw) for raw in raw]
def add_notes(lang, data): m = sexp.sexp_to_key_map(data) new_notes = [sexp.sexp_to_key_map(form) for form in m[":notes"]] for note in new_notes: key = os.path.realpath(str(note[":file"])) view_notes = self.note_map.get(key) or [] view_notes.append(note) self.note_map[key] = view_notes for v in self.window.views(): key = os.path.realpath(str(v.file_name())) notes = self.note_map.get(key) or [] v.run_command( "ensime_notes", { "lang": lang, "action": "add", "value": notes })
def parse(cls, raw): """Parse a data type from a raw data structure""" if not raw: return None value_map = sexp.sexp_to_key_map(raw) self = cls() populate = getattr(self, "populate") populate(value_map) return self
def add_notes(lang, data): m = sexp.sexp_to_key_map(data) new_notes = [sexp.sexp_to_key_map(form) for form in m[":notes"]] for note in new_notes: key = os.path.realpath(str(note[":file"])) view_notes = self.note_map.get(key) or [] view_notes.append(note) self.note_map[key] = view_notes for v in self.window.views(): key = os.path.realpath(str(v.file_name())) notes = self.note_map.get(key) or [] v.run_command("ensime_notes", { "lang": lang, "action": "add", "value": notes })
def on_query_completions(self, view, prefix, locations): #if view.is_dirty(): # view.run_command("save") if not view.match_selector(locations[0], "source.scala") and not view.match_selector(locations[0], "source.java"): return [] env = ensime_environment.ensime_env if env.client() is None: print("Ensime Server doesn't appear to be started") return [] data = env.client().complete_member(view.file_name(), locations[0]) if data is None: print("Returned data was None") return [] print("Got data for completion:%s", data) friend = sexp.sexp_to_key_map(data[1][1]) comps = friend[":completions"] if ":completions" in friend else [] comp_list = [ensime_completion(sexp.sexp_to_key_map(p)) for p in friend[":completions"]] return ([(p.name + "\t" + p.signature, p.name) for p in comp_list], sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS)
def on_query_completions(self, view, prefix, locations): if not view.match_selector(locations[0], "source.scala") and not view.match_selector( locations[0], "source.java"): return [] env = ensime_environment.ensime_env if not env.use_auto_complete: return [] data = env.client().complete_member(view.file_name(), locations[0]) if data is None: return [] friend = sexp.sexp_to_key_map(data[1][1]) comps = friend[":completions"] if ":completions" in friend else [] comp_list = [ ensime_completion(sexp.sexp_to_key_map(p)) for p in friend[":completions"] ] return ([(p.name + "\t" + p.signature, p.name) for p in comp_list], sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS)
def load(window): """Intelligently guess the appropriate .ensime file location for the given window. Load the .ensime and parse as s-expression. Return: (inferred project root directory, config sexp) """ for f in locations(window): root = encode_path(os.path.dirname(f)) src = "()" with open(f) as open_file: src = open_file.read() try: conf = sexp.read_relaxed(src) m = sexp.sexp_to_key_map(conf) if m.get(":root-dir"): root = m[":root-dir"] else: conf = conf + [key(":root-dir"), root] return (root, conf, None) except: return (None, None, bind(error_bad_config, window, f, sys.exc_info())) return (None, None, bind(error_no_config, window))
def load(window): """Intelligently guess the appropriate .ensime file location for the given window. Load the .ensime and parse as s-expression. Return: (inferred project root directory, config sexp) """ for f in locations(window): root = encode_path(os.path.dirname(f)) src = "()" with open(f) as open_file: src = open_file.read() try: conf = sexp.read_relaxed(src) m = sexp.sexp_to_key_map(conf) if m.get(":root-dir"): root = m[":root-dir"] else: conf = conf + [key(":root-dir"), root] return (root, conf, None) except: return (None, None, bind(error_bad_config, window, f, sys.exc_info())) return (None, None, None)