plantuml debug

This commit is contained in:
mr
2026-03-18 09:41:09 +01:00
parent 4eb112bee3
commit d4ac398cdb
2 changed files with 56 additions and 26 deletions

View File

@@ -15,31 +15,32 @@ import (
// PlantUML export
// ---------------------------------------------------------------------------
// plantUMLProcedures defines the !procedure blocks for each resource type.
// These make the output valid, renderable PlantUML while remaining parseable
// by ExtractFromPlantUML (which already skips lines containing "!procedure").
// plantUMLProcedures defines !procedure blocks for each resource type.
// Parameters use the $var/$name convention of PlantUML preprocessor v2.
// Calls are written WITHOUT inline comments (comment on the following line)
// to avoid the "assumed sequence diagram" syntax error.
const plantUMLProcedures = `!procedure Processing($var, $name)
component "$name" as $var <<Processing>>
component "$name" as $var <<Processing>>
!endprocedure
!procedure Data($var, $name)
file "$name" as $var <<Data>>
file "$name" as $var <<Data>>
!endprocedure
!procedure Storage($var, $name)
database "$name" as $var <<Storage>>
database "$name" as $var <<Storage>>
!endprocedure
!procedure ComputeUnit($var, $name)
node "$name" as $var <<ComputeUnit>>
node "$name" as $var <<ComputeUnit>>
!endprocedure
!procedure WorkflowEvent($var, $name)
usecase "$name" as $var <<WorkflowEvent>>
usecase "$name" as $var <<WorkflowEvent>>
!endprocedure
!procedure Workflow($var, $name)
frame "$name" as $var <<Workflow>>
frame "$name" as $var <<Workflow>>
!endprocedure
`
@@ -72,11 +73,10 @@ func (w *Workflow) ToPlantUML() string {
if src == "" || dst == "" {
continue
}
line := fmt.Sprintf("%s --> %s", src, dst)
sb.WriteString(fmt.Sprintf("%s --> %s\n", src, dst))
if comment := plantUMLLinkComment(link); comment != "" {
line += " ' " + comment
sb.WriteString("' " + comment + "\n")
}
sb.WriteString(line + "\n")
}
sb.WriteString("\n@enduml\n")
@@ -146,11 +146,13 @@ func plantUMLItemLine(varName string, item graph.GraphItem) string {
}
func plantUMLResourceLine(macro, varName string, res resources.ResourceInterface) string {
line := fmt.Sprintf("%s(%s, \"%s\")", macro, varName, res.GetName())
decl := fmt.Sprintf("%s(%s, \"%s\")", macro, varName, res.GetName())
if comment := plantUMLResourceComment(res); comment != "" {
line += " ' " + comment
// Comment on the line AFTER the declaration. ExtractFromPlantUML uses
// look-ahead to merge it back. No inline comment = no !procedure conflict.
return decl + "\n' " + comment
}
return line
return decl
}
// plantUMLResourceComment merges resource-level fields with the first instance

View File

@@ -149,15 +149,46 @@ func (d *Workflow) ExtractFromPlantUML(plantUML multipart.File, request *tools.A
},
}
graphVarName := map[string]graph.GraphItem{}
scanner := bufio.NewScanner(plantUML)
// Collect all lines first to support look-ahead (comment on the line after
// the declaration, as produced by ToPlantUML).
scanner := bufio.NewScanner(plantUML)
var lines []string
for scanner.Scan() {
line := scanner.Text()
lines = append(lines, scanner.Text())
}
if err := scanner.Err(); err != nil {
return d, err
}
for i, line := range lines {
trimmed := strings.TrimSpace(line)
// Skip pure comment lines and PlantUML directives — they must never be
// parsed as resource declarations or links. Without this guard, a comment
// like "' source: http://my-server.com" would match the "-" link check.
if strings.HasPrefix(trimmed, "'") ||
strings.HasPrefix(trimmed, "!") ||
strings.HasPrefix(trimmed, "@") ||
trimmed == "" {
continue
}
// Build the parse line: if the current line has no inline comment and the
// next line is a pure comment, append it so parsers receive one combined line.
// Also handles the legacy inline-comment format unchanged.
parseLine := line
if !strings.Contains(line, "'") && i+1 < len(lines) {
if next := strings.TrimSpace(lines[i+1]); strings.HasPrefix(next, "'") {
parseLine = line + " " + next
}
}
for n, new := range resourceCatalog {
if strings.Contains(line, n+"(") && !strings.Contains(line, "!procedure") { // should exclude declaration of type.
if strings.Contains(line, n+"(") && !strings.Contains(line, "!procedure") && !strings.Contains(line, "!define") { // exclude macro declarations
newRes := new()
newRes.SetID(uuid.New().String())
varName, graphItem, err := d.extractResourcePlantUML(line, newRes, n, request.PeerID)
varName, graphItem, err := d.extractResourcePlantUML(parseLine, newRes, n, request.PeerID)
fmt.Println(varName, graphItem, err)
if err != nil {
return d, err
@@ -167,25 +198,25 @@ func (d *Workflow) ExtractFromPlantUML(plantUML multipart.File, request *tools.A
}
continue
} else if strings.Contains(line, "-->") {
err := d.extractLink(line, graphVarName, "-->", false)
err := d.extractLink(parseLine, graphVarName, "-->", false)
if err != nil {
fmt.Println(err)
continue
}
} else if strings.Contains(line, "<--") {
err := d.extractLink(line, graphVarName, "<--", true)
err := d.extractLink(parseLine, graphVarName, "<--", true)
if err != nil {
fmt.Println(err)
continue
}
} else if strings.Contains(line, "--") {
err := d.extractLink(line, graphVarName, "--", false)
err := d.extractLink(parseLine, graphVarName, "--", false)
if err != nil {
fmt.Println(err)
continue
}
} else if strings.Contains(line, "-") {
err := d.extractLink(line, graphVarName, "-", false)
err := d.extractLink(parseLine, graphVarName, "-", false)
if err != nil {
fmt.Println(err)
continue
@@ -193,9 +224,6 @@ func (d *Workflow) ExtractFromPlantUML(plantUML multipart.File, request *tools.A
}
}
}
if err := scanner.Err(); err != nil {
return d, err
}
d.generateResource(d.GetResources(tools.DATA_RESOURCE), request)
d.generateResource(d.GetResources(tools.PROCESSING_RESOURCE), request)
d.generateResource(d.GetResources(tools.STORAGE_RESOURCE), request)