Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(plsql-lsp): return all columns for no table (#14063)
rebelicefce81ebe903c
diff --git a/backend/plugin/parser/plsql/completion.go b/backend/plugin/parser/plsql/completion.goindex 772ff97f6b..a924d3e764 100644--- a/backend/plugin/parser/plsql/completion.go+++ b/backend/plugin/parser/plsql/completion.go@@ -336,6 +336,38 @@ func (m CompletionMap) insertTables(c *Completer, schemas map[string]bool) {}}+func (m CompletionMap) insertAllColumns(c *Completer) {+ for _, schema := range c.listAllDatabases() {+ if _, exists := c.metadataCache[schema]; !exists {+ _, metadata, err := c.getMetadata(c.ctx, c.instanceID, schema)+ if err != nil || metadata == nil {+ continue+ }+ c.metadataCache[schema] = metadata+ }+ schemaMeta := c.metadataCache[schema].GetSchema("")+ for _, table := range schemaMeta.ListTableNames() {+ tableMeta := schemaMeta.GetTable(table)+ if tableMeta == nil {+ continue+ }+ for _, column := range tableMeta.GetColumns() {+ definition := fmt.Sprintf("%s.%s | %s", schema, table, column.Type)+ if !column.Nullable {+ definition += ", NOT NULL"+ }+ comment := column.UserComment+ m.Insert(base.Candidate{+ Type: base.CandidateTypeColumn,+ Text: c.quotedIdentifierIfNeeded(column.Name),+ Definition: definition,+ Comment: comment,+ })+ }+ }+ }+}+func (m CompletionMap) insertColumns(c *Completer, schemas, tables map[string]bool) {for schema := range schemas {if len(schema) == 0 {@@ -366,7 +398,7 @@ func (m CompletionMap) insertColumns(c *Completer, schemas, tables map[string]bocontinue}for _, column := range tableMeta.GetColumns() {- definition := fmt.Sprintf("%s | %s", table, column.Type)+ definition := fmt.Sprintf("%s.%s | %s", schema, table, column.Type)if !column.Nullable {definition += ", NOT NULL"}@@ -599,6 +631,9 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]}}}+ } else {+ // User didn't specify the table, so we return all columns from all tables.+ columnEntries.insertAllColumns(c)}if len(tables) > 0 {diff --git a/backend/plugin/parser/plsql/test-data/test_completion.yaml b/backend/plugin/parser/plsql/test-data/test_completion.yamlindex 3c68af2ed3..77c52f0954 100644--- a/backend/plugin/parser/plsql/test-data/test_completion.yaml+++ b/backend/plugin/parser/plsql/test-data/test_completion.yaml@@ -118,11 +118,11 @@comment: ""- text: C1type: COLUMN- definition: T2 | int, NOT NULL+ definition: SCHEMA1.T2 | int, NOT NULLcomment: ""- text: C2type: COLUMN- definition: T2 | int, NOT NULL+ definition: SCHEMA1.T2 | int, NOT NULLcomment: ""- text: EIDtype: COLUMN@@ -160,11 +160,11 @@comment: ""- text: C1type: COLUMN- definition: T2 | int, NOT NULL+ definition: SCHEMA1.T2 | int, NOT NULLcomment: ""- text: C2type: COLUMN- definition: T2 | int, NOT NULL+ definition: SCHEMA1.T2 | int, NOT NULLcomment: ""- text: EIDtype: COLUMN@@ -202,7 +202,7 @@comment: ""- text: C1type: COLUMN- definition: T1 | int, NOT NULL+ definition: SCHEMA1.T1 | int, NOT NULLcomment: ""- text: EIDtype: COLUMN@@ -238,7 +238,7 @@comment: ""- text: C1type: COLUMN- definition: T1 | int, NOT NULL+ definition: SCHEMA1.T1 | int, NOT NULLcomment: ""- text: V1type: VIEW@@ -272,7 +272,7 @@comment: ""- text: C1type: COLUMN- definition: T1 | int, NOT NULL+ definition: SCHEMA1.T1 | int, NOT NULLcomment: ""- text: V1type: VIEW@@ -282,43 +282,43 @@want:- text: C1type: COLUMN- definition: T1 | int, NOT NULL+ definition: SCHEMA1.T1 | int, NOT NULLcomment: ""- input: SELECT * from t1 cc1 JOIN t2 on cc1.c1 = t2.|want:- text: C1type: COLUMN- definition: T2 | int, NOT NULL+ definition: SCHEMA1.T2 | int, NOT NULLcomment: ""- text: C2type: COLUMN- definition: T2 | int, NOT NULL+ definition: SCHEMA1.T2 | int, NOT NULLcomment: ""- input: SELECT * from t1 cc1 JOIN t2 on cc1.|want:- text: C1type: COLUMN- definition: T1 | int, NOT NULL+ definition: SCHEMA1.T1 | int, NOT NULLcomment: ""- input: SELECT MAX(cc1.|) FROM t2 cc1want:- text: C1type: COLUMN- definition: T2 | int, NOT NULL+ definition: SCHEMA1.T2 | int, NOT NULLcomment: ""- text: C2type: COLUMN- definition: T2 | int, NOT NULL+ definition: SCHEMA1.T2 | int, NOT NULLcomment: ""- input: SELECT cc1.| FROM t2 cc1want:- text: C1type: COLUMN- definition: T2 | int, NOT NULL+ definition: SCHEMA1.T2 | int, NOT NULLcomment: ""- text: C2type: COLUMN- definition: T2 | int, NOT NULL+ definition: SCHEMA1.T2 | int, NOT NULLcomment: ""- input: SELECT * FROM |want:@@ -374,7 +374,7 @@comment: ""- text: C1type: COLUMN- definition: T1 | int, NOT NULL+ definition: SCHEMA1.T1 | int, NOT NULLcomment: ""- text: V1type: VIEW@@ -404,7 +404,7 @@comment: ""- text: C1type: COLUMN- definition: T1 | int, NOT NULL+ definition: SCHEMA1.T1 | int, NOT NULLcomment: ""- text: V1type: VIEW