Example #1
0
// doQuery poses query q to the oracle and writes its response and
// error (if any) to out.
func doQuery(out io.Writer, q *query, useJson bool) {
	fmt.Fprintf(out, "-------- @%s %s --------\n", q.verb, q.id)

	var buildContext = build.Default
	buildContext.GOPATH = "testdata"
	res, err := oracle.Query([]string{q.filename},
		q.verb,
		q.queryPos,
		nil, // ptalog,
		&buildContext,
		true) // reflection
	if err != nil {
		fmt.Fprintf(out, "\nError: %s\n", err)
		return
	}

	if useJson {
		// JSON output
		b, err := json.MarshalIndent(res.Serial(), "", "\t")
		if err != nil {
			fmt.Fprintf(out, "JSON error: %s\n", err.Error())
			return
		}
		out.Write(b)
	} else {
		// "plain" (compiler diagnostic format) output
		WriteResult(out, res)
	}
}
Example #2
0
func queryOracle(mode, pos string) (*oracle.Result, error) {
	mutex.Lock()
	defer mutex.Unlock()
	if mode == "what" {
		return oracle.Query(args, mode, pos, nil, &build.Default, false)
	}
	qpos, err := oracle.ParseQueryPos(prog, pos, false)
	if err != nil {
		return nil, err
	}
	return ora.Query(mode, qpos)
}