Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue Tracker: Refactor document change manager (remove dot-repeat hack) #1266

Closed
8 of 10 tasks
theol0403 opened this issue Jul 4, 2023 · 4 comments
Closed
8 of 10 tasks
Assignees
Labels
category: sync synchronization between vscode and nvim (text, windows, etc) manager: document_change priority

Comments

@theol0403 theol0403 self-assigned this Jul 4, 2023
@theol0403 theol0403 added category: sync synchronization between vscode and nvim (text, windows, etc) priority manager: document_change labels Jul 4, 2023
@theol0403 theol0403 changed the title Issue Tracker: Buffer sync Issue Tracker: Refactor text edit sync Jul 5, 2023
@theol0403 theol0403 changed the title Issue Tracker: Refactor text edit sync Issue Tracker: Refactor document change manager (remove dot-repeat hack) Jul 5, 2023
@theol0403
Copy link
Member Author

theol0403 commented Jul 12, 2023

Here are my new ideas for removing dot repeat. I had some old ones at #992 (comment), but they mostly involved trying to send edits to nvim in a way that would be picked up by dot repeat. Directly writing to dot repeat is going to be added to nvim at some point according to @justinmk, but not yet iirc.

My new idea takes inspiration from the way that many nvim plugins handle dot repeat: https://www.reddit.com/r/neovim/comments/wkqkzf/adding_dotrepeat_to_plugins/

The challenge is that I need to construct a string to save in operatorfunc.

There are two strategies:

  1. bind vscode type event and record keystrokes before sending them back to vscode. This is a major design decision but the performance should be good with the new extension affinity settings. Whenever an arrow key or cursor is moved, dot repeat is reset.
  2. construct a set of typed changes by parsing the sequential editor changes produced by vscode, and trying to calculate what the user actually typed based on document changes. This is tricky however due to things like auto bracket pairs and discontinuous edits.

This should delete a lot of code.

@theol0403
Copy link
Member Author

This effort might be a no-go :/

The current dot repeat workaround works by
- keys trigger insert mode (ciw, o, etc)
- nvim_buf_set_text adds text to the buffer without updating dot repeat
- escape is pressed
- a separate buffer is made
- the recorded changes are replayed using nvim_input
- escape is sent

However, the only thing we can reasonably record is what is pressed during insert mode - the way that insert mode was reached (for example ciw) is not recorded. Thus, I can't set operatorfunc to repeat the whole sequence including whatever is used to enter insert mode.

Binding type event seems like it would be a bad idea, but I'm not fully sure if my (negative) experiments were properly conducted.

However, as one door closes, another opens, and I have come across neovim/neovim#3306, which should allow me to implement the ideas in #992 (comment).

@theol0403
Copy link
Member Author

I have narrowed it down to two options:

bind vscode type

I have figured out how to not break completions, and the lag seems acceptable.

The challenge

Edits come in both with type and onDocumentChanged. How can I merge them together? Ideas:

  • when type, wait for document changed, and cancel it out surgically
  • after sending type, do a diff from document changed and apply the diff instead
  • go back to syncing changes from a diff when leaving insert mode

parse documentChanges and convert to nvim_insert when applicable

I worked on this last year, and made some good progress. The roadblock was situations where you needed arrows, but now I have a solution. The code is pretty complicated for this though.

xiyaowong added a commit to xiyaowong/vscode-neovim that referenced this issue Sep 10, 2023
…anges

Use nvim's built-in `vim.lsp.util.apply_text_edits` to synchronize document changes.
Due to the built-in function already handling marks, it indirectly fixed
the issue of missing marks vscode-neovim#1266
xiyaowong added a commit that referenced this issue Sep 23, 2023
@xiyaowong
Copy link
Collaborator

Closed, most content may be outdated. If there are new ideas, it's best to start a new discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: sync synchronization between vscode and nvim (text, windows, etc) manager: document_change priority
Projects
Status: Done
Development

No branches or pull requests

2 participants