From 5019b312d999f4f9c6a6acee1f047b9587c06f79 Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Fri, 21 Nov 2025 23:38:54 +0100 Subject: Add support for documentChanges in LSP These should ideally be paired with setting the capability on initialize, but for now, the parsing support is there at least for LSP servers that ignore it (like pylsp). --- src/main/lsp.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/main/lsp.c') diff --git a/src/main/lsp.c b/src/main/lsp.c index a8e806b..6c5999c 100644 --- a/src/main/lsp.c +++ b/src/main/lsp.c @@ -12,6 +12,7 @@ #include "dged/minibuffer.h" #include "dged/reactor.h" #include "dged/settings.h" +#include "dged/vec.h" #include "dged/window.h" #include "lsp/references.h" @@ -790,6 +791,25 @@ bool apply_edits(struct lsp_server *server, buffer_push_undo_boundary(b); } + VEC_FOR_EACH(&ws_edit->document_changes, struct text_document_edit * edit) { + if (VEC_EMPTY(&edit->edits)) { + continue; + } + + const char *p = s8tocstr(edit->text_document.uri); + struct buffer *b = buffers_find_by_filename(g_lsp_data.buffers, &p[7]); + + if (b == NULL) { + struct buffer new_buf = buffer_from_file(&p[7]); + b = buffers_add(g_lsp_data.buffers, new_buf); + } + + free((void *)p); + buffer_push_undo_boundary(b); + apply_edits_buffer(server, b, edit->edits, NULL); + buffer_push_undo_boundary(b); + } + resume_completion(); return true; } -- cgit v1.2.3