Skip to content

Commit

Permalink
Initialize and update the ydoc path's property when it change
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Aug 29, 2024
1 parent b8fafc0 commit 45ea722
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion projects/jupyter-server-ydoc/jupyter_server_ydoc/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(

self._watcher = asyncio.create_task(self._watch_file()) if self._poll_interval else None
self.last_modified = None
self._current_path = self.path

@property
def file_id(self) -> str:
Expand Down Expand Up @@ -205,8 +206,13 @@ async def maybe_notify(self) -> None:
"""
do_notify = False
async with self._lock:
path = self.path
if self._current_path != path:
self._current_path = path
do_notify = True

# Get model metadata; format and type are not need
model = await ensure_async(self._contents_manager.get(self.path, content=False))
model = await ensure_async(self._contents_manager.get(path, content=False))

if self.last_modified is not None and self.last_modified < model["last_modified"]:
do_notify = True
Expand Down
2 changes: 2 additions & 0 deletions projects/jupyter-server-ydoc/jupyter_server_ydoc/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(
self._file_type: str = file_type
self._file: FileLoader = file
self._document = YDOCS.get(self._file_type, YFILE)(self.ydoc)
self._document.path = self._file.path

self._logger = logger
self._save_delay = save_delay
Expand Down Expand Up @@ -222,6 +223,7 @@ async def _on_outofband_change(self) -> None:
return

async with self._update_lock:
self._document.path = model["path"]
self._document.source = model["content"]
self._document.dirty = False

Expand Down

0 comments on commit 45ea722

Please sign in to comment.