improve autocomplete
This commit is contained in:
parent
d5edb2bad2
commit
956044cfae
3 changed files with 19 additions and 9 deletions
|
|
@ -19,8 +19,8 @@ package util
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
"gitlab.com/whom/shs/log"
|
||||
"gitlab.com/whom/shs/ast"
|
||||
)
|
||||
|
|
@ -28,7 +28,18 @@ import (
|
|||
// wrap this in a lambda that passes in the vt and ft
|
||||
// I suppose it could be more optimal. Fix if it bothers you
|
||||
func ShellCompleter(line string, vt ast.VarTable, ft ast.FuncTable) []string {
|
||||
dir, path, tok := getPathBase(line)
|
||||
var head, tail string
|
||||
|
||||
idx := strings.LastIndex(line, " ")
|
||||
if idx > 0 {
|
||||
head = line[:idx+1]
|
||||
tail = line[idx+1:]
|
||||
} else {
|
||||
head = ""
|
||||
tail = line
|
||||
}
|
||||
|
||||
dir, path, tok := getPathBase(tail)
|
||||
compSource := []string{}
|
||||
|
||||
if !path {
|
||||
|
|
@ -47,7 +58,7 @@ func ShellCompleter(line string, vt ast.VarTable, ft ast.FuncTable) []string {
|
|||
}
|
||||
} else {
|
||||
for _, f := range fobjs {
|
||||
compSource = append(compSource, f.Name())
|
||||
compSource = append(compSource, dir + "/" + f.Name())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,8 +69,8 @@ func ShellCompleter(line string, vt ast.VarTable, ft ast.FuncTable) []string {
|
|||
|
||||
completions := []string{}
|
||||
for _, i := range compSource {
|
||||
if strings.HasPrefix(i, line) {
|
||||
completions = append(completions, i)
|
||||
if strings.HasPrefix(i, tail) {
|
||||
completions = append(completions, head + i)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue