mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	vim-patch:9.1.1498: completion: 'complete' funcs behave different to 'omnifunc' (#34718)
Problem:  completion: Functions specified in the 'complete' option did
          not have the leader string removed when called with findstart = 0,
          unlike 'omnifunc' behavior
Solution: update behaviour and make behaviour consistent (Girish Palya)
closes: vim/vim#17636
fa16c7ab3f
Co-authored-by: Girish Palya <girishji@gmail.com>
			
			
This commit is contained in:
		| @@ -4237,17 +4237,6 @@ static Callback *get_callback_if_cpt_func(char *p) | |||||||
|   return NULL; |   return NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
| /// Retrieve new completion matches by invoking callback "cb". |  | ||||||
| static void expand_cpt_function(Callback *cb) |  | ||||||
| { |  | ||||||
|   // Re-insert the text removed by ins_compl_delete(). |  | ||||||
|   ins_compl_insert_bytes(compl_orig_text.data + get_compl_len(), -1); |  | ||||||
|   // Get matches |  | ||||||
|   get_cpt_func_completion_matches(cb); |  | ||||||
|   // Undo insertion |  | ||||||
|   ins_compl_delete(false); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| /// get the next set of completion matches for "type". | /// get the next set of completion matches for "type". | ||||||
| /// @return  true if a new match is found, otherwise false. | /// @return  true if a new match is found, otherwise false. | ||||||
| static bool get_next_completion_match(int type, ins_compl_next_state_T *st, pos_T *ini) | static bool get_next_completion_match(int type, ins_compl_next_state_T *st, pos_T *ini) | ||||||
| @@ -4283,7 +4272,7 @@ static bool get_next_completion_match(int type, ins_compl_next_state_T *st, pos_ | |||||||
|  |  | ||||||
|   case CTRL_X_FUNCTION: |   case CTRL_X_FUNCTION: | ||||||
|     if (ctrl_x_mode_normal()) {  // Invoked by a func in 'cpt' option |     if (ctrl_x_mode_normal()) {  // Invoked by a func in 'cpt' option | ||||||
|       expand_cpt_function(st->func_cb); |       get_cpt_func_completion_matches(st->func_cb, true); | ||||||
|     } else { |     } else { | ||||||
|       expand_by_function(type, compl_pattern.data, NULL); |       expand_by_function(type, compl_pattern.data, NULL); | ||||||
|     } |     } | ||||||
| @@ -5982,7 +5971,7 @@ static compl_T *remove_old_matches(void) | |||||||
|  |  | ||||||
| /// Retrieve completion matches using the callback function "cb" and store the | /// Retrieve completion matches using the callback function "cb" and store the | ||||||
| /// 'refresh:always' flag. | /// 'refresh:always' flag. | ||||||
| static void get_cpt_func_completion_matches(Callback *cb) | static void get_cpt_func_completion_matches(Callback *cb, bool restore_leader) | ||||||
| { | { | ||||||
|   int startcol = cpt_sources_array[cpt_sources_index].cs_startcol; |   int startcol = cpt_sources_array[cpt_sources_index].cs_startcol; | ||||||
|  |  | ||||||
| @@ -5992,7 +5981,14 @@ static void get_cpt_func_completion_matches(Callback *cb) | |||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   if (restore_leader) {  // Re-insert the text removed by ins_compl_delete() | ||||||
|  |     ins_compl_insert_bytes(compl_orig_text.data + get_compl_len(), -1); | ||||||
|  |   } | ||||||
|   set_compl_globals(startcol, curwin->w_cursor.col, true); |   set_compl_globals(startcol, curwin->w_cursor.col, true); | ||||||
|  |   if (restore_leader) { | ||||||
|  |     ins_compl_delete(false);  // Undo insertion | ||||||
|  |   } | ||||||
|  |  | ||||||
|   expand_by_function(0, cpt_compl_pattern.data, cb); |   expand_by_function(0, cpt_compl_pattern.data, cb); | ||||||
|   cpt_sources_array[cpt_sources_index].cs_refresh_always = compl_opt_refresh_always; |   cpt_sources_array[cpt_sources_index].cs_refresh_always = compl_opt_refresh_always; | ||||||
|   compl_opt_refresh_always = false; |   compl_opt_refresh_always = false; | ||||||
| @@ -6029,7 +6025,7 @@ static void cpt_compl_refresh(void) | |||||||
|         } |         } | ||||||
|         cpt_sources_array[cpt_sources_index].cs_startcol = startcol; |         cpt_sources_array[cpt_sources_index].cs_startcol = startcol; | ||||||
|         if (ret == OK) { |         if (ret == OK) { | ||||||
|           get_cpt_func_completion_matches(cb); |           get_cpt_func_completion_matches(cb, false); | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -568,8 +568,8 @@ func Test_cpt_func_cursorcol() | |||||||
|       call assert_equal(8, col('.')) |       call assert_equal(8, col('.')) | ||||||
|       return col('.') |       return col('.') | ||||||
|     endif |     endif | ||||||
|     call assert_equal("foo bar", getline(1)) |     call assert_equal("foo ", getline(1)) | ||||||
|     call assert_equal(8, col('.')) |     call assert_equal(5, col('.')) | ||||||
|     " return v:none |     " return v:none | ||||||
|   endfunc |   endfunc | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 zeertzjq
					zeertzjq