WolfgangMehner / vim-plugins

Vim plug-ins which offer support for various programming languages.
415 stars 96 forks source link

Bash-Support: parce call stack on error #49

Open bam80 opened 5 years ago

bam80 commented 5 years ago

We already can jump to error place in the script. But it would be fine if we could have also call stack in QuickFix window. That way we could jump on the stack even without debugger. The call stack can be traced out with caller builtin, using trap on error. We just need to tune 'errorformat' to parse it properly.

WolfgangMehner commented 5 years ago

This is not really my area of expertise, but I guess the use case would be like this:

Backtrace () {
  i=1
  while caller $i
  do
    i=$((i+1))
  done
}
trap 'Backtrace' EXIT ERR

Then you get a trace like:

test.sh|33| MY_UNBOUND_VARIABLE: unbound variable
|| 39 bbb /home/wolfgang/path/test.sh
|| 42 main /home/wolfgang/path/test.sh
bam80 commented 5 years ago

@WolfgangMehner thanks, could you please attach the test script here?

WolfgangMehner commented 5 years ago

My point was mainly about the format we need to be able to pass. I guessed the following format:

<line-number> <function-name> <file-name>

Here is the full script (can not upload *.sh for some reason):

trap_test.txt

WolfgangMehner commented 5 years ago

Extended the error format for testing: https://github.com/WolfgangMehner/vim-plugins/tree/bashsupport-trace-test

bam80 commented 5 years ago

@WolfgangMehner Thanks for your kind. The links is broken

WolfgangMehner commented 5 years ago

Can you find the branch "bashsupport-trace-test" anyway?

WolfgangMehner commented 5 years ago

I'm not sure I fully understood your last comment, sorry. Which link or links is broken?

bam80 commented 5 years ago

Sorry, my fault - I just didn't catch the link points to the other branch.