def plugin_loaded(): global watchdog, settings settings = load_settings() Log._set_verbosity(settings.verbosity) StackIDEManager.configure(settings) Win.show_popup = settings.show_popup watchdog = StackIDEWatchdog()
def test_monitors_new_windows(self): StackIDEManager.check_windows() self.assertEqual(0, len(StackIDEManager.ide_backend_instances)) sublime.create_window('.') StackIDEManager.check_windows() self.assertEqual(1, len(StackIDEManager.ide_backend_instances)) sublime.destroy_windows()
def on_post_save(self, view): if not is_haskell_view(view): return if not StackIDEManager.is_running(view.window()): return StackIDEManager.for_window(view.window()).update_files([relative_view_file_name(view)])
def on_post_save(self, view): if not is_haskell_view(view): return if not StackIDEManager.is_running(view.window()): return StackIDEManager.for_window(view.window()).update_files( [relative_view_file_name(view)])
def on_settings_changed(): global settings updated_settings = load_settings() if updated_settings.verbosity != settings.verbosity: Log._set_verbosity(updated_settings.verbosity) elif updated_settings.add_to_PATH != settings.add_to_PATH: Log.normal("Settings changed, reloading backends") StackIDEManager.configure(updated_settings) StackIDEManager.reset() elif updated_settings.show_popup != settings.show_popup: Win.show_popup = updated_settings.show_popup settings = updated_settings
def run(self, request): """ Pass a request to stack-ide. Called via run_command("send_stack_ide_request", {"request":}) """ instance = StackIDEManager.for_window(self.window) if instance: instance.send_request(request)
def test_retains_live_instances(self): window = mock_window(['.']) sublime.add_window(window) StackIDEManager.check_windows() self.assertEqual(1, len(StackIDEManager.ide_backend_instances)) # substitute a 'live' instance instance = stack_ide.StackIDE(window, test_settings, FakeBackend()) StackIDEManager.ide_backend_instances[window.id()] = instance # instance should still exist. StackIDEManager.check_windows() self.assertEqual(1, len(StackIDEManager.ide_backend_instances)) self.assertEqual(instance, StackIDEManager.ide_backend_instances[window.id()]) sublime.destroy_windows()
def test_kills_live_orphans(self): window = sublime.create_window('.') StackIDEManager.check_windows() self.assertEqual(1, len(StackIDEManager.ide_backend_instances)) # substitute a 'live' instance backend = MagicMock() stack_ide.stack_ide_loadtargets = Mock(return_value=['app/Main.hs', 'src/Lib.hs']) instance = stack_ide.StackIDE(window, test_settings, backend) StackIDEManager.ide_backend_instances[window.id()] = instance # close the window sublime.destroy_windows() # instance should be killed StackIDEManager.check_windows() self.assertEqual(0, len(StackIDEManager.ide_backend_instances)) self.assertFalse(instance.is_alive) backend.send_request.assert_called_with(Req.get_shutdown())
def test_reset(self): window = mock_window(['.']) sublime.add_window(window) StackIDEManager.check_windows() self.assertEqual(1, len(StackIDEManager.ide_backend_instances)) # substitute a 'live' instance backend = MagicMock() stack_ide.stack_ide_loadtargets = Mock(return_value=['app/Main.hs', 'src/Lib.hs']) instance = stack_ide.StackIDE(window, test_settings, backend) StackIDEManager.ide_backend_instances[window.id()] = instance StackIDEManager.reset() # instances should be shut down. self.assertEqual(1, len(StackIDEManager.ide_backend_instances)) self.assertFalse(instance.is_alive) backend.send_request.assert_called_with(Req.get_shutdown()) sublime.destroy_windows()
def test_retains_existing_instances(self): StackIDEManager.check_windows() self.assertEqual(0, len(StackIDEManager.ide_backend_instances)) sublime.create_window('.') StackIDEManager.check_windows() self.assertEqual(1, len(StackIDEManager.ide_backend_instances)) StackIDEManager.check_windows() self.assertEqual(1, len(StackIDEManager.ide_backend_instances)) sublime.destroy_windows()
def on_selection_modified(self, view): if not is_haskell_view(view): return window = view.window() if not StackIDEManager.is_running(window): return # Only try to get types for views into files # (rather than e.g. the find field or the console pane) if view.file_name(): # Uncomment to see the scope at the cursor: # Log.debug(view.scope_name(view.sel()[0].begin())) request = Req.get_exp_types(span_from_view_selection(view)) send_request(window, request, Win(window).highlight_type)
def on_query_completions(self, view, prefix, locations): if not is_haskell_view(view): return window = view.window() if not StackIDEManager.is_running(window): return # Check if this completion query is due to our refreshing the completions list # after receiving a response from stack-ide, and if so, don't send # another request for completions. if not self.refreshing: self.view = view request = Req.get_autocompletion(filepath=relative_view_file_name(view),prefix=prefix) send_request(window, request, self._handle_response) # Clear the flag to allow future completion queries self.refreshing = False return list(self.format_completion(*completion) for completion in self.returned_completions)
def on_query_completions(self, view, prefix, locations): if not is_haskell_view(view): return window = view.window() if not StackIDEManager.is_running(window): return # Check if this completion query is due to our refreshing the completions list # after receiving a response from stack-ide, and if so, don't send # another request for completions. if not self.refreshing: self.view = view request = Req.get_autocompletion( filepath=relative_view_file_name(view), prefix=prefix) send_request(window, request, self._handle_response) # Clear the flag to allow future completion queries self.refreshing = False return list( self.format_completion(*completion) for completion in self.returned_completions)
def run(self): StackIDEManager.reset()
def plugin_unloaded(): global watchdog watchdog.kill() StackIDEManager.reset() watchdog = None
def test_creates_initial_window(self): sublime.create_window('.') StackIDEManager.check_windows() self.assertEqual(1, len(StackIDEManager.ide_backend_instances)) sublime.destroy_windows()
def test_defaults(self): StackIDEManager.check_windows() self.assertEqual(0, len(StackIDEManager.ide_backend_instances))
def check_for_processes(self): StackIDEManager.check_windows() self.timer = threading.Timer(1.0, self.check_for_processes) self.timer.start()