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

add alter and drop autocomplete #429

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions drivers/completer/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ func (c completer) complete(previousWords []string, text []rune) [][]rune {
if TailMatches(IGNORE_CASE, previousWords, "CREATE", "TABLE", "*") || TailMatches(IGNORE_CASE, previousWords, "CREATE", "TEMP|TEMPORARY", "TABLE", "*") {
return CompleteFromList(text, "(")
}

/* Complete ALTER */
if TailMatches(IGNORE_CASE, previousWords, "ALTER") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start, but would be great if this also completed table names. See https://github.com/postgres/postgres/blob/master/src/bin/psql/tab-complete.c#L1814 for reference, and also check a few lines below how we already do this for INSERT INTO.

Completing other objects like index names would also be great, but we can stick to tables in this PR.

return CompleteFromList(text, "DATABASE", "FUNCTION", "INDEX", "SCHEMA", "SEQUENCE", "TABLE", "TRIGGER", "USER", "VIEW")
}

/* Complete DROP */
if TailMatches(IGNORE_CASE, previousWords, "DROP") {
return CompleteFromList(text, "CONSTRAINT", "COLUMN", "DATABASE", "FUNCTION", "INDEX", "SCHEMA", "SEQUENCE", "TABLE", "TRIGGER", "USER", "VIEW")
}

/* INSERT --- can be inside EXPLAIN, RULE, etc */
/* Complete INSERT with "INTO" */
if TailMatches(IGNORE_CASE, previousWords, "INSERT") {
Expand Down
36 changes: 36 additions & 0 deletions drivers/completer/completer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,42 @@ func TestCompleter(t *testing.T) {
},
0,
},
{
"type on alter",
"ALTER ",
6,
[]string{
"DATABASE",
"FUNCTION",
"INDEX",
"SCHEMA",
"SEQUENCE",
"TABLE",
"TRIGGER",
"USER",
"VIEW",
},
0,
},
{
"type on drop",
"DROP ",
5,
[]string{
"CONSTRAINT",
"COLUMN",
"DATABASE",
"FUNCTION",
"INDEX",
"SCHEMA",
"SEQUENCE",
"TABLE",
"TRIGGER",
"USER",
"VIEW",
},
0,
},
{
"TABLE Selectables",
"TABLE ",
Expand Down