diff options
| author | Josh Rahm <rahm@google.com> | 2022-07-18 19:37:18 +0000 |
|---|---|---|
| committer | Josh Rahm <rahm@google.com> | 2022-07-18 19:37:18 +0000 |
| commit | 308e1940dcd64aa6c344c403d4f9e0dda58d9c5c (patch) | |
| tree | 35fe43e01755e0f312650667004487a44d6b7941 /runtime/pack | |
| parent | 96a00c7c588b2f38a2424aeeb4ea3581d370bf2d (diff) | |
| parent | e8c94697bcbe23a5c7b07c292b90a6b70aadfa87 (diff) | |
| download | rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.gz rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.tar.bz2 rneovim-308e1940dcd64aa6c344c403d4f9e0dda58d9c5c.zip | |
Merge remote-tracking branch 'upstream/master' into rahm
Diffstat (limited to 'runtime/pack')
| -rw-r--r-- | runtime/pack/dist/opt/matchit/autoload/matchit.vim | 4 | ||||
| -rw-r--r-- | runtime/pack/dist/opt/termdebug/plugin/termdebug.vim | 256 |
2 files changed, 193 insertions, 67 deletions
diff --git a/runtime/pack/dist/opt/matchit/autoload/matchit.vim b/runtime/pack/dist/opt/matchit/autoload/matchit.vim index e8689980ae..eafb7c0551 100644 --- a/runtime/pack/dist/opt/matchit/autoload/matchit.vim +++ b/runtime/pack/dist/opt/matchit/autoload/matchit.vim @@ -763,9 +763,9 @@ fun! s:ParseSkip(str) let skip = "synIDattr(synID(line('.'),col('.'),1),'name') !~? '" .. \ strpart(skip,2) .. "'" elseif skip[0] == "r" - let skip = "strpart(getline('.'),0,col('.'))=~'" . strpart(skip,2). "'" + let skip = "strpart(getline('.'),0,col('.'))=~'" .. strpart(skip,2) .. "'" elseif skip[0] == "R" - let skip = "strpart(getline('.'),0,col('.'))!~'" . strpart(skip,2). "'" + let skip = "strpart(getline('.'),0,col('.'))!~'" .. strpart(skip,2) .. "'" endif endif return skip diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim index c881133b72..802ebd42b5 100644 --- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim +++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @@ -2,12 +2,13 @@ " " Author: Bram Moolenaar " Copyright: Vim license applies, see ":help license" -" Last Change: 2021 Dec 16 +" Last Change: 2022 Jun 24 " -" WORK IN PROGRESS - Only the basics work -" Note: On MS-Windows you need a recent version of gdb. The one included with -" MingW is too old (7.6.1). -" I used version 7.12 from http://www.equation.com/servlet/equation.cmd?fa=gdb +" WORK IN PROGRESS - The basics works stable, more to come +" Note: In general you need at least GDB 7.12 because this provides the +" frame= response in MI thread-selected events we need to sync stack to file. +" The one included with "old" MingW is too old (7.6.1), you may upgrade it or +" use a newer version from http://www.equation.com/servlet/equation.cmd?fa=gdb " " There are two ways to run gdb: " - In a terminal window; used if possible, does not work on MS-Windows @@ -36,7 +37,7 @@ " " For neovim compatibility, the vim specific calls were replaced with neovim " specific calls: -" term_start -> term_open +" term_start -> termopen " term_sendkeys -> chansend " term_getline -> getbufline " job_info && term_getjob -> using linux command ps to get the tty @@ -70,11 +71,6 @@ set cpo&vim command -nargs=* -complete=file -bang Termdebug call s:StartDebug(<bang>0, <f-args>) command -nargs=+ -complete=file -bang TermdebugCommand call s:StartDebugCommand(<bang>0, <f-args>) -" Name of the gdb command, defaults to "gdb". -if !exists('g:termdebugger') - let g:termdebugger = 'gdb' -endif - let s:pc_id = 12 let s:asm_id = 13 let s:break_id = 14 " breakpoint number is added to this @@ -104,8 +100,17 @@ call s:Highlight(1, '', &background) hi default debugBreakpoint term=reverse ctermbg=red guibg=red hi default debugBreakpointDisabled term=reverse ctermbg=gray guibg=gray +" Get the command to execute the debugger as a list, defaults to ["gdb"]. func s:GetCommand() - return type(g:termdebugger) == v:t_list ? copy(g:termdebugger) : [g:termdebugger] + if exists('g:termdebug_config') + let cmd = get(g:termdebug_config, 'command', 'gdb') + elseif exists('g:termdebugger') + let cmd = g:termdebugger + else + let cmd = 'gdb' + endif + + return type(cmd) == v:t_list ? copy(cmd) : [cmd] endfunc func s:StartDebug(bang, ...) @@ -176,12 +181,10 @@ func s:StartDebug_internal(dict) call s:StartDebug_term(a:dict) endif - if exists('g:termdebug_disasm_window') - if g:termdebug_disasm_window - let curwinid = win_getid(winnr()) - call s:GotoAsmwinOrCreateIt() - call win_gotoid(curwinid) - endif + if s:GetDisasmWindow() + let curwinid = win_getid(winnr()) + call s:GotoAsmwinOrCreateIt() + call win_gotoid(curwinid) endif if exists('#User#TermdebugStartPost') @@ -196,7 +199,7 @@ func s:CloseBuffers() endfunc func s:CheckGdbRunning() - if nvim_get_chan_info(s:gdb_job_id) == {} + if !s:running echoerr string(s:GetCommand()[0]) . ' exited unexpectedly' call s:CloseBuffers() return '' @@ -204,8 +207,8 @@ func s:CheckGdbRunning() return 'ok' endfunc +" Open a terminal window without a job, to run the debugged program in. func s:StartDebug_term(dict) - " Open a terminal window without a job, to run the debugged program in. execute s:vertical ? 'vnew' : 'new' let s:pty_job_id = termopen('tail -f /dev/null;#gdb program') if s:pty_job_id == 0 @@ -251,18 +254,28 @@ func s:StartDebug_term(dict) let proc_args = get(a:dict, 'proc_args', []) let gdb_cmd = s:GetCommand() - " Add -quiet to avoid the intro message causing a hit-enter prompt. - let gdb_cmd += ['-quiet'] - " Disable pagination, it causes everything to stop at the gdb - let gdb_cmd += ['-iex', 'set pagination off'] - " Interpret commands while the target is running. This should usually only - " be exec-interrupt, since many commands don't work properly while the - " target is running (so execute during startup). - let gdb_cmd += ['-iex', 'set mi-async on'] - " Open a terminal window to run the debugger. - let gdb_cmd += ['-tty', pty] - " Command executed _after_ startup is done, provides us with the necessary feedback - let gdb_cmd += ['-ex', 'echo startupdone\n'] + + if exists('g:termdebug_config') && has_key(g:termdebug_config, 'command_add_args') + let gdb_cmd = g:termdebug_config.command_add_args(gdb_cmd, pty) + else + " Add -quiet to avoid the intro message causing a hit-enter prompt. + let gdb_cmd += ['-quiet'] + " Disable pagination, it causes everything to stop at the gdb + let gdb_cmd += ['-iex', 'set pagination off'] + " Interpret commands while the target is running. This should usually only + " be exec-interrupt, since many commands don't work properly while the + " target is running (so execute during startup). + let gdb_cmd += ['-iex', 'set mi-async on'] + " Open a terminal window to run the debugger. + let gdb_cmd += ['-tty', pty] + " Command executed _after_ startup is done, provides us with the necessary + " feedback + let gdb_cmd += ['-ex', 'echo startupdone\n'] + endif + + if exists('g:termdebug_config') && has_key(g:termdebug_config, 'command_filter') + let gdb_cmd = g:termdebug_config.command_filter(gdb_cmd) + endif " Adding arguments requested by the user let gdb_cmd += gdb_args @@ -279,6 +292,8 @@ func s:StartDebug_term(dict) call s:CloseBuffers() return endif + let s:running = v:true + let s:starting = v:true let gdb_job_info = nvim_get_chan_info(s:gdb_job_id) let s:gdbbuf = gdb_job_info['buffer'] let s:gdbwin = win_getid(winnr()) @@ -354,14 +369,16 @@ func s:StartDebug_term(dict) sleep 10m endwhile + let s:starting = v:false + " Set the filetype, this can be used to add mappings. set filetype=termdebug call s:StartDebugCommon(a:dict) endfunc +" Open a window with a prompt buffer to run gdb in. func s:StartDebug_prompt(dict) - " Open a window with a prompt buffer to run gdb in. if s:vertical vertical new else @@ -461,7 +478,7 @@ endfunc func s:StartDebugCommon(dict) " Sign used to highlight the line where the program has stopped. " There can be only one. - sign define debugPC linehl=debugPC + call sign_define('debugPC', #{linehl: 'debugPC'}) " Install debugger commands in the text window. call win_gotoid(s:sourcewin) @@ -522,6 +539,7 @@ func TermDebugSendCommand(cmd) endif sleep 10m endif + " TODO: should we prepend CTRL-U to clear the command? call chansend(s:gdb_job_id, a:cmd . "\r") if do_continue Continue @@ -662,6 +680,11 @@ func s:GetAsmAddr(msg) endfunc function s:EndTermDebug(job_id, exit_code, event) + let s:running = v:false + if s:starting + return + endif + if exists('#User#TermdebugStopPre') doauto <nomodeline> User TermdebugStopPre endif @@ -690,7 +713,9 @@ func s:EndDebugCommon() endif endif endfor - exe was_buf .. "buf" + if bufexists(was_buf) + exe was_buf .. "buf" + endif call s:DeleteCommands() @@ -749,8 +774,8 @@ func s:HandleDisasmMsg(msg) let lnum = search('^' . s:asm_addr) if lnum != 0 - exe 'sign unplace ' . s:asm_id - exe 'sign place ' . s:asm_id . ' line=' . lnum . ' name=debugPC' + call sign_unplace('TermDebug', #{id: s:asm_id}) + call sign_place(s:asm_id, 'TermDebug', 'debugPC', '%', #{lnum: lnum}) endif call win_gotoid(curwinid) @@ -836,6 +861,7 @@ func s:InstallCommands() command Clear call s:ClearBreakpoint() command Step call s:SendResumingCommand('-exec-step') command Over call s:SendResumingCommand('-exec-next') + command -nargs=? Until call s:Until(<q-args>) command Finish call s:SendResumingCommand('-exec-finish') command -nargs=* Run call s:Run(<q-args>) command -nargs=* Arguments call s:SendResumingCommand('-exec-arguments ' . <q-args>) @@ -858,7 +884,13 @@ func s:InstallCommands() command Asm call s:GotoAsmwinOrCreateIt() command Winbar call s:InstallWinbar() - if !exists('g:termdebug_map_K') || g:termdebug_map_K + let map = 1 + if exists('g:termdebug_config') + let map = get(g:termdebug_config, 'map_K', 1) + elseif exists('g:termdebug_map_K') + let map = g:termdebug_map_K + endif + if map " let s:k_map_saved = maparg('K', 'n', 0, 1) let s:k_map_saved = {} for map in nvim_get_keymap('n') @@ -870,6 +902,26 @@ func s:InstallCommands() nnoremap K :Evaluate<CR> endif + if has('menu') && &mouse != '' + call s:InstallWinbar() + + let popup = 1 + if exists('g:termdebug_config') + let popup = get(g:termdebug_config, 'popup', 1) + elseif exists('g:termdebug_popup') + let popup = g:termdebug_popup + endif + if popup + let s:saved_mousemodel = &mousemodel + let &mousemodel = 'popup_setpos' + an 1.200 PopUp.-SEP3- <Nop> + an 1.210 PopUp.Set\ breakpoint :Break<CR> + an 1.220 PopUp.Clear\ breakpoint :Clear<CR> + an 1.230 PopUp.Run\ until :Until<CR> + an 1.240 PopUp.Evaluate :Evaluate<CR> + endif + endif + let &cpo = save_cpo endfunc @@ -894,6 +946,7 @@ func s:DeleteCommands() delcommand Clear delcommand Step delcommand Over + delcommand Until delcommand Finish delcommand Run delcommand Arguments @@ -910,7 +963,7 @@ func s:DeleteCommands() if empty(s:k_map_saved) nunmap K else - " call mapset('n', 0, s:k_map_saved) + " call mapset(s:k_map_saved) let mode = s:k_map_saved.mode !=# ' ' ? s:k_map_saved.mode : '' call nvim_set_keymap(mode, 'K', s:k_map_saved.rhs, { \ 'expr': s:k_map_saved.expr ? v:true : v:false, @@ -923,22 +976,57 @@ func s:DeleteCommands() unlet s:k_map_saved endif - exe 'sign unplace ' . s:pc_id - for [id, entries] in items(s:breakpoints) - for subid in keys(entries) - exe 'sign unplace ' . s:Breakpoint2SignNumber(id, subid) - endfor - endfor + if has('menu') + " Remove the WinBar entries from all windows where it was added. + " let curwinid = win_getid(winnr()) + " for winid in s:winbar_winids + " if win_gotoid(winid) + " aunmenu WinBar.Step + " aunmenu WinBar.Next + " aunmenu WinBar.Finish + " aunmenu WinBar.Cont + " aunmenu WinBar.Stop + " aunmenu WinBar.Eval + " endif + " endfor + " call win_gotoid(curwinid) + " let s:winbar_winids = [] + + if exists('s:saved_mousemodel') + let &mousemodel = s:saved_mousemodel + unlet s:saved_mousemodel + aunmenu PopUp.-SEP3- + aunmenu PopUp.Set\ breakpoint + aunmenu PopUp.Clear\ breakpoint + aunmenu PopUp.Run\ until + aunmenu PopUp.Evaluate + endif + endif + + call sign_unplace('TermDebug') unlet s:breakpoints unlet s:breakpoint_locations - sign undefine debugPC - for val in s:BreakpointSigns - exe "sign undefine debugBreakpoint" . val - endfor + call sign_undefine('debugPC') + call sign_undefine(s:BreakpointSigns->map("'debugBreakpoint' .. v:val")) let s:BreakpointSigns = [] endfunc +" :Until - Execute until past a specified position or current line +func s:Until(at) + if s:stopped + " reset s:stopped here, it may take a bit of time before we get a response + let s:stopped = 0 + " call ch_log('assume that program is running after this command') + " Use the fname:lnum format + let at = empty(a:at) ? + \ fnameescape(expand('%:p')) . ':' . line('.') : a:at + call s:SendCommand('-exec-until ' . at) + " else + " call ch_log('dropping command, program is running: exec-until') + endif +endfunc + " :Break - Set a breakpoint at the cursor position. func s:SetBreakpoint(at) " Setting a breakpoint may not work while the program is running. @@ -972,7 +1060,8 @@ func s:ClearBreakpoint() " Assume this always works, the reply is simply "^done". call s:SendCommand('-break-delete ' . id) for subid in keys(s:breakpoints[id]) - exe 'sign unplace ' . s:Breakpoint2SignNumber(id, subid) + call sign_unplace('TermDebug', + \ #{id: s:Breakpoint2SignNumber(id, subid)}) endfor unlet s:breakpoints[id] unlet s:breakpoint_locations[bploc][idx] @@ -1026,7 +1115,7 @@ func s:Evaluate(range, arg) call s:SendEval(expr) endfunc -" get what is specified / under the cursor +" get what is specified / under the cursor func s:GetEvaluationExpression(range, arg) if a:arg != '' " user supplied evaluation @@ -1257,6 +1346,26 @@ func s:GotoSourcewinOrCreateIt() endif endfunc +func s:GetDisasmWindow() + if exists('g:termdebug_config') + return get(g:termdebug_config, 'disasm_window', 0) + endif + if exists('g:termdebug_disasm_window') + return g:termdebug_disasm_window + endif + return 0 +endfunc + +func s:GetDisasmWindowHeight() + if exists('g:termdebug_config') + return get(g:termdebug_config, 'disasm_window_height', 0) + endif + if exists('g:termdebug_disasm_window') && g:termdebug_disasm_window > 1 + return g:termdebug_disasm_window + endif + return 0 +endfunc + func s:GotoAsmwinOrCreateIt() if !win_gotoid(s:asmwin) if win_gotoid(s:sourcewin) @@ -1280,10 +1389,8 @@ func s:GotoAsmwinOrCreateIt() exe 'file Termdebug-asm-listing' endif - if exists('g:termdebug_disasm_window') - if g:termdebug_disasm_window > 1 - exe 'resize ' . g:termdebug_disasm_window - endif + if s:GetDisasmWindowHeight() > 0 + exe 'resize ' .. s:GetDisasmWindowHeight() endif endif @@ -1294,8 +1401,8 @@ func s:GotoAsmwinOrCreateIt() call s:SendCommand('disassemble $pc') endif else - exe 'sign unplace ' . s:asm_id - exe 'sign place ' . s:asm_id . ' line=' . lnum . ' name=debugPC' + call sign_unplace('TermDebug', #{id: s:asm_id}) + call sign_place(s:asm_id, 'TermDebug', 'debugPC', '%', #{lnum: lnum}) endif endif endfunc @@ -1330,8 +1437,8 @@ func s:HandleCursor(msg) if lnum == 0 call s:SendCommand('disassemble $pc') else - exe 'sign unplace ' . s:asm_id - exe 'sign place ' . s:asm_id . ' line=' . lnum . ' name=debugPC' + call sign_unplace('TermDebug', #{id: s:asm_id}) + call sign_place(s:asm_id, 'TermDebug', 'debugPC', '%', #{lnum: lnum}) endif call win_gotoid(curwinid) @@ -1344,6 +1451,16 @@ func s:HandleCursor(msg) if lnum =~ '^[0-9]*$' call s:GotoSourcewinOrCreateIt() if expand('%:p') != fnamemodify(fname, ':p') + echomsg 'different fname: "' .. expand('%:p') .. '" vs "' .. fnamemodify(fname, ':p') .. '"' + augroup Termdebug + " Always open a file read-only instead of showing the ATTENTION + " prompt, since it is unlikely we want to edit the file. + " The file may be changed but not saved, warn for that. + au SwapExists * echohl WarningMsg + \ | echo 'Warning: file is being edited elsewhere' + \ | echohl None + \ | let v:swapchoice = 'o' + augroup END if &modified " TODO: find existing window exe 'split ' . fnameescape(fname) @@ -1352,11 +1469,15 @@ func s:HandleCursor(msg) else exe 'edit ' . fnameescape(fname) endif + augroup Termdebug + au! SwapExists + augroup END endif exe lnum normal! zv - exe 'sign unplace ' . s:pc_id - exe 'sign place ' . s:pc_id . ' line=' . lnum . ' name=debugPC file=' . fname + call sign_unplace('TermDebug', #{id: s:pc_id}) + call sign_place(s:pc_id, 'TermDebug', 'debugPC', fname, + \ #{lnum: lnum, priority: 110}) if !exists('b:save_signcolumn') let b:save_signcolumn = &signcolumn call add(s:signcolumn_buflist, bufnr()) @@ -1364,7 +1485,7 @@ func s:HandleCursor(msg) setlocal signcolumn=yes endif elseif !s:stopped || fname != '' - exe 'sign unplace ' . s:pc_id + call sign_unplace('TermDebug', #{id: s:pc_id}) endif call win_gotoid(wid) @@ -1381,7 +1502,9 @@ func s:CreateBreakpoint(id, subid, enabled) else let hiName = "debugBreakpoint" endif - exe "sign define debugBreakpoint" . nr . " text=" . substitute(nr, '\..*', '', '') . " texthl=" . hiName + call sign_define('debugBreakpoint' .. nr, + \ #{text: substitute(nr, '\..*', '', ''), + \ texthl: hiName}) endif endfunc @@ -1459,7 +1582,9 @@ endfunc func s:PlaceSign(id, subid, entry) let nr = printf('%d.%d', a:id, a:subid) - exe 'sign place ' . s:Breakpoint2SignNumber(a:id, a:subid) . ' line=' . a:entry['lnum'] . ' name=debugBreakpoint' . nr . ' priority=110 file=' . a:entry['fname'] + call sign_place(s:Breakpoint2SignNumber(a:id, a:subid), 'TermDebug', + \ 'debugBreakpoint' .. nr, a:entry['fname'], + \ #{lnum: a:entry['lnum'], priority: 110}) let a:entry['placed'] = 1 endfunc @@ -1473,7 +1598,8 @@ func s:HandleBreakpointDelete(msg) if has_key(s:breakpoints, id) for [subid, entry] in items(s:breakpoints[id]) if has_key(entry, 'placed') - exe 'sign unplace ' . s:Breakpoint2SignNumber(id, subid) + call sign_unplace('TermDebug', + \ #{id: s:Breakpoint2SignNumber(id, subid)}) unlet entry['placed'] endif endfor |