Skip to content

Commit 73e70b0

Browse files
committed
fix: DESCRIBE CONSTANT emits COMMENT field
Bug #25: Constants created with COMMENT 'text' were stored correctly but DESCRIBE CONSTANT did not emit the COMMENT line. Also fixed the CREATE CONSTANT handler to store stmt.Comment into the model's Documentation field.
1 parent 6764cda commit 73e70b0

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

mdl/executor/cmd_constants.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,6 @@ func (e *Executor) describeConstant(name ast.QualifiedName) error {
141141

142142
// outputConstantMDL outputs a constant definition in MDL format.
143143
func (e *Executor) outputConstantMDL(c *model.Constant, moduleName string) error {
144-
// Output documentation if present
145-
if c.Documentation != "" {
146-
lines := strings.Split(c.Documentation, "\n")
147-
fmt.Fprintln(e.output, "/**")
148-
for _, line := range lines {
149-
fmt.Fprintf(e.output, " * %s\n", line)
150-
}
151-
fmt.Fprintln(e.output, " */")
152-
}
153-
154144
// Format default value based on type
155145
defaultValueStr := formatDefaultValue(c.Type, c.DefaultValue)
156146

@@ -159,6 +149,10 @@ func (e *Executor) outputConstantMDL(c *model.Constant, moduleName string) error
159149
fmt.Fprintf(e.output, " DEFAULT %s", defaultValueStr)
160150

161151
// Add options if present
152+
if c.Documentation != "" {
153+
escaped := strings.ReplaceAll(c.Documentation, "'", "''")
154+
fmt.Fprintf(e.output, "\n COMMENT '%s'", escaped)
155+
}
162156
if c.ExposedToClient {
163157
fmt.Fprintf(e.output, "\n EXPOSED TO CLIENT")
164158
}
@@ -310,8 +304,12 @@ func (e *Executor) createConstant(stmt *ast.CreateConstantStmt) error {
310304
modName := h.GetModuleName(modID)
311305
if strings.EqualFold(modName, stmt.Name.Module) && strings.EqualFold(c.Name, stmt.Name.Name) {
312306
if stmt.CreateOrModify {
313-
// Update existing constant
314-
c.Documentation = stmt.Documentation
307+
// Update existing constant — COMMENT takes precedence over doc-comment
308+
if stmt.Comment != "" {
309+
c.Documentation = stmt.Comment
310+
} else {
311+
c.Documentation = stmt.Documentation
312+
}
315313
c.Type = constType
316314
c.DefaultValue = defaultValue
317315
c.ExposedToClient = stmt.ExposedToClient
@@ -327,10 +325,16 @@ func (e *Executor) createConstant(stmt *ast.CreateConstantStmt) error {
327325
}
328326
}
329327

328+
// COMMENT 'text' takes precedence; fall back to /** */ doc-comment
329+
doc := stmt.Comment
330+
if doc == "" {
331+
doc = stmt.Documentation
332+
}
333+
330334
constant := &model.Constant{
331335
ContainerID: module.ID,
332336
Name: stmt.Name.Name,
333-
Documentation: stmt.Documentation,
337+
Documentation: doc,
334338
Type: constType,
335339
DefaultValue: defaultValue,
336340
ExposedToClient: stmt.ExposedToClient,

0 commit comments

Comments
 (0)