Example #1
0
func complVariable(n parse.Node, ed *Editor) (int, int, []*candidate) {
	begin, end := n.Begin(), n.End()

	primary, ok := n.(*parse.Primary)
	if !ok || primary.Type != parse.Variable {
		return -1, -1, nil
	}

	splice, ns, head := eval.ParseVariable(primary.Value)

	// Collect matching variables.
	var varnames []string
	iterateVariables(ed.evaler, ns, func(varname string) {
		if strings.HasPrefix(varname, head) {
			varnames = append(varnames, varname)
		}
	})
	sort.Strings(varnames)

	cands := make([]*candidate, len(varnames))
	// Build candidates.
	for i, varname := range varnames {
		cands[i] = &candidate{text: "$" + eval.MakeVariableName(splice, ns, varname)}
	}
	return begin, end, cands
}
Example #2
0
func complFormHeadInner(head string, ed *Editor) ([]*candidate, error) {
	if util.DontSearch(head) {
		return complFilenameInner(head, true)
	}

	var commands []string
	got := func(s string) {
		if strings.HasPrefix(s, head) {
			commands = append(commands, s)
		}
	}
	for special := range isBuiltinSpecial {
		got(special)
	}
	splice, ns, _ := eval.ParseVariable(head)
	iterateVariables(ed.evaler, ns, func(varname string) {
		if strings.HasPrefix(varname, eval.FnPrefix) {
			got(eval.MakeVariableName(splice, ns, varname[len(eval.FnPrefix):]))
		}
	})
	for command := range ed.isExternal {
		got(command)
	}
	sort.Strings(commands)

	cands := []*candidate{}
	for _, cmd := range commands {
		cands = append(cands, &candidate{text: cmd})
	}
	return cands, nil
}
Example #3
0
func complFormHeadInner(head string, ed *Editor) ([]*candidate, error) {
	if util.DontSearch(head) {
		return complFilenameInner(head, true)
	}

	var commands []string
	got := func(s string) {
		if strings.HasPrefix(s, head) {
			commands = append(commands, s)
		}
	}
	for special := range isBuiltinSpecial {
		got(special)
	}
	explode, ns, _ := eval.ParseVariable(head)
	if !explode {
		iterateVariables(ed.evaler, ns, func(varname string) {
			if strings.HasPrefix(varname, eval.FnPrefix) {
				got(eval.MakeVariableName(false, ns, varname[len(eval.FnPrefix):]))
			} else {
				got(eval.MakeVariableName(false, ns, varname) + "=")
			}
		})
	}
	for command := range ed.isExternal {
		got(command)
		if strings.HasPrefix(head, "e:") {
			got("e:" + command)
		}
	}
	// TODO Support non-module namespaces.
	for ns := range ed.evaler.Modules {
		if head != ns+":" {
			got(ns + ":")
		}
	}
	sort.Strings(commands)

	cands := []*candidate{}
	for _, cmd := range commands {
		cands = append(cands, &candidate{text: cmd})
	}
	return cands, nil
}