Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error struct { // Throwpint similar to v:throwpint. You can build stacktrace from this using // Vim.Build() // e.g. // function F[5]..<lambda>3[1]..<SNR>13_test3[2] // /path/to/file.vim[14] Throwpoint string `json:"throwpoint"` // Vim script error message // e.g. // E121: Undefined variable: err1 // E15: Invalid expression: err1 Messages []string `json:"messages"` }
Error represents Vim script error vimdoc:type:
Error *stacktrace-type-error*
func Histerrs ¶
Histerrs parses given message history and returns all errors. :h :message Example(msghist):
Error detected while processing function Main[2]..<SNR>96_test[1]..<SNR>96_test2[1]..F: line 3: E121: Undefined variable: err1 E15: Invalid expression: err1 line 4: E121: Undefined variable: err2 E15: Invalid expression: err2 Error detected while processing /path/to/file.vim: line 33: E605: Exception not caught: 0
vimdoc:func:
stacktrace#histerrs([{string}]) *stacktrace#histerrs()* Parses message history and returns list of error |stacktrace-type-error|. |:message| content is used by default.
type Stack ¶
type Stack struct { // Function name including <SNR> for script local function Funcname string `json:"funcname,omitempty"` // The line number relative to the start of the function Flnum int `json:"flnum,omitempty"` // Line text. It's empty if the func is lambda or partial Line string `json:"line,omitempty"` // Filename is empty if func is defined in Ex-command line Filename string `json:"filename,omitempty"` // The line number relative to the start of the file Lnum int `json:"lnum,omitempty"` // Text for quickfix or location list Text string `json:"text,omitempty"` }
Stack represents a stack of stacktrace. The field names are compatible with quickfix and location list. :h setqflist()
vimdoc:type:
Stack *stacktrace-type-stack*
type Stacktrace ¶
type Stacktrace struct {
Stacks []*Stack `json:"stacks"`
}
Stacktrace represents stacktrace.
vimdoc:type:
Stacktrace *stacktrace-type-stacktrace*
type Vim ¶
type Vim struct {
// contains filtered or unexported fields
}
Vim is vim client wrapper for stacktrace pkg.
func (*Vim) Build ¶
func (cli *Vim) Build(throwpoint string) (*Stacktrace, error)
Build builds rich stacktrace from given throwpoint.
vimdoc:func:
stacktrace#build({throwpoint}) *stacktrace#build()* Return rich stacktrace |stacktrace-type-stacktrace| from given throwpoint similar to |v:throwpoint|. Example throwpoint: - function <SNR>13_test[1]..<SNR>13_test3, line 2 - function <SNR>13_test[1]..<SNR>13_test3[2] - /path/to/file[2]
Example ¶
scripts := ` function! F() abort let l:G = {-> s:test()} return l:G() endfunction function! s:test() abort return s:d.f() endfunction let s:d = {} function! s:d.f() abort return s:test2() endfunction function! s:test2() abort try throw 'error!' catch return v:throwpoint " You can use stacktrace#build in Vim script " call stacktrace#build(v:throwpoint) endtry " If you just want the current callstack, use stacktrace#callstack() " call stacktrace#callstack() endfunction ` tmp, _ := ioutil.TempFile("", "vim-stacktrace-test") defer tmp.Close() defer os.Remove(tmp.Name()) tmp.WriteString(scripts) filename := tmp.Name() cli, closer, err := vim.NewChildClient(&testHandler{}, vimArgs) if err != nil { log.Fatal(err) } defer closer.Close() v := &Vim{c: cli} v.c.Ex(":source " + filename) throwpoint, _ := v.c.Expr("g:F()") stacktrace, _ := v.Build(throwpoint.(string)) for _, stack := range stacktrace.Stacks { if stack.Filename != "" { stack.Filename = "/path/to/file.vim" } fmt.Println(stack) }
Output: /path/to/file.vim:4: F:2: return l:G() :0: <lambda>1:1: /path/to/file.vim:8: <SNR>2_test:1: return s:d.f() /path/to/file.vim:0: {1}:1: return s:test2() /path/to/file.vim:18: <SNR>2_test2:2: throw 'error!'
func (*Vim) Callstack ¶
func (cli *Vim) Callstack() (*Stacktrace, error)
Callstack returns current callstack.
vimdoc:func:
stacktrace#callstack() *stacktrace#callstack()* Returns current callstack |stacktrace-type-stacktrace|.
func (*Vim) Fromhist ¶
func (cli *Vim) Fromhist() (*Stacktrace, error)
Fromhist returns selected stacktrace from errors in message history.
vimdoc:func:
stacktrace#fromhist() *stacktrace#fromhist()* Show error candidates from |message-history| and returns stacktrace of selected error |stacktrace-type-stacktrace|.
Click to show internal directories.
Click to hide internal directories.