Skip to content

Commit 757d342

Browse files
committed
Fix incorrect handling of full document sync (used by bash-language-server)
1 parent 57e39f1 commit 757d342

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

lsp/src/lsp-main.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ static gboolean on_editor_notify(G_GNUC_UNUSED GObject *obj, GeanyEditor *editor
840840
LspServer *srv;
841841

842842
// lots of SCN_MODIFIED notifications, filter-out those we are not interested in
843-
if (!(nt->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_BEFOREDELETE | SC_MOD_BEFOREINSERT)))
843+
if (!(nt->modificationType & (SC_MOD_BEFOREINSERT | SC_MOD_INSERTTEXT | SC_MOD_BEFOREDELETE | SC_MOD_DELETETEXT)))
844844
return FALSE;
845845

846846
srv = lsp_server_get(doc);
@@ -861,26 +861,43 @@ static gboolean on_editor_notify(G_GNUC_UNUSED GObject *obj, GeanyEditor *editor
861861
{
862862
LspPosition pos_start = lsp_utils_scintilla_pos_to_lsp(sci, nt->position);
863863
LspPosition pos_end = pos_start;
864-
gchar *text = g_malloc(nt->length + 1);
864+
gchar *text;
865+
866+
if (srv->use_incremental_sync)
867+
{
868+
text = g_malloc(nt->length + 1);
869+
memcpy(text, nt->text, nt->length);
870+
text[nt->length] = '\0';
871+
}
872+
else
873+
text = sci_get_contents(doc->editor->sci, -1);
865874

866-
memcpy(text, nt->text, nt->length);
867-
text[nt->length] = '\0';
868875
lsp_sync_text_document_did_change(srv, doc, pos_start, pos_end, text);
869876

870877
g_free(text);
871878
}
872-
else if (nt->modificationType & SC_MOD_BEFOREDELETE) // BEFORE! delete
879+
else if (srv->use_incremental_sync &&(nt->modificationType & SC_MOD_BEFOREDELETE))
873880
{
881+
// BEFORE! delete for incremental sync
874882
LspPosition pos_start = lsp_utils_scintilla_pos_to_lsp(sci, nt->position);
875883
LspPosition pos_end = lsp_utils_scintilla_pos_to_lsp(sci, nt->position + nt->length);
876884
gchar *text = g_strdup("");
877885

878886
lsp_sync_text_document_did_change(srv, doc, pos_start, pos_end, text);
887+
g_free(text);
888+
}
889+
else if (!srv->use_incremental_sync &&(nt->modificationType & SC_MOD_DELETETEXT))
890+
{
891+
// AFTER! delete for full document sync
892+
LspPosition dummy_start = lsp_utils_scintilla_pos_to_lsp(sci, 0);
893+
LspPosition dummy_end = lsp_utils_scintilla_pos_to_lsp(sci, 0);
894+
gchar *text = sci_get_contents(doc->editor->sci, -1);
879895

896+
lsp_sync_text_document_did_change(srv, doc, dummy_start, dummy_end, text);
880897
g_free(text);
881898
}
882899

883-
if (nt->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_BEFOREDELETE))
900+
if (nt->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT))
884901
{
885902
guint update_source = GPOINTER_TO_UINT(plugin_get_document_data(geany_plugin, doc, UPDATE_SOURCE_DOC_DATA));
886903

lsp/src/lsp-sync.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,15 @@ void lsp_sync_text_document_did_change(LspServer *server, GeanyDocument *doc,
186186
}
187187
else
188188
{
189-
gchar *contents = sci_get_contents(doc->editor->sci, -1);
190189
node = JSONRPC_MESSAGE_NEW (
191190
"textDocument", "{",
192191
"uri", JSONRPC_MESSAGE_PUT_STRING(doc_uri),
193192
"version", JSONRPC_MESSAGE_PUT_INT32(doc_version),
194193
"}",
195194
"contentChanges", "[", "{",
196-
"text", JSONRPC_MESSAGE_PUT_STRING(contents),
195+
"text", JSONRPC_MESSAGE_PUT_STRING(text),
197196
"}", "]"
198197
);
199-
g_free(contents);
200198
}
201199

202200
//printf("%s\n\n\n", lsp_utils_json_pretty_print(node));

0 commit comments

Comments
 (0)