@@ -840,7 +840,7 @@ static gboolean on_editor_notify(G_GNUC_UNUSED GObject *obj, GeanyEditor *editor
840
840
LspServer * srv ;
841
841
842
842
// 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 )))
844
844
return FALSE;
845
845
846
846
srv = lsp_server_get (doc );
@@ -861,26 +861,43 @@ static gboolean on_editor_notify(G_GNUC_UNUSED GObject *obj, GeanyEditor *editor
861
861
{
862
862
LspPosition pos_start = lsp_utils_scintilla_pos_to_lsp (sci , nt -> position );
863
863
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 );
865
874
866
- memcpy (text , nt -> text , nt -> length );
867
- text [nt -> length ] = '\0' ;
868
875
lsp_sync_text_document_did_change (srv , doc , pos_start , pos_end , text );
869
876
870
877
g_free (text );
871
878
}
872
- else if (nt -> modificationType & SC_MOD_BEFOREDELETE ) // BEFORE! delete
879
+ else if (srv -> use_incremental_sync && ( nt -> modificationType & SC_MOD_BEFOREDELETE ))
873
880
{
881
+ // BEFORE! delete for incremental sync
874
882
LspPosition pos_start = lsp_utils_scintilla_pos_to_lsp (sci , nt -> position );
875
883
LspPosition pos_end = lsp_utils_scintilla_pos_to_lsp (sci , nt -> position + nt -> length );
876
884
gchar * text = g_strdup ("" );
877
885
878
886
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 );
879
895
896
+ lsp_sync_text_document_did_change (srv , doc , dummy_start , dummy_end , text );
880
897
g_free (text );
881
898
}
882
899
883
- if (nt -> modificationType & (SC_MOD_INSERTTEXT | SC_MOD_BEFOREDELETE ))
900
+ if (nt -> modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT ))
884
901
{
885
902
guint update_source = GPOINTER_TO_UINT (plugin_get_document_data (geany_plugin , doc , UPDATE_SOURCE_DOC_DATA ));
886
903
0 commit comments