def get_projects(): if hsdev.agent_connected(): folders = sublime.active_window().folders() view_files = [v.file_name() for v in sublime.active_window().views() if (is_haskell_source(v) or is_cabal_source(v)) and v.file_name()] def npath(p): return os.path.normcase(os.path.normpath(p)) def childof(c, p): return npath(c).startswith(npath(p)) return dict((info['name'], info) for info in filter( lambda p: any([childof(p['path'], f) for f in folders]) or any([childof(src, p['path']) for src in view_files]), (hsdev.client.list_projects() or []))) else: folder_files = [src for f in sublime.active_window().folders() for src in list_files_in_dir_recursively(f) if os.path.splitext(src)[1] in [".hs", ".cabal"]] view_files = [v.file_name() for v in sublime.active_window().views() if (is_haskell_source(v) or is_cabal_source(v)) and v.file_name()] src_files = list(map(lambda p: os.path.normcase(os.path.normpath(p)), folder_files + view_files)) active_projects = [] while src_files: src = src_files.pop() proj_dir, proj_name = get_cabal_project_dir_and_name_of_file(src) if proj_dir: active_projects.append((proj_name, proj_dir)) src_files = [f for f in src_files if not f.startswith(proj_dir)] return dict((name, {'name': name, 'path': path}) for name, path in active_projects)
def on_activated(self, view): hsdev.start_agent() self.set_cabal_status(view) window = view.window() if window: if int(sublime.version()) < 3000: pass else: if not self.project_file_name: self.project_file_name = window.project_file_name() if window.project_file_name( ) is not None and window.project_file_name( ) != self.project_file_name: self.project_file_name = window.project_file_name() log('project switched to {0}, reinspecting'.format( self.project_file_name)) if hsdev.agent_connected(): log('reinspect all', log_trace) hsdev.client.remove_all() hsdev.agent.start_inspect() hsdev.agent.force_inspect() else: show_status_message("inspector not connected", is_ok=False)
def on_activated(self, view): hsdev.start_agent() self.set_cabal_status(view) window = view.window() if window: if int(sublime.version()) < 3000: pass else: if not self.project_file_name: self.project_file_name = window.project_file_name() if window.project_file_name() is not None and window.project_file_name() != self.project_file_name: self.project_file_name = window.project_file_name() log('project switched to {0}, reinspecting'.format(self.project_file_name)) if hsdev.agent_connected(): log('reinspect all', log_trace) hsdev.client.remove_all() hsdev.agent.start_inspect() hsdev.agent.force_inspect() else: show_status_message("inspector not connected", is_ok = False)
def run_chain(self, cmds, msg, fly_mode = False): self.messages = [] self.msgs = [] self.corrections = [] self.fly_mode = fly_mode self.filename = self.view.file_name() if not self.filename: return self.contents = {} if self.view.is_dirty(): self.contents[self.filename] = self.view.substr(sublime.Region(0, self.view.size())) if not self.fly_mode: hide_output(self.view) if not cmds: return else: self.status_msg = status_message_process(msg + ': ' + self.filename, priority = 2) self.status_msg.start() if not hsdev.agent_connected(): log('hsdev chain fails: hsdev not connected', log_error) self.status_msg.fail() self.status_msg.stop() else: self.go_chain(cmds)
def run(self): if hsdev.agent_connected(): log('reinspect all', log_trace) hsdev.agent.start_inspect() else: show_status_message("inspector not connected", is_ok = False)