Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ wheels/

# Virtual environments
*env*

# Logs
*.log
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
# ELVA Neovim Real-time Collaboration Plugin



During development I'm using this ugly line to Update the Plugin and start nvim and connect to the elva server in one command

```bash
$ nvim -u vimrc --headless -c "UpdateRemotePlugins" -c "q" 2>&1| grep 'registered plugins' | grep 'elva_nvim' && nvim -u vimrc -c "ElvaConnect localhost 8089 1234567890"
```

## Roadmap

### Functionality

- [ ] bidirectional text sync
- [x] bidirectional text sync
- [x] text sync from ytext to neovim buffer
- [x] text sync from neovim buffer to ytext
- [ ] bidirectional awareness sync
- [ ] efficient text delta passing between Neovim and plugin
- [ ] awareness sync from ydoc to neovim
- [ ] awareness sync from neovim to ydoc
- [x] efficient text delta passing between Neovim and plugin
- [ ] session management (grouping of documents)


Expand All @@ -29,6 +40,23 @@
- [ ] Visual Studio Code


### Utilities

- [ ] decorator to not have explicit function arguments and not just `args: list`


### Testing

- [ ] bidirectional text sync
- [ ] text sync from ytext to neovim buffer
- [ ] text sync from neovim buffer to ytext
- [ ] bidirectional awareness sync
- [ ] awareness sync from ydoc to neovim
- [ ] awareness sync from neovim to ydoc
- [ ] efficient text delta passing between Neovim and plugin
- [ ] session management (grouping of documents)


## Development

- environment setup
Expand Down
59 changes: 59 additions & 0 deletions lua/elva/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
local M = {}

function M.attach(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
-- Listen to byte-level changes to sync with Yjs (which uses linear indices)
local attached = vim.api.nvim_buf_attach(bufnr, false, {
on_bytes = function(_str_bytes, _bufnr, _changedtick, start_row, start_col, byte_offset, _old_end_row, _old_end_col, old_byte_len, new_row, new_col, new_byte_len)
local new_text = ""
vim.notify("Elva: buffer changed")
vim.fn.ElvaLogDebug("_bufnr = ", _bufnr, "start_row =", start_row, "start_col =", start_col, "byte_offset = ", byte_offset, "old_byte_len =", old_byte_len, "new_byte_len =", new_byte_len)

if new_byte_len > 0 then
local end_row = start_row + new_row
local end_col
if new_row == 0 then
end_col = start_col + new_col
else
end_col = new_col
end

local status, lines = pcall(vim.api.nvim_buf_get_text, bufnr, start_row, start_col, end_row, end_col, {})
--local lines = vim.api.nvim_buf_get_text(bufnr, start_row, start_col, end_row, end_col, {})
if status then
new_text = table.concat(lines, "\n")
else
-- catch the pressed `o` on last line error and set `new_text` manually
byte_offset = byte_offset - 1 -- we don't use byte_offset so we don't have to change it,
-- but it is different for `o` and Enter on the last line
new_text = "\n"
end

end
-- Forward the change to the Python host
-- new_bytes is passed as a string (or bytes in msgpack)
vim.fn.ElvaOnBytes(bufnr, start_row, start_col, byte_offset, old_byte_len, new_text)
end
})
if not attached then
vim.notify("Elva: Failed to attach to buffer " .. bufnr, vim.log.levels.ERROR)
end

-- Awareness: Track local cursor movements
local group = vim.api.nvim_create_augroup("ElvaAwareness" .. bufnr, { clear = true })
vim.api.nvim_create_autocmd({"CursorMoved", "CursorMovedI"}, {
group = group,
buffer = bufnr,
callback = function()
local cursor = vim.api.nvim_win_get_cursor(0)
-- cursor is {row, col} (1-based row, 0-based col)
vim.fn.ElvaOnCursorMoved(bufnr, cursor[1] - 1, cursor[2])
end
})
end





return M
1 change: 1 addition & 0 deletions lua/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("elva")
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ keywords = [
dependencies = [
"elva",
"pynvim",
"pytest>=9.0.2",
"pytest-asyncio>=1.3.0",
]

[dependency-groups]
Expand All @@ -68,5 +70,3 @@ documentation = "https://github.com/elva-project/elva.nvim/blob/main/README.md"
issues = "https://github.com/elva-project/elva.nvim/issues"
changelog = "https://github.com/elva-project/elva.nvim/blob/main/CHANGELOG.md"

[tool.uv.sources]
elva = { path = "../elva", editable = true }
1 change: 1 addition & 0 deletions rplugin/python3/elva_nvim/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .plugin import ElvaPlugin
Loading