Exemplo n.º 1
0
func (e *explorer) onDoc(args []string, eval *struct {
	Env   context.Env
	Cwd   string `eval:"getcwd()"`
	Name  string `eval:"expand('%')"`
	Bufnr int    `eval:"bufnr('%')"`
}) error {

	if len(args) < 1 || len(args) > 2 {
		return errors.New("one or two arguments required")
	}

	spec, err := e.expandSpec(args[0])
	if err != nil {
		return err
	}

	ctx := context.Get(&eval.Env)
	name := bufNamePrefix + resolvePackageSpec(&ctx.Build, eval.Cwd, nvim.NewBufferReader(e.nvim, nvim.Buffer(eval.Bufnr)), spec)

	var cmds []string
	if name != eval.Name {
		cmds = append(cmds, "edit "+name)
	}

	if len(args) >= 2 {
		cmds = append(cmds, fmt.Sprintf("call cursor(get(b:anchors, %q, [0, 0]))", strings.Trim(args[1], ".")))
	}
	if len(cmds) == 0 {
		return nil
	}
	return e.nvim.Command(strings.Join(cmds, " | "))
}
Exemplo n.º 2
0
func (e *explorer) onDef(args []string, eval *struct {
	Env   context.Env
	Cwd   string `eval:"getcwd()"`
	Bufnr int    `eval:"bufnr('%')"`
}) error {
	if len(args) < 1 || len(args) > 2 {
		return errors.New("one or two arguments required")
	}

	spec, err := e.expandSpec(args[0])
	if err != nil {
		return err
	}

	ctx := context.Get(&eval.Env)
	path := resolvePackageSpec(&ctx.Build, eval.Cwd, nvim.NewBufferReader(e.nvim, nvim.Buffer(eval.Bufnr)), spec)

	var sym string
	if len(args) >= 2 {
		sym = strings.Trim(args[1], ".")
	}

	file, line, col, err := findDef(&ctx.Build, eval.Cwd, path, sym)
	if err != nil {
		return errors.New("definition not found")
	}

	return e.nvim.Command(fmt.Sprintf("edit %s | call cursor(%d, %d)", file, line, col))
}
Exemplo n.º 3
0
func (e *explorer) onComplete(a *nvim.CommandCompletionArgs, eval *struct {
	Env   context.Env
	Cwd   string `eval:"getcwd()"`
	Bufnr int    `eval:"bufnr('%')"`
}) ([]string, error) {

	ctx := context.Get(&eval.Env)

	f := strings.Fields(a.CmdLine)
	var completions []string
	if len(f) >= 3 || (len(f) == 2 && a.ArgLead == "") {
		spec, err := e.expandSpec(f[1])
		if err != nil {
			return nil, err
		}
		completions = completeSymMethodArg(&ctx.Build, resolvePackageSpec(&ctx.Build, eval.Cwd, nvim.NewBufferReader(e.nvim, nvim.Buffer(eval.Bufnr)), spec), a.ArgLead)
	} else {
		completions = completePackageArg(&ctx.Build, eval.Cwd, nvim.NewBufferReader(e.nvim, nvim.Buffer(eval.Bufnr)), a.ArgLead)
	}
	return completions, nil
}