]> granicus.if.org Git - vim/commitdiff
patch 8.2.4197: cannot use an import in the "expr" part of 'spellsuggest' v8.2.4197
authorBram Moolenaar <Bram@vim.org>
Sun, 23 Jan 2022 17:59:06 +0000 (17:59 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 23 Jan 2022 17:59:06 +0000 (17:59 +0000)
Problem:    Cannot use an import in the "expr" part of 'spellsuggest'.
Solution:   Set the script context when evaluating "expr" of 'spellsuggest'.

src/evalvars.c
src/testdir/test_vim9_import.vim
src/version.c

index 305ffe548863b44eea94b79ae17a3f07033fa139..bd8cc73a12fe9a03e3bcbe1eacd693f6839f8e32 100644 (file)
@@ -495,12 +495,17 @@ eval_spell_expr(char_u *badword, char_u *expr)
     typval_T   rettv;
     list_T     *list = NULL;
     char_u     *p = skipwhite(expr);
+    sctx_T     saved_sctx = current_sctx;
+    sctx_T     *ctx;
 
     // Set "v:val" to the bad word.
     prepare_vimvar(VV_VAL, &save_val);
     set_vim_var_string(VV_VAL, badword, -1);
     if (p_verbose == 0)
        ++emsg_off;
+    ctx = get_option_sctx("spellsuggest");
+    if (ctx != NULL)
+       current_sctx = *ctx;
 
     if (eval1(&p, &rettv, &EVALARG_EVALUATE) == OK)
     {
@@ -514,6 +519,7 @@ eval_spell_expr(char_u *badword, char_u *expr)
        --emsg_off;
     clear_tv(get_vim_var_tv(VV_VAL));
     restore_vimvar(VV_VAL, &save_val);
+    current_sctx = saved_sctx;
 
     return list;
 }
index 3b7ec9cba6a83d0ff2727a26088d93c3b5a7375a..8291e4a4804c45be4f9f1cddadbdef37050efec7 100644 (file)
@@ -936,6 +936,34 @@ def Test_import_in_charconvert()
   set charconvert&
 enddef
 
+func Test_import_in_spellsuggest_expr()
+  CheckFeature spell
+  call Run_Test_import_in_spellsuggest_expr()
+endfunc
+
+def Run_Test_import_in_spellsuggest_expr()
+  var lines =<< trim END
+      vim9script
+      export def MySuggest(): list<any>
+        return [['Fox', 8], ['Fop', 9]]
+      enddef
+  END
+  writefile(lines, 'Xsuggest.vim')
+
+  lines =<< trim END
+      vim9script
+      import './Xsuggest.vim' as sugg
+      set spell spellsuggest=expr:sugg.MySuggest()
+  END
+  CheckScriptSuccess(lines)
+
+  set verbose=1  # report errors
+  call assert_equal(['Fox', 'Fop'], spellsuggest('Fo', 2))
+
+  delete('Xsuggest.vim')
+  set nospell spellsuggest& verbose=0
+enddef
+
 def Test_export_fails()
   CheckScriptFailure(['export var some = 123'], 'E1042:')
   CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
index 13a91bff40c072555ff59ed15622f59324065ef1..42e313c0fbb4a1a7f16b252e3e2ddebecc56bc49 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4197,
 /**/
     4196,
 /**/