diff options
-rw-r--r-- | runtime/syntax/vim.vim | 80 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 6 | ||||
-rw-r--r-- | src/nvim/insexpand.c | 2 | ||||
-rw-r--r-- | src/nvim/math.c | 8 | ||||
-rw-r--r-- | src/nvim/rbuffer.c | 5 | ||||
-rw-r--r-- | test/functional/api/server_requests_spec.lua | 18 | ||||
-rw-r--r-- | test/functional/ex_cmds/drop_spec.lua | 20 | ||||
-rw-r--r-- | test/old/testdir/test_excmd.vim | 16 |
8 files changed, 135 insertions, 20 deletions
diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim index d5761087e0..d37c54a63f 100644 --- a/runtime/syntax/vim.vim +++ b/runtime/syntax/vim.vim @@ -155,7 +155,7 @@ syn match vimNumber '\%(^\|\A\)\zs#\x\{6}' skipwhite nextgroup=vimGlobal,vimSub syn case match " All vimCommands are contained by vimIsCommand. {{{2 -syn cluster vimCmdList contains=vimAbb,vimAddress,vimAutoCmd,vimAugroup,vimBehave,@vimEcho,vimExecute,vimIsCommand,vimExtCmd,vimFunction,vimGlobal,vimHighlight,vimLet,vimMap,vimMark,vimNotFunc,vimNorm,vimSet,vimSyntax,vimUnlet,vimUnmap,vimUserCmd,vimMenu,vimMenutranslate +syn cluster vimCmdList contains=vimAbb,vimAddress,vimAutoCmd,vimAugroup,vimBehave,vimDef,@vimEcho,vimEnddef,vimEndfunction,vimExecute,vimIsCommand,vimExtCmd,vimFor,vimFunction,vimGlobal,vimHighlight,vimLet,vimMap,vimMark,vimNotFunc,vimNorm,vimSet,vimSyntax,vimUnlet,vimUnmap,vimUserCmd,vimMenu,vimMenutranslate syn match vimCmdSep "[:|]\+" skipwhite nextgroup=@vimCmdList,vimSubst1 syn match vimIsCommand "\<\%(\h\w*\|[23]mat\%[ch]\)\>" contains=vimCommand syn match vimVar contained "\<\h[a-zA-Z0-9#_]*\>" @@ -215,7 +215,7 @@ syn keyword vimAugroupKey contained aug[roup] skipwhite nextgroup=vimAugroupBan " Operators: {{{2 " ========= -syn cluster vimOperGroup contains=vimEnvvar,vimFunc,vimFuncVar,vimOper,vimOperParen,vimNumber,vimString,vimType,vimRegister,@vimContinue,vim9Comment,vimVar +syn cluster vimOperGroup contains=vimEnvvar,vimFunc,vimFuncVar,vimOper,vimOperParen,vimNumber,vimString,vimRegister,@vimContinue,vim9Comment,vimVar syn match vimOper "||\|&&\|[-+*/%.!]" skipwhite nextgroup=vimString,vimSpecFile syn match vimOper "\%#=1\(==\|!=\|>=\|<=\|=\~\|!\~\|>\|<\|=\|!\~#\)[?#]\{0,2}" skipwhite nextgroup=vimString,vimSpecFile syn match vimOper "\(\<is\|\<isnot\)[?#]\{0,2}\>" skipwhite nextgroup=vimString,vimSpecFile @@ -227,25 +227,67 @@ endif " Functions : Tag is provided for those who wish to highlight tagged functions {{{2 " ========= -syn cluster vimFuncList contains=vimCommand,vimFunctionError,vimFuncKey,Tag,vimFuncSID -syn cluster vimFuncBodyList contains=@vimCmdList,vimCmplxRepeat,vimComment,vim9Comment,vimContinue,vimCtrlChar,vimEnvvar,vimFBVar,vimFunc,vimFunction,vimFuncVar,vimLetHereDoc,vimLineComment,vimNotation,vimNotFunc,vimNumber,vimOper,vimOperParen,vimRegion,vimRegister,vimSearch,vimSpecFile,vimString,vimSubst -syn match vimFunction "\<\(fu\%[nction]\)!\=\s\+\%(<[sS][iI][dD]>\|[sSgGbBwWtTlL]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)*\ze\s*(" contains=@vimFuncList nextgroup=vimFuncBody -syn match vimFunction "\<def!\=\ze\s*(" contains=@vimFuncList nextgroup=vimFuncBody +syn cluster vimFuncList contains=vimFuncBang,vimFunctionError,vimFuncKey,vimFuncSID,Tag +syn cluster vimDefList contains=vimFuncBang,vimFunctionError,vimDefKey,vimFuncSID,Tag +syn cluster vimFuncBodyList contains=@vimCmdList,vimCmplxRepeat,vimComment,vimContinue,vimCtrlChar,vimDef,vimEnvvar,vimFBVar,vimFunc,vimFunction,vimFuncVar,vimLetHereDoc,vimLineComment,vimNotation,vimNotFunc,vimNumber,vimOper,vimOperParen,vimRegion,vimRegister,vimSearch,vimSpecFile,vimString,vimSubst +syn cluster vimDefBodyList contains=@vimCmdList,vimCmplxRepeat,vim9Comment,vimContinue,vimCtrlChar,vimDef,vimEnvvar,vimFBVar,vimFunc,vimFunction,vimLetHereDoc,vim9LineComment,vimNotation,vimNotFunc,vimNumber,vimOper,vimOperParen,vimRegion,vimRegister,vimSearch,vimSpecFile,vimString,vimSubst + +syn region vimFuncPattern contained matchgroup=vimOper start="/" end="$" contains=@vimSubstList +syn match vimFunction "\<fu\%[nction]\>" skipwhite nextgroup=vimCmdSep,vimComment,vimFuncPattern contains=vimFuncKey +syn match vimDef "\<def\>" skipwhite nextgroup=vimCmdSep,vimComment,vimFuncPattern contains=vimDefKey + +syn match vimFunction "\<fu\%[nction]\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+" contains=@vimFuncList skipwhite nextgroup=vimFuncParams +syn match vimDef "\<def\s\+new\%(\i\|{.\{-1,}}\)\+" contains=@vimDefList nextgroup=vimDefParams +syn match vimDef "\<def\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+" contains=@vimDefList nextgroup=vimDefParams + +syn match vimFuncComment contained +".*+ skipwhite skipnl nextgroup=vimFuncBody,vimEndfunction +syn match vimDefComment contained "#.*" skipwhite skipnl nextgroup=vimDefBody,vimEnddef + +syn match vimFuncBang contained "!" +syn match vimFuncSID contained "\c<sid>" +syn match vimFuncSID contained "\<[sg]:" +syn keyword vimFuncKey contained fu[nction] +syn keyword vimDefKey contained def + +syn region vimFuncParams contained matchgroup=Delimiter start="(" skip=+\n\s*\\\|\n\s*"\\ + end=")" skipwhite skipnl nextgroup=vimFuncBody,vimFuncComment,vimEndfunction,vimFuncMod contains=vimFuncParam,@vimContinue +syn region vimDefParams contained matchgroup=Delimiter start="(" end=")" skipwhite skipnl nextgroup=vimDefBody,vimDefComment,vimEnddef,vimReturnType contains=vimDefParam,vim9Comment +syn match vimFuncParam contained "\<\h\w*\>\|\.\.\." skipwhite nextgroup=vimFuncParamEquals +syn match vimDefParam contained "\<\h\w*\>" skipwhite nextgroup=vimParamType,vimFuncParamEquals + +syn match vimFuncParamEquals contained "=" skipwhite nextgroup=@vimExprList +syn match vimFuncMod contained "\<\%(abort\|closure\|dict\|range\)\>" skipwhite skipnl nextgroup=vimFuncBody,vimFuncComment,vimEndfunction,vimFuncMod + +syn region vimFuncBody contained start="^" matchgroup=vimCommand end="\<endfu\%[nction]\>" contains=@vimFuncBodyList +syn region vimDefBody contained start="^" matchgroup=vimCommand end="\<enddef\>" contains=@vimDefBodyList + +syn match vimEndfunction "\<endf\%[unction]\>" +syn match vimEnddef "\<enddef\>" if exists("g:vimsyn_folding") && g:vimsyn_folding =~# 'f' - syn region vimFuncBody contained fold start="\ze\s*(" matchgroup=vimCommand end="\<\(endf\>\|endfu\%[nction]\>\|enddef\>\)" contains=@vimFuncBodyList -else - syn region vimFuncBody contained start="\ze\s*(" matchgroup=vimCommand end="\<\(endf\>\|endfu\%[nction]\>\|enddef\>\)" contains=@vimFuncBodyList + syn region vimFuncFold start="\<fu\%[nction]\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+\s*(" end="\<endf\%[unction]\>" contains=vimFunction fold keepend transparent + syn region vimFuncFold start="\<def\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+(" end="\<enddef\>" contains=vimDef fold keepend transparent + syn region vimFuncFold start="\<def\s\+new\%(\i\|{.\{-1,}}\)\+(" end="\<enddef\>" contains=vimDef fold keepend transparent endif -syn match vimFuncVar contained "a:\(\K\k*\|\d\+\)" -syn match vimFuncSID contained "\c<sid>\|\<s:" -syn keyword vimFuncKey contained fu[nction] + +syn match vimFuncVar contained "a:\%(\K\k*\|\d\+\)\>" syn match vimFuncBlank contained "\s\+" syn keyword vimPattern contained start skip end +" Types: {{{2 +" ===== " vimTypes : new for vim9 -syn match vimType ":\s*\zs\<\(bool\|number\|float\|string\|blob\|list<\|dict<\|job\|channel\|func\)\>" +syn region vimReturnType contained start=":\s" end="$" matchgroup=vim9Comment end="\ze#" skipwhite skipnl nextgroup=vimDefBody,vimDefComment,vimEnddef contains=vimTypeSep transparent +syn match vimParamType contained ":\s\+\a" skipwhite skipnl nextgroup=vimFuncParamEquals contains=vimTypeSep,@vimType + +syn match vimTypeSep contained ":\s\@=" skipwhite nextgroup=@vimType +syn keyword vimType contained any blob bool channel float job number string void +syn match vimType contained "\<func\>" +syn region vimCompoundType contained matchgroup=vimType start="\<func(" end=")" nextgroup=vimTypeSep contains=@vimType oneline transparent +syn region vimCompoundType contained matchgroup=vimType start="\<\%(list\|dict\)<" end=">" contains=@vimType oneline transparent +syn match vimUserType contained "\<\u\w*\>" + +syn cluster vimType contains=vimType,vimCompoundType,vimUserType " Keymaps: (Vim Project Addition) {{{2 " ======= @@ -454,7 +496,7 @@ syn case ignore syn keyword vimEchohlNone contained none syn case match -syn cluster vimEcho contains=vimEcho.* +syn cluster vimEcho contains=vimEcho,vimEchohl syn region vimExecute matchgroup=vimCommand start="\<exe\%[cute]\>" skip=+\\|\|\n\s*\\\|\n\s*"\\ + matchgroup=vimCmdSep end="|" excludenl end="$" contains=@vimContinue,@vimExprList transparent @@ -977,11 +1019,16 @@ if !exists("skip_vim_syntax_inits") hi def link vimContinue Special hi def link vimContinueComment vimComment hi def link vimCtrlChar SpecialChar + hi def link vimDefComment vimComment + hi def link vimDefKey vimCommand + hi def link vimDefParam vimVar hi def link vimEcho vimCommand hi def link vimEchohlNone vimGroup hi def link vimEchohl vimCommand hi def link vimElseIfErr Error hi def link vimElseif vimCondHL + hi def link vimEndfunction vimCommand + hi def link vimEnddef vimCommand hi def link vimEnvvar PreProc hi def link vimError Error hi def link vimEscape Special @@ -992,8 +1039,13 @@ if !exists("skip_vim_syntax_inits") hi def link vimFor vimCommand hi def link vimFTCmd vimCommand hi def link vimFTOption vimSynType + hi def link vimFuncBang vimBang + hi def link vimFuncComment vimComment hi def link vimFuncKey vimCommand hi def link vimFuncName Function + hi def link vimFuncMod Special + hi def link vimFuncParam vimVar + hi def link vimFuncParamEquals vimOper hi def link vimFuncSID Special hi def link vimFuncVar Identifier hi def link vimGroupAdd vimSynOption diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index a34eb0232b..d754150089 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -866,11 +866,13 @@ void ex_drop(exarg_T *eap) const int save_ar = curbuf->b_p_ar; // reload the file if it is newer - curbuf->b_p_ar = 1; + curbuf->b_p_ar = true; buf_check_timestamp(curbuf); curbuf->b_p_ar = save_ar; } - ex_rewind(eap); + if (curbuf->b_ml.ml_flags & ML_EMPTY) { + ex_rewind(eap); + } return; } } diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 46936ea2bd..fe5faf8c10 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2774,7 +2774,7 @@ static void get_complete_info(list_T *what_list, dict_T *retdict) } if (ret == OK && (what_flag & CI_WHAT_ITEMS || what_flag & CI_WHAT_SELECTED)) { - list_T *li; + list_T *li = NULL; int selected_idx = -1; if (what_flag & CI_WHAT_ITEMS) { li = tv_list_alloc(kListLenMayKnow); diff --git a/src/nvim/math.c b/src/nvim/math.c index 9a0825823c..39d166bb53 100644 --- a/src/nvim/math.c +++ b/src/nvim/math.c @@ -4,6 +4,10 @@ #include <stdint.h> #include <string.h> +#ifdef _MSC_VER +# include <intrin.h> // Required for _BitScanForward64 +#endif + #include "nvim/math.h" #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -52,6 +56,10 @@ int xctz(uint64_t x) // Use compiler builtin if possible. #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 4)) return __builtin_ctzll(x); +#elif defined(_MSC_VER) + unsigned long index; + _BitScanForward64(&index, x); + return (int)index; #else int count = 0; // Set x's trailing zeroes to ones and zero the rest. diff --git a/src/nvim/rbuffer.c b/src/nvim/rbuffer.c index ef286b3e22..493c079d4c 100644 --- a/src/nvim/rbuffer.c +++ b/src/nvim/rbuffer.c @@ -123,7 +123,10 @@ char *rbuffer_read_ptr(RBuffer *buf, size_t *read_count) FUNC_ATTR_NONNULL_ALL void rbuffer_consumed(RBuffer *buf, size_t count) FUNC_ATTR_NONNULL_ALL { - assert(count && count <= buf->size); + if (count == 0) { + return; + } + assert(count <= buf->size); buf->read_ptr += count; if (buf->read_ptr >= buf->end_ptr) { diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 298dbac217..562eeae951 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -363,6 +363,24 @@ describe('server -> client', function() server:close() client:close() end) + + it('via stdio, with many small flushes does not crash #23781', function() + source([[ + let chan = jobstart([v:progpath, '--embed', '--headless', '-n', '-u', 'NONE', '-i', 'NONE'], { 'rpc':v:false }) + call chansend(chan, 0Z94) + sleep 50m + call chansend(chan, 0Z00) + call chansend(chan, 0Z01) + call chansend(chan, 0ZAC) + call chansend(chan, 0Z6E76696D5F636F6D6D616E64) + call chansend(chan, 0Z91) + call chansend(chan, 0ZA5) + call chansend(chan, 0Z71616C6C21) + let g:statuses = jobwait([chan]) + ]]) + eq(eval('g:statuses'), { 0 }) + assert_alive() + end) end) describe('connecting to its own pipe address', function() diff --git a/test/functional/ex_cmds/drop_spec.lua b/test/functional/ex_cmds/drop_spec.lua index cbda5aac98..cfba4e93bd 100644 --- a/test/functional/ex_cmds/drop_spec.lua +++ b/test/functional/ex_cmds/drop_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local command = helpers.command local Screen = require('test.functional.ui.screen') local clear, feed, feed_command = helpers.clear, helpers.feed, helpers.feed_command +local exec = helpers.exec describe(':drop', function() local screen @@ -16,7 +17,7 @@ describe(':drop', function() [2] = { reverse = true }, [3] = { bold = true }, }) - command('set laststatus=2 shortmess-=F') + command('set nohidden laststatus=2 shortmess-=F') end) it('works like :e when called with only one window open', function() @@ -43,7 +44,6 @@ describe(':drop', function() end) it("splits off a new window when a buffer can't be abandoned", function() - command('set nohidden') feed_command('edit tmp1') feed_command('vsplit') feed_command('edit tmp2') @@ -59,4 +59,20 @@ describe(':drop', function() "tmp3" [New] | ]]) end) + + -- oldtest: Test_drop_modified_file() + it('does not cause E37 with modified same file', function() + exec([[ + edit Xdrop_modified.txt + call setline(1, 'The quick brown fox jumped over the lazy dogs') + ]]) + feed_command('drop Xdrop_modified.txt') + screen:expect([[ + ^The quick brown fox jumped over the| + lazy dogs | + {0:~ }|*6 + {1:Xdrop_modified.txt [+] }| + :drop Xdrop_modified.txt | + ]]) + end) end) diff --git a/test/old/testdir/test_excmd.vim b/test/old/testdir/test_excmd.vim index b7356c22fa..4a780078fd 100644 --- a/test/old/testdir/test_excmd.vim +++ b/test/old/testdir/test_excmd.vim @@ -3,6 +3,7 @@ source check.vim source shared.vim source term_util.vim +source screendump.vim func Test_ex_delete() new @@ -758,4 +759,19 @@ func Test_ex_address_range_overflow() call assert_fails(':--+foobar', 'E492:') endfunc +func Test_drop_modified_file() + CheckScreendump + let lines =<< trim END + call setline(1, 'The quick brown fox jumped over the lazy dogs') + END + call writefile([''], 'Xdrop_modified.txt', 'D') + call writefile(lines, 'Xtest_drop_modified', 'D') + let buf = RunVimInTerminal('-S Xtest_drop_modified Xdrop_modified.txt', {'rows': 10,'columns': 40}) + call term_sendkeys(buf, ":drop Xdrop_modified.txt\<CR>") + call VerifyScreenDump(buf, 'Test_drop_modified_1', {}) + + " clean up + call StopVimInTerminal(buf) +endfunc + " vim: shiftwidth=2 sts=2 expandtab |