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(LSP): display column definition and comments (#9690)
rebelice0f24b14d1ac3
diff --git a/backend/api/lsp/completion.go b/backend/api/lsp/completion.goindex ea58fd70d5..bdfb390abf 100644--- a/backend/api/lsp/completion.go+++ b/backend/api/lsp/completion.go@@ -55,10 +55,11 @@ func (h *Handler) handleTextDocumentCompletion(ctx context.Context, _ *jsonrpc2.var items []lsp.CompletionItemfor _, candidate := range candidates {items = append(items, lsp.CompletionItem{- Label: candidate.Text,- Detail: fmt.Sprintf("<%s>", string(candidate.Type)),- Kind: convertLSPCompletionItemKind(candidate.Type),- SortText: generateSortText(params, candidate),+ Label: candidate.Text,+ Detail: fmt.Sprintf("<%s> %s", string(candidate.Type), candidate.Definition),+ Kind: convertLSPCompletionItemKind(candidate.Type),+ Documentation: candidate.Comment,+ SortText: generateSortText(params, candidate),})}diff --git a/backend/plugin/parser/base/complete.go b/backend/plugin/parser/base/complete.goindex 1d6cdfc4ec..06f5858632 100644--- a/backend/plugin/parser/base/complete.go+++ b/backend/plugin/parser/base/complete.go@@ -31,8 +31,10 @@ const (// Candidate is the candidate for auto-completion.type Candidate struct {- Text string- Type CandidateType+ Text string+ Type CandidateType+ Definition string+ Comment string}func (c Candidate) String() string {diff --git a/backend/plugin/parser/mysql/completion.go b/backend/plugin/parser/mysql/completion.goindex 310e6cf2cb..74d9946468 100644--- a/backend/plugin/parser/mysql/completion.go+++ b/backend/plugin/parser/mysql/completion.go@@ -1091,12 +1091,38 @@ func (m CompletionMap) insertViews(c *Completer, schemas map[string]bool) {}}-func (m CompletionMap) insertColumns(c *Completer, schemas, tables map[string]bool) {- for _, columnName := range c.listColumns(schemas, tables) {- m.Insert(base.Candidate{- Type: base.CandidateTypeColumn,- Text: columnName,- })+func (m CompletionMap) insertColumns(c *Completer, databases, tables map[string]bool) {+ for database := range databases {+ if _, exists := c.metadataCache[database]; !exists {+ metadata, err := c.getMetadata(c.ctx, database)+ if err != nil || metadata == nil {+ continue+ }+ c.metadataCache[database] = metadata+ }++ for table := range tables {+ tableMeta := c.metadataCache[database].GetSchema("").GetTable(table)+ if tableMeta == nil {+ continue+ }+ for _, column := range tableMeta.GetColumns() {+ definition := fmt.Sprintf("%s | %s", table, column.Type)+ if !column.Nullable {+ definition += ", NOT NULL"+ }+ comment := column.UserComment+ if len(column.Classification) != 0 {+ comment = column.Classification + "\n" + column.UserComment+ }+ m.Insert(base.Candidate{+ Type: base.CandidateTypeColumn,+ Text: column.Name,+ Definition: definition,+ Comment: comment,+ })+ }+ }}}@@ -1138,28 +1164,3 @@ func (c *Completer) listViews(database string) []string {return c.metadataCache[database].GetSchema("").ListViewNames()}--func (c *Completer) listColumns(databases, tables map[string]bool) []string {- var result []string- for database := range databases {- if _, exists := c.metadataCache[database]; !exists {- metadata, err := c.getMetadata(c.ctx, database)- if err != nil || metadata == nil {- continue- }- c.metadataCache[database] = metadata- }-- for table := range tables {- tableMeta := c.metadataCache[database].GetSchema("").GetTable(table)- if tableMeta == nil {- continue- }- for _, column := range tableMeta.GetColumns() {- result = append(result, column.Name)- }- }- }-- return result-}diff --git a/backend/plugin/parser/mysql/test-data/test_completion.yaml b/backend/plugin/parser/mysql/test-data/test_completion.yamlindex dbced1ae1d..90bb700887 100644--- a/backend/plugin/parser/mysql/test-data/test_completion.yaml+++ b/backend/plugin/parser/mysql/test-data/test_completion.yaml@@ -2,117 +2,215 @@want:- text: dbtype: DATABASE+ definition: ""+ comment: ""- text: t1type: TABLE+ definition: ""+ comment: ""- text: t2type: TABLE+ definition: ""+ comment: ""- text: c1type: COLUMN+ definition: t2 | , NOT NULL+ comment: ""- text: c2type: COLUMN+ definition: t2 | , NOT NULL+ comment: ""- text: eidtype: COLUMN+ definition: ""+ comment: ""- text: xidtype: COLUMN+ definition: ""+ comment: ""- text: v1type: VIEW+ definition: ""+ comment: ""- input: SELECT c1 as eid FROM t1 ORDER BY |want:- text: dbtype: DATABASE+ definition: ""+ comment: ""- text: t1type: TABLE+ definition: ""+ comment: ""- text: t2type: TABLE+ definition: ""+ comment: ""- text: c1type: COLUMN+ definition: t1 | , NOT NULL+ comment: ""- text: eidtype: COLUMN+ definition: ""+ comment: ""- text: v1type: VIEW+ definition: ""+ comment: ""- input: SELECT FROM basdkfjasldf;SELECT | FROM t1want:- text: dbtype: DATABASE+ definition: ""+ comment: ""- text: t1type: TABLE+ definition: ""+ comment: ""- text: t2type: TABLE+ definition: ""+ comment: ""- text: c1type: COLUMN+ definition: t1 | , NOT NULL+ comment: ""- text: v1type: VIEW+ definition: ""+ comment: ""- input: SELECT | FROM (SELECT c1 FROM t1) cc1(cc1c1)want:- text: dbtype: DATABASE+ definition: ""+ comment: ""- text: cc1type: TABLE+ definition: ""+ comment: ""- text: t1type: TABLE+ definition: ""+ comment: ""- text: t2type: TABLE+ definition: ""+ comment: ""- text: cc1c1type: COLUMN+ definition: ""+ comment: ""- text: v1type: VIEW+ definition: ""+ comment: ""- input: SELECT | FROM (SELECT c1 FROM t1) cc1want:- text: dbtype: DATABASE+ definition: ""+ comment: ""- text: cc1type: TABLE+ definition: ""+ comment: ""- text: t1type: TABLE+ definition: ""+ comment: ""- text: t2type: TABLE+ definition: ""+ comment: ""- text: v1type: VIEW+ definition: ""+ comment: ""- input: SELECT * from t1 cc1 JOIN t2 on cc1.|want:- text: c1type: COLUMN+ definition: t1 | , NOT NULL+ comment: ""- input: SELECT MAX(cc1.|) FROM t2 cc1want:- text: c1type: COLUMN+ definition: t2 | , NOT NULL+ comment: ""- text: c2type: COLUMN+ definition: t2 | , NOT NULL+ comment: ""- input: SELECT * FROM |want:- text: dbtype: DATABASE+ definition: ""+ comment: ""- text: t1type: TABLE+ definition: ""+ comment: ""- text: t2type: TABLE+ definition: ""+ comment: ""- text: v1type: VIEW+ definition: ""+ comment: ""- input: SELECT | FROM t1want:- text: dbtype: DATABASE+ definition: ""+ comment: ""- text: t1type: TABLE+ definition: ""+ comment: ""- text: t2type: TABLE+ definition: ""+ comment: ""- text: c1type: COLUMN+ definition: t1 | , NOT NULL+ comment: ""- text: v1type: VIEW+ definition: ""+ comment: ""- input: SELECT | FROM t2 xwant:- text: dbtype: DATABASE+ definition: ""+ comment: ""- text: t1type: TABLE+ definition: ""+ comment: ""- text: t2type: TABLE+ definition: ""+ comment: ""- text: xtype: TABLE+ definition: ""+ comment: ""- text: c1type: COLUMN+ definition: t2 | , NOT NULL+ comment: ""- text: c2type: COLUMN+ definition: t2 | , NOT NULL+ comment: ""- text: v1type: VIEW+ definition: ""+ comment: ""