Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for autocompleting CREATE queries #286

Merged
merged 2 commits into from
Aug 2, 2021
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
10 changes: 10 additions & 0 deletions drivers/completer/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,16 @@ func (c completer) complete(previousWords []string, text []rune) [][]rune {
}
/* XXX: implement tab completion for DELETE ... USING */

/* Complete CREATE */
if tailMatches(IGNORE_CASE, previousWords, "CREATE") {
return completeFromList(text, "DATABASE", "SEQUENCE", "TABLE", "VIEW", "TEMPORARY")
jgryko5 marked this conversation as resolved.
Show resolved Hide resolved
}
if tailMatches(IGNORE_CASE, previousWords, "CREATE", "TEMP|TEMPORARY") {
return completeFromList(text, "TABLE", "VIEW")
}
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