Skip to content

feat: initialize Y.Docs from VSC buffers - #160

Merged
Vtec234 merged 11 commits into
mainfrom
connect-init
Sep 30, 2026
Merged

Vtec234 merged 11 commits into
mainfrom
connect-init

Conversation

@Vtec234

@Vtec234 Vtec234 commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

This PR changes how Y.Docs are initialized in collab-server when they are opened for the first time. Previously, collab-server would open the given file on disk and read its contents. In this PR, VSC instead sends the contents of its text buffer to collab-server when YTextBinding is constructed. This produces a different outcome in case the VSC buffer has unsaved changes. Previously, they would be discarded, whereas now they are kept.

Addresses, but does not entirely fix, #146 - renaming once works now, but renaming back to an old name will restore the last buffer state of the old name.

This is moving in the direction of having collab-server sync only the open text buffers, but not the project files: disk IO is now the sole purview of VSC clients. After this PR, collab-server will not even have access to project files.

Instrumentally, we introduce a tRPC connection between VSC and collab-server to communicate events that Hocuspocus/Yjs doesn't handle natively.

Comment thread collab-server/src/index.ts
Comment thread vscode-workbench/src/textBinding.ts
Comment thread vscode-workbench/src/util.ts Outdated

@robsimmons robsimmons left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for revising this to do a bit less. The tRPC communication channel is likely to be helpful for other things, and with the exception of increasing the delay before initFromRemote overwrites the buffer, this pretty clearly improves things more than it breaks them without adding a lot of cruft.

Please file and/or link an issue about the initFromRemote problem if there isn't one before you merge.

@Vtec234
Vtec234 merged commit 933a761 into main Sep 30, 2026
1 check passed
@Vtec234
Vtec234 deleted the connect-init branch October 3, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants