Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
digital-phoenix committed Mar 5, 2024
2 parents ceee7fc + d815328 commit 275ffac
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Default.sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
{ "keys": ["tab"], "command": "refact_accept_completion", "context": [{"key": "refact.show_completion"}] },
{ "keys": ["escape"], "command": "refact_clear_completion", "context": [{"key": "refact.show_completion"}] },
{ "keys": ["ctrl+alt+p"], "command": "refact_pause" }
{ "keys": ["ctrl+alt+p"], "command": "refact_pause" },
{ "keys": ["primary+option+p"], "command": "refact_pause" }
]
8 changes: 7 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,18 @@ def on_text_command(self, view, command_name, args):
elif command_name == "drag_select":
session.clear_completion()

def restart_server():
global refact_session_manager
print("restarting server")
if refact_session_manager:
refact_session_manager.restart_server()

def plugin_loaded():
global refact_session_manager
global start_refact
s = sublime.load_settings("refact.sublime-settings")
pause_completion = s.get("pause_completion", False)
s.add_on_change("restart_server", restart_server)
if pause_completion:
sublime.status_message("⏸️ refact.ai")
else:
Expand Down Expand Up @@ -158,4 +165,3 @@ def run(self, edit):
class RefactClearCompletion(sublime_plugin.TextCommand):
def run(self, edit):
refact_session_manager.get_session(self.view).clear_completion()

3 changes: 0 additions & 3 deletions src/refact_lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ def shutdown(self):
self.statusbar.handle_err(err)

print("lsp error shutdown")

def logMessage(self, args):
print("logMessage", args)

def connect(self, process):
capabilities = {}
Expand Down
14 changes: 10 additions & 4 deletions src/refact_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ def get_server_commands(self):
def start_server(self):
self.active = True
server_cmds = self.get_server_commands()
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
self.process = subprocess.Popen(server_cmds, startupinfo=startupinfo, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr=subprocess.PIPE, shell=False)

if hasattr(subprocess, 'STARTUPINFO'):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
self.process = subprocess.Popen(server_cmds, startupinfo=startupinfo, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
else:
self.process = subprocess.Popen(server_cmds, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr=subprocess.PIPE, shell=False)

self.statusbar.update_statusbar("ok")
if not self.connection is None:
Expand All @@ -52,7 +56,9 @@ def start_server(self):
self.connection = LSP(self.process, self.statusbar)

def stop_server(self):
self.connection.shutdown()
if not self.connection is None:
self.connection.shutdown()
self.process.terminate()
self.active = False
self.statusbar.update_statusbar("pause")

4 changes: 4 additions & 0 deletions src/refact_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def __init__(self):
self.connection = self.process.start_server()
self.views = {}

def restart_server(self):
self.shutdown()
self.start()

def start(self):
self.connection = self.process.start_server()

Expand Down

0 comments on commit 275ffac

Please sign in to comment.