diff --git a/client_commands.py b/client_commands.py index 373b600..b2121cc 100644 --- a/client_commands.py +++ b/client_commands.py @@ -25,7 +25,6 @@ class CodempConnectCommand(sublime_plugin.WindowCommand): try: client.connect(server_host, user_name, password) except Exception as e: - logger.error(f"Could not connect: {e}") sublime.error_message( "Could not connect:\n Make sure the server is up\n\ and your credentials are correct." @@ -79,7 +78,7 @@ class CodempJoinWorkspaceCommand(sublime_plugin.WindowCommand): promise = client.codemp.join_workspace(workspace_id) active_window = sublime.active_window() - def defer_instantiation(promise): + def _(): try: workspace = promise.wait() except Exception as e: @@ -90,7 +89,7 @@ class CodempJoinWorkspaceCommand(sublime_plugin.WindowCommand): return client.install_workspace(workspace, active_window) - sublime.set_timeout_async(lambda: defer_instantiation(promise)) + sublime.set_timeout_async(_) # the else shouldn't really happen, and if it does, it should already be instantiated. # ignore. diff --git a/src/buffers.py b/src/buffers.py index 1a74f9b..6959686 100644 --- a/src/buffers.py +++ b/src/buffers.py @@ -10,10 +10,9 @@ from ..lib import codemp logger = logging.getLogger(__name__) - def make_bufferchange_cb(buff: VirtualBuffer): def __callback(bufctl: codemp.BufferController): - def get_change_and_apply(): + def _(): change_id = buff.view.change_id() while change := bufctl.try_recv().wait(): logger.debug("received remote buffer change!") @@ -43,15 +42,10 @@ def make_bufferchange_cb(buff: VirtualBuffer): }, # pyright: ignore ) - sublime.set_timeout(get_change_and_apply) - + sublime.set_timeout(_) return __callback -# This class is used as an abstraction between the local buffers (sublime side) and the -# remote buffers (codemp side), to handle the syncronicity. -# This class is mainly manipulated by a VirtualWorkspace, that manages its buffers -# using this abstract class class VirtualBuffer: def __init__( self, @@ -61,7 +55,7 @@ class VirtualBuffer: ): self.buffctl = buffctl self.view = view - self.id = self.buffctl.name() + self.id = self.buffctl.path() self.tmpfile = os.path.join(rootdir, self.id) open(self.tmpfile, "a").close() @@ -70,9 +64,8 @@ class VirtualBuffer: self.view.set_name(self.id) self.view.retarget(self.tmpfile) - s = self.view.settings() + self.view.settings().set(g.CODEMP_BUFFER_TAG, True) self.view.set_status(g.SUBLIME_STATUS_ID, "[Codemp]") - s[g.CODEMP_BUFFER_TAG] = True logger.info(f"registering a callback for buffer: {self.id}") self.buffctl.callback(make_bufferchange_cb(self)) @@ -103,13 +96,13 @@ class VirtualBuffer: def sync(self, text_listener): promise = self.buffctl.content() - def defer_sync(promise): + def _(): content = promise.wait() safe_listener_detach(text_listener) populate_view(self.view, content) safe_listener_attach(text_listener, self.view.buffer()) - sublime.set_timeout_async(lambda: defer_sync(promise)) + sublime.set_timeout_async(_) def send_buffer_change(self, changes): # we do not do any index checking, and trust sublime with providing the correct diff --git a/src/client.py b/src/client.py index 85bb06c..ed8edca 100644 --- a/src/client.py +++ b/src/client.py @@ -32,20 +32,7 @@ class VirtualClient: self._view2buff: dict[sublime.View, VirtualBuffer] = {} self._buff2workspace: bidict[VirtualBuffer, VirtualWorkspace] = bidict() - self._workspace2window: dict[VirtualWorkspace, sublime.Window] = bidict() - - def dump(self): - logger.debug("CLIENT STATUS:") - logger.debug(f"codemp: {self.codemp is not None}") - logger.debug(f"drived: {self.driver is not None}") - logger.debug("WORKSPACES:") - logger.debug(f"{self._id2workspace}") - logger.debug(f"{self._workspace2window}") - logger.debug(f"{self._buff2workspace}") - logger.debug(f"{self._buff2workspace.inverse}") - logger.debug("VIEWS") - logger.debug(f"{self._view2buff}") - logger.debug(f"{self._id2buffer}") + self._workspace2window: dict[VirtualWorkspace, sublime.Window] = {} def all_workspaces( self, window: Optional[sublime.Window] = None @@ -127,7 +114,12 @@ class VirtualClient: "could not register the logger... If reconnecting it's ok, the previous logger is still registered" ) - self.codemp = codemp.connect(host, user, password).wait() + config = codemp.get_default_config() + config.username = user + config.host = host + config.password = password + + self.codemp = codemp.connect(config).wait() id = self.codemp.user_id() logger.debug(f"Connected to '{host}' as user {user} (id: {id})") @@ -148,8 +140,6 @@ class VirtualClient: self.unregister_buffer(vbuff) vws.uninstall() - # self._buff2workspace.inverse_del(vws) - if we delete all straight - # keys the last delete will remove also the empty key. def unregister_buffer(self, buffer: VirtualBuffer): del self._buff2workspace[buffer] diff --git a/src/workspace.py b/src/workspace.py index 4f8f711..30997bf 100644 --- a/src/workspace.py +++ b/src/workspace.py @@ -1,7 +1,7 @@ from __future__ import annotations from typing import Optional, Tuple -from listeners import CodempClientTextChangeListener +from ..listeners import CodempClientTextChangeListener import sublime import shutil import tempfile @@ -17,7 +17,7 @@ logger = logging.getLogger(__name__) def make_cursor_callback(workspace: VirtualWorkspace): def _callback(ctl: codemp.CursorController): - def get_event_and_draw(): + def _(): while event := ctl.try_recv().wait(): logger.debug("received remote cursor movement!") if event is None: @@ -32,7 +32,7 @@ def make_cursor_callback(workspace: VirtualWorkspace): draw_cursor_region(vbuff.view, event.start, event.end, event.user) - sublime.set_timeout_async(get_event_and_draw) + sublime.set_timeout_async(_) return _callback @@ -53,7 +53,6 @@ class VirtualWorkspace: self._id2buff: dict[str, VirtualBuffer] = {} tmpdir = tempfile.mkdtemp(prefix="codemp_") - logging.debug(f"setting up virtual fs for workspace in: {tmpdir}") self.rootdir = tmpdir proj: dict = self.window.project_data() # pyright: ignore