patch 9.1.1812: completion: flicker with slow LSPs

Commit: 
https://github.com/vim/vim/commit/71b97f29054135151d618433a11ce611ba25844d
Author: Girish Palya <[email protected]>
Date:   Mon Sep 29 20:56:06 2025 +0000

    patch 9.1.1812: completion: flicker with slow LSPs
    
    Problem:  completion: flicker with slow LSPs
    Solution: Disable flushing the changed text (Girish Palya).
    
    In insert-mode completion, the leader text is temporarily deleted while
    searching for completion candidates. If the LSP server responds slowly,
    the client may call `:sleep` to wait, which triggers `out_flush()`. This
    causes the deleted text to briefly disappear before being redrawn when
    results arrive, producing a visible flicker.
    
    There are two possible fixes:
    
    1. Suppress flushing while a user function (e.g. LSP client) is waiting.
    2. Reinsert the deleted text before invoking the user function.
    
    This Commit implements (1), which is the simpler solution, though somewhat
    heavy-handed. If you think this may introduce unwanted side effects, I
    can rework it to use (2).
    
    closes: #18439
    
    Signed-off-by: Girish Palya <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/globals.h b/src/globals.h
index 5e2f7b0f4..b105ce515 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -1133,6 +1133,9 @@ EXTERN int        secure INIT(= FALSE);
                                // allowed, e.g. when sourcing .exrc or .vimrc
                                // in current directory
 
+EXTERN int     no_flush INIT(= 0);
+                               // non-zero to prevent flushing output buffer
+
 EXTERN int     textlock INIT(= 0);
                                // non-zero when changing text and jumping to
                                // another window or editing another buffer is
diff --git a/src/insexpand.c b/src/insexpand.c
index 286fc0b47..17d0965ff 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -3601,8 +3601,18 @@ expand_by_function(int type, char_u *base, callback_T 
*cb)
     // Insert mode in another buffer.
     ++textlock;
 
+    // Suppress flushing of the output buffer. Without this, text removed
+    // temporarily by ins_compl_delete() is flushed to the terminal and shown
+    // as deleted, only to be redrawn later. This causes visible flicker (typed
+    // chars disappear and reappear) when a user func (e.g. an LSP server)
+    // responds slowly. Such funcs may call sleep(), which indirectly triggers
+    // out_flush(). We want deleted text to remain visible.
+    ++no_flush;
+
     retval = call_callback(cb, 0, &rettv, 2, args);
 
+    --no_flush;
+
     // Call a function, which returns a list or dict.
     if (retval == OK)
     {
@@ -6093,7 +6103,6 @@ find_next_completion_match(
     int                compl_fuzzy_match = (cur_cot_flags & COT_FUZZY) != 0;
     string_T   *leader;
 
-
     while (--todo >= 0)
     {
        if (compl_shows_dir_forward() && compl_shown_match->cp_next != NULL)
@@ -6203,7 +6212,7 @@ find_next_completion_match(
  *
  * Note that this function may be called recursively once only.  First with
  * "allow_get_expansion" TRUE, which calls ins_compl_get_exp(), which in turn
- * calls this function with "allow_get_expansion" FALSE.
+ * calls this with "allow_get_expansion" FALSE (via ins_compl_check_keys()).
  */
     static int
 ins_compl_next(
diff --git a/src/term.c b/src/term.c
index e23085837..0fa5652b3 100644
--- a/src/term.c
+++ b/src/term.c
@@ -2772,7 +2772,7 @@ out_flush(void)
 {
     int            len;
 
-    if (out_pos == 0)
+    if (no_flush > 0 || out_pos == 0)
        return;
 
     // set out_pos to 0 before ui_write, to avoid recursiveness
diff --git a/src/testdir/test_ins_complete.vim 
b/src/testdir/test_ins_complete.vim
index e7346b8b5..5f5fb8d97 100644
--- a/src/testdir/test_ins_complete.vim
+++ b/src/testdir/test_ins_complete.vim
@@ -420,7 +420,7 @@ func Test_CompleteDoneDict()
   au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict(0)
 
   set complete=.,F<SID>CompleteDone_CompleteFuncDict
-  execute "normal a\<C-N>\<C-Y>"
+  execute "normal dda\<C-N>\<C-Y>"
   set complete&
 
   call assert_equal(['one', 'two'], v:completed_item[ 'user_data' ])
@@ -473,7 +473,7 @@ func Test_CompleteDoneDictNoUserData()
   let s:called_completedone = 0
 
   set complete=.,F<SID>CompleteDone_CompleteFuncDictNoUserData
-  execute "normal a\<C-N>\<C-Y>"
+  execute "normal dda\<C-N>\<C-Y>"
   set complete&
 
   call assert_equal('', v:completed_item[ 'user_data' ])
diff --git a/src/version.c b/src/version.c
index 5c74bc0e1..d989f097a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1812,
 /**/
     1811,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1v3Kya-001sqb-5z%40256bit.org.

Raspunde prin e-mail lui