Skip to content

Commit

Permalink
add override documentation to snapshots (#116)
Browse files Browse the repository at this point in the history
* add override documentation

* update override param

* ' ' -> '_'
  • Loading branch information
tjdevries authored Nov 21, 2022
1 parent e2d4e9e commit 1a4eec4
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions bindings/go/scip/testutil/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,21 @@ func FormatSnapshot(
b.WriteRune(' ')
b.WriteString(formatSymbol(occ.Symbol))

prefix := "\n" + commentSyntax + strings.Repeat(" ", int(pos.Start.Character))

hasOverrideDocumentation := len(occ.OverrideDocumentation) > 0
if hasOverrideDocumentation {
documentation := occ.OverrideDocumentation[0]
writeDocumentation(&b, documentation, prefix, true)
}

if info, ok := symtab[occ.Symbol]; ok && isDefinition {
prefix := "\n" + commentSyntax + strings.Repeat(" ", int(pos.Start.Character))
for _, documentation := range info.Documentation {
// At least get the first line of documentation if there is leading whitespace
documentation = strings.TrimSpace(documentation)

b.WriteString(prefix)
b.WriteString("documentation ")
truncatedDocumentation := documentation
newlineIndex := strings.Index(documentation, "\n")
if newlineIndex >= 0 {
truncatedDocumentation = documentation[0:newlineIndex]
}
b.WriteString(truncatedDocumentation)
writeDocumentation(&b, documentation, prefix, false)
}

sort.SliceStable(info.Relationships, func(i, j int) bool {
return info.Relationships[i].Symbol < info.Relationships[j].Symbol
})
Expand All @@ -153,6 +153,24 @@ func FormatSnapshot(
return b.String(), formattingError
}

func writeDocumentation(b *strings.Builder, documentation string, prefix string, override bool) {
// At least get the first line of documentation if there is leading whitespace
documentation = strings.TrimSpace(documentation)

b.WriteString(prefix)
if override {
b.WriteString("override_")
}
b.WriteString("documentation ")

truncatedDocumentation := documentation
newlineIndex := strings.Index(documentation, "\n")
if newlineIndex >= 0 {
truncatedDocumentation = documentation[0:newlineIndex]
}
b.WriteString(truncatedDocumentation)
}

// isRangeLess compares two SCIP ranges (which are encoded as []int32).
func isSCIPRangeLess(a []int32, b []int32) bool {
if a[0] != b[0] { // start line
Expand Down

0 comments on commit 1a4eec4

Please sign in to comment.