Exemplo n.º 1
0
// printDoc prints the documentation for the given import path.
func printDoc(ctx *build.Context, path string, cwd string) (*doc.Doc, error) {
	importPath := strings.TrimPrefix(path, bufNamePrefix)
	p := docPrinter{
		Doc:        doc.NewDoc(),
		importPath: importPath,
	}
	if importPath != "" {
		pkg, err := loadPackage(ctx, importPath, cwd, loadPackageDoc|loadPackageExamples|loadPackageFixVendor)
		if err != nil {
			return nil, err
		}
		p.pkg = pkg
	}
	return p.execute()
}
Exemplo n.º 2
0
func (e *explorer) onBufReadCmd(eval *struct {
	Env   context.Env
	Cwd   string `eval:"getcwd()"`
	Name  string `eval:"expand('%')"`
	Bufnr int    `eval:"bufnr('%')"`
}) error {

	ctx := context.Get(&eval.Env)
	d, err := printDoc(&ctx.Build, eval.Name, eval.Cwd)
	if err != nil {
		d := doc.NewDoc()
		d.WriteString(err.Error())
	}
	return e.docm.Display(d, nvim.Buffer(eval.Bufnr))
	/*
		p.Command("nnoremap <buffer> <silent> g? :<C-U>help :Godoc<CR>")
		p.Command(`nnoremap <buffer> <silent> ]] :<C-U>call search('\C\v^[^ \t)}]', 'W')<CR>`)
		p.Command(`nnoremap <buffer> <silent> [[ :<C-U>call search('\C\v^[^ \t)}]', 'Wb')<CR>`)
	*/
}