Skip to content

Commit

Permalink
Feature/add uninstall hook (#59)
Browse files Browse the repository at this point in the history
* Adding uninstall hook

* Making static method as amirtu requested
  • Loading branch information
Eransho authored Apr 28, 2020
1 parent 4e1bfba commit 17f969d
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions TabNine.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,45 @@ def join_path(*args):


class TabNineProcess:
install_directory = os.path.dirname(os.path.realpath(__file__))
def __init__(self):
self.tabnine_proc = None
self.num_restarts = 0
self.install_directory = os.path.dirname(os.path.realpath(__file__))

def on_change():
self.num_restarts = 0
self.restart_tabnine_proc()
sublime.load_settings(SETTINGS_PATH).add_on_change('TabNine', on_change)

def restart_tabnine_proc(self):
if self.tabnine_proc is not None:
try:
self.tabnine_proc.terminate()
except Exception: #pylint: disable=W0703
pass
binary_dir = os.path.join(self.install_directory, "binaries")
@staticmethod
def run_tabnine(inheritStdio=False, additionalArgs=[]):
binary_dir = os.path.join(TabNineProcess.install_directory, "binaries")
settings = sublime.load_settings(SETTINGS_PATH)
tabnine_path = settings.get("custom_binary_path")
if tabnine_path is None:
tabnine_path = get_tabnine_path(binary_dir)
args = [tabnine_path, "--client", "sublime"]
args = [tabnine_path, "--client", "sublime"] + additionalArgs
log_file_path = settings.get("log_file_path")
if log_file_path is not None:
args += ["--log-file-path", log_file_path]
extra_args = settings.get("extra_args")
if extra_args is not None:
args += extra_args
self.tabnine_proc = subprocess.Popen(
return subprocess.Popen(
args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stdin=None if inheritStdio else subprocess.PIPE,
stdout=None if inheritStdio else subprocess.PIPE,
stderr=subprocess.STDOUT,
startupinfo=get_startup_info(sublime.platform()))

def restart_tabnine_proc(self):
if self.tabnine_proc is not None:
try:
self.tabnine_proc.terminate()
except Exception: #pylint: disable=W0703
pass
self.tabnine_proc = TabNineProcess.run_tabnine()

def request(self, req):
if self.tabnine_proc is None:
self.restart_tabnine_proc()
Expand Down Expand Up @@ -114,7 +118,6 @@ def request(self, req):
self.num_restarts += 1
self.restart_tabnine_proc()


class TabNineCommand(sublime_plugin.TextCommand):
def run(*args, **kwargs): #pylint: disable=W0613,E0211
print("TabNine commands are supposed to be intercepted by TabNineListener")
Expand Down Expand Up @@ -545,3 +548,9 @@ def run(self, edit):
}

response = tabnine_proc.request(request)

def plugin_unloaded():
from package_control import events

if events.remove('TabNine'):
TabNineProcess.run_tabnine(True, ['--uninstalled'])

0 comments on commit 17f969d

Please sign in to comment.