mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-04-01 17:57:31 +02:00
checkpoint on comp
This commit is contained in:
parent
f81bea6658
commit
afbdf644bf
@ -35,8 +35,8 @@ const (
|
||||
)
|
||||
|
||||
func init() {
|
||||
comp.RegisterSimpleCompFn("meta", simpleCompMeta)
|
||||
comp.RegisterSimpleCompFn("command+meta", simpleCompCommandMeta)
|
||||
comp.RegisterSimpleCompFn(comp.CGTypeMeta, simpleCompMeta)
|
||||
comp.RegisterSimpleCompFn(comp.CGTypeCommandMeta, simpleCompCommandMeta)
|
||||
}
|
||||
|
||||
const DefaultUserId = "sawka"
|
||||
|
@ -20,14 +20,19 @@ import (
|
||||
const MaxCompQuoteLen = 5000
|
||||
|
||||
const (
|
||||
SimpleCompGenTypeFile = "file"
|
||||
SimpleCompGenTypeDir = "dir"
|
||||
SimpleCompGenTypeCommand = "command"
|
||||
SimpleCompGenTypeRemote = "remote"
|
||||
SimpleCompGenTypeRemoteInstance = "remoteinstance"
|
||||
SimpleCompGenTypeMetaCmd = "metacmd"
|
||||
SimpleCompGenTypeGlobalCmd = "globalcmd"
|
||||
SimpleCompGenTypeVariable = "variable"
|
||||
// local to simplecomp
|
||||
CGTypeCommand = "command"
|
||||
CGTypeFile = "file"
|
||||
CGTypeDir = "directory"
|
||||
CGTypeVariable = "variable"
|
||||
|
||||
// implemented in cmdrunner
|
||||
CGTypeMeta = "metacmd"
|
||||
CGTypeCommandMeta = "command+meta"
|
||||
|
||||
CGTypeRemote = "remote"
|
||||
CGTypeRemoteInstance = "remoteinstance"
|
||||
CGTypeGlobalCmd = "globalcmd"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -48,13 +53,6 @@ type StrWithPos struct {
|
||||
Pos int
|
||||
}
|
||||
|
||||
type fullCompPrefix struct {
|
||||
RawStr string
|
||||
RawPos int
|
||||
CompPrefix string
|
||||
QuoteTypePref string
|
||||
}
|
||||
|
||||
type ParsedWord struct {
|
||||
Offset int
|
||||
Word *syntax.Word
|
||||
@ -285,7 +283,9 @@ func splitInitialWhitespace(str string) (string, string) {
|
||||
return str, ""
|
||||
}
|
||||
|
||||
func ParseCompPoint(fullCmdStr string, pos int) (*CompPoint, error) {
|
||||
func ParseCompPoint(cmdStr StrWithPos) *CompPoint {
|
||||
fullCmdStr := cmdStr.Str
|
||||
pos := cmdStr.Pos
|
||||
// fmt.Printf("---\n")
|
||||
// fmt.Printf("cmd: %s\n", strWithCursor(fullCmdStr, pos))
|
||||
|
||||
@ -367,7 +367,7 @@ func ParseCompPoint(fullCmdStr string, pos int) (*CompPoint, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return &rtnPoint, nil
|
||||
return &rtnPoint
|
||||
}
|
||||
|
||||
func splitCompWord(p *CompPoint) {
|
||||
@ -387,8 +387,23 @@ func splitCompWord(p *CompPoint) {
|
||||
p.Words = newWords
|
||||
}
|
||||
|
||||
func DoCompGen(ctx context.Context, point CompPoint, rptr sstore.RemotePtrType, state *packet.ShellState) (*CompReturn, error) {
|
||||
return nil, nil
|
||||
func DoCompGen(ctx context.Context, sp StrWithPos, compCtx CompContext) (*CompReturn, *StrWithPos, error) {
|
||||
compPoint := ParseCompPoint(sp)
|
||||
compType := CGTypeFile
|
||||
if compPoint.CompWord == 0 {
|
||||
compType = CGTypeCommandMeta
|
||||
}
|
||||
// TODO lookup special types
|
||||
compPrefix := compPoint.getCompPrefix()
|
||||
crtn, err := DoSimpleComp(ctx, compType, compPrefix, compCtx, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if compCtx.ForDisplay {
|
||||
return crtn, nil, nil
|
||||
}
|
||||
rtnSP := compPoint.FullyExtend(crtn)
|
||||
return crtn, &rtnSP, nil
|
||||
}
|
||||
|
||||
func SortCompReturnEntries(c *CompReturn) {
|
||||
|
@ -16,11 +16,7 @@ func parseToSP(s string) StrWithPos {
|
||||
|
||||
func testParse(cmdStr string, pos int) {
|
||||
fmt.Printf("cmd: %s\n", strWithCursor(cmdStr, pos))
|
||||
p, err := ParseCompPoint(cmdStr, pos)
|
||||
if err != nil {
|
||||
fmt.Printf("err: %v\n", err)
|
||||
return
|
||||
}
|
||||
p := ParseCompPoint(StrWithPos{Str: cmdStr, Pos: pos})
|
||||
p.dump()
|
||||
}
|
||||
|
||||
@ -52,19 +48,13 @@ func testMiniExtend(t *testing.T, p *CompPoint, newWord string, complete bool, e
|
||||
}
|
||||
|
||||
func Test2(t *testing.T) {
|
||||
p, err := ParseCompPoint("ls f", 4)
|
||||
if err != nil {
|
||||
t.Fatalf("error: %v", err)
|
||||
}
|
||||
p := ParseCompPoint(parseToSP("ls f[*]"))
|
||||
testMiniExtend(t, p, "foo", false, "foo[*]")
|
||||
testMiniExtend(t, p, "foo", true, "foo [*]")
|
||||
testMiniExtend(t, p, "foo bar", true, "'foo bar' [*]")
|
||||
testMiniExtend(t, p, "foo'bar", true, `$'foo\'bar' [*]`)
|
||||
|
||||
p, err = ParseCompPoint("ls fmore", 4)
|
||||
if err != nil {
|
||||
t.Fatalf("error: %v", err)
|
||||
}
|
||||
p = ParseCompPoint(parseToSP("ls f[*]more"))
|
||||
testMiniExtend(t, p, "foo", false, "foo[*]more")
|
||||
testMiniExtend(t, p, "foo bar", false, `'foo bar[*]more`)
|
||||
testMiniExtend(t, p, "foo bar", true, `'foo bar[*]more`)
|
||||
@ -72,10 +62,7 @@ func Test2(t *testing.T) {
|
||||
}
|
||||
|
||||
func testParseRT(t *testing.T, origSP StrWithPos) {
|
||||
p, err := ParseCompPoint(origSP.Str, origSP.Pos)
|
||||
if err != nil {
|
||||
t.Fatalf("error: %v", err)
|
||||
}
|
||||
p := ParseCompPoint(origSP)
|
||||
newSP := StrWithPos{Str: p.getOrigStr(), Pos: p.getOrigPos()}
|
||||
if origSP != newSP {
|
||||
t.Fatalf("not equal: [%s] != [%s]", origSP, newSP)
|
||||
@ -92,10 +79,7 @@ func Test3(t *testing.T) {
|
||||
func testExtend(t *testing.T, origStr string, compStrs []string, expectedStr string) {
|
||||
origSP := parseToSP(origStr)
|
||||
expectedSP := parseToSP(expectedStr)
|
||||
p, err := ParseCompPoint(origSP.Str, origSP.Pos)
|
||||
if err != nil {
|
||||
t.Fatalf("error: %v", err)
|
||||
}
|
||||
p := ParseCompPoint(origSP)
|
||||
crtn := compsToCompReturn(compStrs, false)
|
||||
newSP := p.FullyExtend(crtn)
|
||||
if newSP != expectedSP {
|
||||
|
@ -13,10 +13,10 @@ import (
|
||||
|
||||
var globalLock = &sync.Mutex{}
|
||||
var simpleCompMap = map[string]SimpleCompGenFnType{
|
||||
"file": simpleCompFile,
|
||||
"directory": simpleCompDir,
|
||||
"variable": simpleCompVar,
|
||||
"command": simpleCompCommand,
|
||||
CGTypeCommand: simpleCompCommand,
|
||||
CGTypeFile: simpleCompFile,
|
||||
CGTypeDir: simpleCompDir,
|
||||
CGTypeVariable: simpleCompVar,
|
||||
}
|
||||
|
||||
type SimpleCompGenFnType = func(ctx context.Context, prefix string, compCtx CompContext, args []interface{}) (*CompReturn, error)
|
||||
@ -79,17 +79,17 @@ func doCompGen(ctx context.Context, prefix string, compType string, compCtx Comp
|
||||
}
|
||||
|
||||
func simpleCompFile(ctx context.Context, prefix string, compCtx CompContext, args []interface{}) (*CompReturn, error) {
|
||||
return doCompGen(ctx, prefix, "file", compCtx)
|
||||
return doCompGen(ctx, prefix, CGTypeFile, compCtx)
|
||||
}
|
||||
|
||||
func simpleCompDir(ctx context.Context, prefix string, compCtx CompContext, args []interface{}) (*CompReturn, error) {
|
||||
return doCompGen(ctx, prefix, "directory", compCtx)
|
||||
return doCompGen(ctx, prefix, CGTypeDir, compCtx)
|
||||
}
|
||||
|
||||
func simpleCompVar(ctx context.Context, prefix string, compCtx CompContext, args []interface{}) (*CompReturn, error) {
|
||||
return doCompGen(ctx, prefix, "variable", compCtx)
|
||||
return doCompGen(ctx, prefix, CGTypeVariable, compCtx)
|
||||
}
|
||||
|
||||
func simpleCompCommand(ctx context.Context, prefix string, compCtx CompContext, args []interface{}) (*CompReturn, error) {
|
||||
return doCompGen(ctx, prefix, "command", compCtx)
|
||||
return doCompGen(ctx, prefix, CGTypeCommand, compCtx)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user