Skip to content

Run rustc/cargo in the background to avoid blocking UI #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"""This module exports the Rustc plugin class."""

import os
import threading
from SublimeLinter.lint import Linter, util, persist


class Rust(Linter):

"""Provides an interface to Rust."""
Expand All @@ -38,7 +38,32 @@ class Rust(Linter):
cargo_config = None
crate_root = None

thread = None
dirty = threading.Event()
args_for_thread = None
result_from_thread = ""

def run(self, cmd, code):
if not self.thread:
self.thread = threading.Thread(target=self.wait_to_run, args = ())
self.thread.daemon = True
self.thread.start()
print('running', self.result_from_thread, self.thread)
self.args_for_thread = (cmd, code)
self.dirty.set()
return self.result_from_thread

def wait_to_run(self):
while True:
print('waiting')
self.dirty.wait()
print('firing')
cmd, code = self.args_for_thread
self.result_from_thread = self.really_run(cmd, code)
self.dirty.clear()
print('got', self.result_from_thread)

def really_run(self, cmd, code):
"""
Return a list with the command to execute.

Expand All @@ -57,6 +82,10 @@ def run(self, cmd, code):
module hierarchy will probably cause an error and prevent proper
linting in the rest of the file.
"""

# NOTE sharing the config with this thread is not safe but I am too lazy to
# strip out all the instance variables and pass them atomically

self.use_cargo = self.get_view_settings().get('use-cargo', False)
self.use_crate_root = self.get_view_settings().get(
'use-crate-root', False)
Expand Down