Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ func (c *Completer) parseGetOperation() ([]prompt.Suggest, error) {
docPath := normalizeFirestorePath(c.curToken.Literal)
parts := strings.Split(docPath, "/")
if len(parts)%2 == 0 {
return []prompt.Suggest{}, nil
// complete doc path, suggest SELECT
return []prompt.Suggest{selectSuggestion}, nil
}
var baseDoc string
if len(parts) == 1 {
Expand All @@ -258,6 +259,35 @@ func (c *Completer) parseGetOperation() ([]prompt.Suggest, error) {
return prompt.FilterHasPrefix(suggestions, c.curToken.Literal, false), nil
}

c.nextToken()

if c.curTokenIs(EOF) {
return []prompt.Suggest{selectSuggestion}, nil
}

if c.curTokenIs(IDENT) {
return prompt.FilterHasPrefix([]prompt.Suggest{selectSuggestion}, c.curToken.Literal, true), nil
}

if c.curTokenIs(SELECT) {
c.nextToken()

if c.curTokenIs(EOF) {
return []prompt.Suggest{}, nil
}

// skip select fields
for !c.curTokenIs(EOF) {
if c.curTokenIs(COMMA) {
c.nextToken()
} else {
c.nextToken()
}
}

return []prompt.Suggest{}, nil
}

return []prompt.Suggest{}, nil
}

Expand Down
20 changes: 20 additions & 0 deletions completer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ func TestCompleter(t *testing.T) {
input: `GET user/1/p`,
want: []prompt.Suggest{newCollectionSuggestion("user/1", "posts")},
},
{
desc: "get with doc path suggest select",
input: `GET user/1 `,
want: []prompt.Suggest{selectSuggestion},
},
{
desc: "middle of get select",
input: `GET user/1 S`,
want: []prompt.Suggest{selectSuggestion},
},
{
desc: "get with select and no field",
input: `GET user/1 SELECT `,
want: []prompt.Suggest{},
},
{
desc: "get with select and field",
input: `GET user/1 SELECT name`,
want: []prompt.Suggest{},
},
{
desc: "middle of count",
input: `CO`,
Expand Down
Loading