Skip to content

Commit

Permalink
Added support for autocompleting CREATE queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jgryko5 authored and nineinchnick committed Aug 2, 2021
1 parent 8ffb02d commit ae8d47e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions drivers/completer/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ func (c completer) complete(previousWords []string, text []rune) [][]rune {
}
/* XXX: implement tab completion for DELETE ... USING */

/* Complete CREATE */
if tailMatches(IGNORE_CASE, previousWords, "CREATE") || tailMatches(IGNORE_CASE, previousWords, "CREATE", "TEMP|TEMPORARY") {
return completeFromList(text, "DATABASE", "SEQUENCE", "TABLE", "VIEW", "TEMPORARY")
}
if tailMatches(IGNORE_CASE, previousWords, "CREATE", "TABLE", "*") || tailMatches(IGNORE_CASE, previousWords, "CREATE", "TEMP|TEMPORARY", "TABLE", "*") {
return completeFromList(text, "(")
}
/* INSERT --- can be inside EXPLAIN, RULE, etc */
/* Complete INSERT with "INTO" */
if tailMatches(IGNORE_CASE, previousWords, "INSERT") {
Expand Down
22 changes: 22 additions & 0 deletions drivers/completer/completer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,28 @@ func TestCompleter(t *testing.T) {
[]string{},
2,
},
{
"type on create",
"CREATE ",
7,
[]string{
"DATABASE",
"TABLE",
"SEQUENCE",
"VIEW",
"TEMPORARY",
},
0,
},
{
"brackets on create table",
"CREATE TABLE p ",
15,
[]string{
"(",
},
0,
},
}

completer := NewDefaultCompleter(WithReader(mockReader{}), WithConnStrings([]string{"pg://"}))
Expand Down

0 comments on commit ae8d47e

Please sign in to comment.