MCPcopy Create free account
hub / github.com/cogentcore/core / CompleteMatch

Method CompleteMatch

shell/complete.go:19–63  ·  view source on GitHub ↗

CompleteMatch is the [complete.MatchFunc] for the shell.

(data any, text string, posLine, posChar int)

Source from the content-addressed store, hash-verified

17
18// CompleteMatch is the [complete.MatchFunc] for the shell.
19func (sh *Shell) CompleteMatch(data any, text string, posLine, posChar int) (md complete.Matches) {
20 comps := complete.Completions{}
21 text = text[:posChar]
22 md.Seed = complete.SeedPath(text)
23 fullPath := complete.SeedSpace(text)
24 fullPath = errors.Log1(homedir.Expand(fullPath))
25 parent := strings.TrimSuffix(fullPath, md.Seed)
26 dir := filepath.Join(sh.Config.Dir, parent)
27 if filepath.IsAbs(parent) {
28 dir = parent
29 }
30 entries := errors.Log1(os.ReadDir(dir))
31 for _, entry := range entries {
32 icon := icons.File
33 if entry.IsDir() {
34 icon = icons.Folder
35 }
36 name := strings.ReplaceAll(entry.Name(), " ", `\ `) // escape spaces
37 comps = append(comps, complete.Completion{
38 Text: name,
39 Icon: icon,
40 Desc: filepath.Join(sh.Config.Dir, name),
41 })
42 }
43 if parent == "" {
44 for cmd := range sh.Builtins {
45 comps = append(comps, complete.Completion{
46 Text: cmd,
47 Icon: icons.Terminal,
48 Desc: "Builtin command: " + cmd,
49 })
50 }
51 for cmd := range sh.Commands {
52 comps = append(comps, complete.Completion{
53 Text: cmd,
54 Icon: icons.Terminal,
55 Desc: "Command: " + cmd,
56 })
57 }
58 // todo: write something that looks up all files on path -- should cache that per
59 // path string setting
60 }
61 md.Matches = complete.MatchSeedCompletion(comps, md.Seed)
62 return md
63}
64
65// CompleteEdit is the [complete.EditFunc] for the shell.
66func (sh *Shell) CompleteEdit(data any, text string, cursorPos int, completion complete.Completion, seed string) (ed complete.Edit) {

Callers 1

DoMethod · 0.80

Calls 7

SeedPathFunction · 0.92
SeedSpaceFunction · 0.92
Log1Function · 0.92
MatchSeedCompletionFunction · 0.92
ReadDirMethod · 0.80
NameMethod · 0.65
IsDirMethod · 0.45

Tested by

no test coverage detected