def activated_worker(self, view, filename): with self.backend_mgr: EventCommon.assoc_to_project(view, self.backend_mgr, filename) _, project_name = Common.locate_cabal_project_from_view(view) if Common.view_is_haskell_source(view): self.autocompleter.generate_completions_cache( project_name, filename)
def do_load(self, view): filename = view.file_name() if not Common.view_is_haskell_source(view) or not filename: return if Settings.COMPONENT_DEBUG.event_viewer: print('{0}.on_load {1}.'.format(type(self).__name__, filename)) view_settings = view.settings() or {} if Settings.PLUGIN.use_improved_syntax and (filename.endswith(".hs") or filename.endswith(".hsc") or \ view_settings.get('syntax', '').endswith('.tmLanguage')): view_settings.set( 'syntax', 'Packages/SublimeHaskell/Syntaxes/Haskell-SublimeHaskell.sublime-syntax' ) EventCommon.assoc_to_project(view, self.backend_mgr, filename) _project_dir, project_name = Common.locate_cabal_project_from_view( view) if Settings.PLUGIN.enable_infer_types: BackendManager.active_backend().infer(files=[filename]) Utils.run_async('rescan source {0}/{1}'.format(project_name, filename), self.rescan_source, project_name, filename, {'drop_all': False})
def on_selection_modified(self, view): if Common.view_is_haskell_source(view) and view.file_name(): srcfile = view.file_name() if SourceHaskellTypeCache().has( srcfile) and SourceHaskellTypeCache().shown(srcfile): view.run_command('sublime_haskell_show_all_types', {'filename': srcfile})
def on_post_save(self, view): if not Common.view_is_inspected_source(view): return if Settings.COMPONENT_DEBUG.event_viewer: print('{0}.on_post_save invoked.'.format(type(self).__name__)) filename = view.file_name() if not filename: if Settings.COMPONENT_DEBUG.event_viewer: print('{0}.on_post_save: no file name.'.format( type(self).__name__)) return _project_dir, project_name = Common.locate_cabal_project_from_view( view) if Common.view_is_haskell_source(view): self.type_cache.remove(filename) if Settings.PLUGIN.enable_auto_build: view.window().run_command('sublime_haskell_build_auto') else: EventCommon.do_check_lint( view, continue_success=self.post_successful_check) Utils.run_async('rescan source {0}/{1}'.format(project_name, filename), self.rescan_source, project_name, filename, False)
def do_hover(self, view, point, hover_zone): # Note: view.file_name() is not set in certain views, such as the "Haskell Show Types Panel". Avoid # generating lookup errors, which are logged in the console window (for better or worse.) filename = view.file_name() if filename and Common.view_is_haskell_source(view): # Ensure that we never block the Python main thread. info_pop = InfoPop.SublimeHaskellHoverPopup(view, view.file_name(), point, hover_zone) Utils.run_async('SublimeHaskellPopup.on_hover', info_pop.do_hover)
def do_new(self, view): filename = view.file_name() if not Common.view_is_haskell_source(view) or not filename: return if Settings.COMPONENT_DEBUG.event_viewer: print('{0}.on_new invoked.'.format(type(self).__name__)) EventCommon.assoc_to_project(view, self.backend_mgr, filename) _project_dir, project_name = Common.locate_cabal_project_from_view(view) Utils.run_async('rescan {0}/{1}'.format(project_name, filename), self.rescan_source, project_name, filename, {'drop_all': True}) view.settings().set('translate_tabs_to_spaces', True)
def get_projects(self): win = self.view.window() folders = win.folders() view_files = [v.file_name() for v in win.views() if v.file_name() and (Common.view_is_haskell_source(v) or Common.view_is_cabal_source(v))] def childof(path, prefix): return Utils.normalize_path(path).startswith(Utils.normalize_path(prefix)) def relevant_project(proj): return any([childof(proj['path'], f) for f in folders]) or any([childof(src, proj['path']) for src in view_files]) projects = BackendMgr.active_backend().list_projects() or [] return dict((info['name'], info) for info in projects if relevant_project(info))
def on_load(self, view): filename = view.file_name() if not Common.view_is_haskell_source(view) or not filename: return if Settings.COMPONENT_DEBUG.event_viewer: print('{0}.on_load {1}.'.format(type(self).__name__, filename)) EventCommon.assoc_to_project(view, self.backend_mgr, filename) _project_dir, project_name = Common.locate_cabal_project_from_view( view) Utils.run_async('rescan source {0}/{1}'.format(project_name, filename), self.rescan_source, project_name, filename, {'drop_all': False})
def get_projects(self): win = self.view.window() folders = win.folders() view_files = [v.file_name() for v in win.views() if v.file_name() and (Common.view_is_haskell_source(v) or Common.view_is_cabal_source(v))] def childof(path, prefix): return Utils.normalize_path(path).startswith(Utils.normalize_path(prefix)) def relevant_project(proj): return any([childof(proj['path'], f) for f in folders]) or any([childof(src, proj['path']) for src in view_files]) projects = BackendMgr.active_backend().list_projects() or [] return dict((info['name'], info) for info in projects if relevant_project(info))
def do_load(self, view): filename = view.file_name() if not Common.view_is_haskell_source(view) or not filename: return if Settings.COMPONENT_DEBUG.event_viewer: print('{0}.on_load {1}.'.format(type(self).__name__, filename)) view_settings = view.settings() or {} if Settings.PLUGIN.use_improved_syntax and (filename.endswith(".hs") or filename.endswith(".hsc") or \ view_settings.get('syntax', '').endswith('.tmLanguage')): view_settings.set('syntax', 'Packages/SublimeHaskell/Syntaxes/Haskell-SublimeHaskell.sublime-syntax') EventCommon.assoc_to_project(view, self.backend_mgr, filename) _project_dir, project_name = Common.locate_cabal_project_from_view(view) Utils.run_async('rescan source {0}/{1}'.format(project_name, filename), self.rescan_source, project_name, filename, {'drop_all': False})
def do_post_save(self, view): if not Common.view_is_inspected_source(view): return current_time = time.clock() last_update = self.update_cache.get(view.file_name()) if last_update is not None and last_update[0] == view.change_count( ) and (current_time - last_update[1]) < 0.2: # view contents equals # and last update was in less then 0.2s before, skipping print('SublimeHaskellEventListener: duplicate save detected.') return self.update_cache[view.file_name()] = (view.change_count(), current_time) if Settings.COMPONENT_DEBUG.event_viewer: print('{0}.on_post_save invoked.'.format(type(self).__name__)) filename = view.file_name() if not filename: if Settings.COMPONENT_DEBUG.event_viewer: print('{0}.on_post_save: no file name.'.format( type(self).__name__)) return _project_dir, project_name = Common.locate_cabal_project_from_view( view) if Common.view_is_haskell_source(view): self.type_cache.remove(filename) if Settings.PLUGIN.enable_auto_build: Builder.Builder( view, continue_success=self.post_successful_check).auto_build() else: EventCommon.do_check_lint( view, continue_success=self.post_successful_check) Utils.run_async('rescan source {0}/{1}'.format(project_name, filename), self.rescan_source, project_name, filename, False)
def do_post_save(self, view): if not Common.view_is_inspected_source(view): return if Settings.COMPONENT_DEBUG.event_viewer: print('{0}.on_post_save invoked.'.format(type(self).__name__)) filename = view.file_name() if not filename: if Settings.COMPONENT_DEBUG.event_viewer: print('{0}.on_post_save: no file name.'.format(type(self).__name__)) return _project_dir, project_name = Common.locate_cabal_project_from_view(view) if Common.view_is_haskell_source(view): self.type_cache.remove(filename) if Settings.PLUGIN.enable_auto_build: Builder.Builder(view, continue_success=self.post_successful_check).auto_build() else: EventCommon.do_check_lint(view, continue_success=self.post_successful_check) Utils.run_async('rescan source {0}/{1}'.format(project_name, filename), self.rescan_source, project_name, filename, False)
def is_visible(self): return Common.view_is_haskell_source(self.view) or Common.view_is_haskell_repl(self.view)
def is_visible(self): return Common.view_is_haskell_symbol_info(self.view) or \ Common.view_is_haskell_source(self.view) or \ Common.view_is_haskell_repl(self.view)
def is_enabled(self): return (self.view.settings().get('package') is not None) or \ Common.view_is_haskell_source(self.view) or \ Common.view_is_haskell_repl(self.view)
def on_selection_modified(self, view): if Common.view_is_haskell_source(view) and view.file_name(): srcfile = view.file_name() if SourceHaskellTypeCache().has(srcfile) and SourceHaskellTypeCache().shown(srcfile): view.run_command('sublime_haskell_show_all_types', {'filename': srcfile})
def is_enabled(self): return Common.view_is_haskell_source( self.view) and self.view.file_name() is not None
def is_visible(self): return Common.view_is_haskell_source(self.view) and super().is_visible()
def is_enabled(self): return Common.view_is_haskell_source( self.view) and super().is_enabled()
def is_visible(self): return Common.view_is_haskell_source( self.view) and super().is_visible()
def on_selection_modified(self, view): if TOGGLE_SYMBOL_INFO and Common.view_is_haskell_source(view) and view.file_name(): view.run_command('sublime_haskell_symbol_info', {'no_browse': True})
def is_enabled(self): return Common.view_is_haskell_source(self.view) or Common.view_is_haskell_repl(self.view) or \ (Common.view_is_haskell_symbol_info(self.view) and self.view.settings().get('location'))
def is_enabled(self): return Common.view_is_haskell_source(self.view) and self.view.file_name() is not None
def is_enabled(self): return Common.view_is_haskell_source(self.view) and \ self.view.file_name() is not None and \ SourceHaskellTypeCache().has(self.view.file_name()) and \ SourceHaskellTypeCache().shown(self.view.file_name())
def is_enabled(self): return Common.view_is_haskell_source(self.view) and super().is_enabled()
def activated_worker(self, view, filename): with self.backend_mgr: EventCommon.assoc_to_project(view, self.backend_mgr, filename) _, project_name = Common.locate_cabal_project_from_view(view) if Common.view_is_haskell_source(view): self.autocompleter.generate_completions_cache(project_name, filename)
def context_haskell_source_or_repl(self, view, _key, _operator, _operand, _matchall): return Common.view_is_haskell_source(view) or Common.view_is_haskell_repl(view)
def context_haskell_source_or_repl(self, view, _key, _operator, _operand, _matchall): return Common.view_is_haskell_source( view) or Common.view_is_haskell_repl(view)
def is_enabled(self): return Common.view_is_haskell_source(self.view) and \ self.view.file_name() is not None and \ SourceHaskellTypeCache().has(self.view.file_name()) and \ SourceHaskellTypeCache().shown(self.view.file_name())