Skip to content

Commit a0147a7

Browse files
jtibshiranimatthewnitschke-wkvarungandhi-src
authored
Include diagnostics in snapshot output (#226)
Co-authored-by: Matthew Nitschke <matthew.nitschke@workiva.com> Co-authored-by: Varun Gandhi <varun.gandhi@sourcegraph.com>
1 parent 67e7820 commit a0147a7

File tree

16 files changed

+109
-33
lines changed

16 files changed

+109
-33
lines changed

bindings/go/scip/testutil/format.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func FormatSnapshots(
4040
var documentErrors error
4141
for _, document := range index.Documents {
4242
sourceFilePath := filepath.Join(localSourcesRoot, document.RelativePath)
43-
snapshot, err := FormatSnapshot(document, index, commentSyntax, symbolFormatter, sourceFilePath)
43+
snapshot, err := FormatSnapshot(document, commentSyntax, symbolFormatter, sourceFilePath)
4444
err = symbolFormatter.OnError(err)
4545
if err != nil {
4646
documentErrors = errors.CombineErrors(
@@ -64,7 +64,6 @@ func FormatSnapshots(
6464
// that is suitable for snapshot testing.
6565
func FormatSnapshot(
6666
document *scip.Document,
67-
index *scip.Index,
6867
commentSyntax string,
6968
formatter scip.SymbolFormatter,
7069
sourceFilePath string,
@@ -154,29 +153,42 @@ func FormatSnapshot(
154153
}
155154
}
156155

156+
for _, diagnostic := range occ.Diagnostics {
157+
writeDiagnostic(&b, prefix, diagnostic)
158+
}
159+
157160
b.WriteString("\n")
158161
i++
159162
}
160163
}
161164
return b.String(), formattingError
162165
}
163166

164-
func writeDocumentation(b *strings.Builder, documentation string, prefix string, override bool) {
165-
// At least get the first line of documentation if there is leading whitespace
166-
documentation = strings.TrimSpace(documentation)
167+
func writeMultiline(b *strings.Builder, prefix string, paragraph string) {
168+
for _, s := range strings.Split(paragraph, "\n") {
169+
b.WriteString(prefix)
170+
b.WriteString("> ")
171+
b.WriteString(s)
172+
}
173+
}
167174

175+
func writeDocumentation(b *strings.Builder, documentation string, prefix string, override bool) {
168176
b.WriteString(prefix)
169177
if override {
170178
b.WriteString("override_")
171179
}
172-
b.WriteString("documentation ")
180+
b.WriteString("documentation")
173181

174-
truncatedDocumentation := documentation
175-
newlineIndex := strings.Index(documentation, "\n")
176-
if newlineIndex >= 0 {
177-
truncatedDocumentation = documentation[0:newlineIndex]
178-
}
179-
b.WriteString(truncatedDocumentation)
182+
writeMultiline(b, prefix, documentation)
183+
}
184+
185+
func writeDiagnostic(b *strings.Builder, prefix string, diagnostic *scip.Diagnostic) {
186+
b.WriteString(prefix)
187+
b.WriteString("diagnostic ")
188+
b.WriteString(diagnostic.Severity.String())
189+
b.WriteRune(':')
190+
191+
writeMultiline(b, prefix, diagnostic.Message)
180192
}
181193

182194
// isRangeLess compares two SCIP ranges (which are encoded as []int32).

cmd/scip/tests/reprolang/bindings/go/repro/scip.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@ import (
88
)
99

1010
func (i *identifier) occurrence(roles scip.SymbolRole) *scip.Occurrence {
11+
var diagnostics []*scip.Diagnostic
12+
if strings.HasPrefix(i.value, "deprecated") {
13+
diagnostics = []*scip.Diagnostic{{
14+
Severity: scip.Severity_Warning,
15+
Message: "deprecated identifier",
16+
}}
17+
}
18+
1119
return &scip.Occurrence{
1220
Range: i.position.SCIPRange(),
1321
Symbol: i.symbol,
1422
SymbolRoles: int32(roles),
23+
Diagnostics: diagnostics,
1524
}
1625
}
1726

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
definition deprecatedMethod.
2+
reference deprecatedMethod.

cmd/scip/tests/snapshots/output/cyclic-reference/cycle1.repro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Test cyclic references between files.
22
definition hello().
33
# ^^^^^^^^ definition cycle1.repro/hello().
4-
# documentation signature of hello().
4+
# documentation
5+
# > signature of hello().
56
reference hello().
67
# ^^^^^^^^ reference cycle1.repro/hello().
78
reference hello2().

cmd/scip/tests/snapshots/output/cyclic-reference/cycle2.repro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Test cyclic references between files.
22
definition hello2().
33
# ^^^^^^^^^ definition cycle2.repro/hello2().
4-
# documentation signature of hello2().
4+
# documentation
5+
# > signature of hello2().
56
reference hello().
67
# ^^^^^^^^ reference cycle1.repro/hello().
78
reference hello2().
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
definition deprecatedMethod.
2+
# ^^^^^^^^^^^^^^^^^ definition diagnostics.repro/deprecatedMethod.
3+
# documentation
4+
# > signature of deprecatedMethod.
5+
# diagnostic Warning:
6+
# > deprecated identifier
7+
reference deprecatedMethod.
8+
# ^^^^^^^^^^^^^^^^^ reference diagnostics.repro/deprecatedMethod.
9+
# diagnostic Warning:
10+
# > deprecated identifier
11+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{"id":1,"version":"0.4.3","projectRoot":"file:/root","positionEncoding":"utf-8","toolInfo":{"name":"reprolang","version":"1.0.0"},"type":"vertex","label":"metaData"}
2+
{"id":2,"type":"vertex","label":"definitionResult"}
3+
{"id":3,"type":"vertex","label":"resultSet"}
4+
{"id":4,"type":"vertex","label":"referenceResult"}
5+
{"id":5,"type":"vertex","label":"hoverResult","result":{"contents":{"kind":"markdown","value":"signature of deprecatedMethod."}}}
6+
{"id":6,"type":"edge","label":"textDocument/definition","inV":2,"outV":3}
7+
{"id":7,"type":"edge","label":"textDocument/references","inV":4,"outV":3}
8+
{"id":8,"type":"edge","label":"textDocument/hover","inV":5,"outV":3}
9+
{"id":9,"type":"vertex","label":"moniker","identifier":"reprolang repro_manager diagnostics 1.0.0 diagnostics.repro/deprecatedMethod.","kind":"export","scheme":"reprolang"}
10+
{"id":10,"type":"edge","label":"moniker","inV":9,"outV":3}
11+
{"id":11,"name":"diagnostics","version":"1.0.0","manager":"repro_manager","type":"vertex","label":"packageInformation"}
12+
{"id":12,"type":"edge","label":"packageInformation","inV":11,"outV":9}
13+
{"id":13,"type":"vertex","label":"document","uri":"file:/root/diagnostics.repro"}
14+
{"id":14,"type":"vertex","label":"range","start":{"line":0,"character":11},"end":{"line":0,"character":28}}
15+
{"id":15,"type":"edge","label":"next","inV":3,"outV":14}
16+
{"id":16,"type":"edge","label":"item","inVs":[14],"outV":2,"document":13}
17+
{"id":17,"type":"edge","label":"item","inVs":[14],"outV":4,"document":13}
18+
{"id":18,"type":"vertex","label":"range","start":{"line":1,"character":10},"end":{"line":1,"character":27}}
19+
{"id":19,"type":"edge","label":"next","inV":3,"outV":18}
20+
{"id":20,"type":"edge","label":"item","inVs":[18],"outV":4,"document":13}
21+
{"id":21,"type":"edge","label":"contains","inVs":[14,18],"outV":13}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
definition readFileSync.
22
# ^^^^^^^^^^^^^ definition duplicate.repro/readFileSync.
3-
# documentation signature of readFileSync.
3+
# documentation
4+
# > signature of readFileSync.
45
definition readFileSync.
56
# ^^^^^^^^^^^^^ definition duplicate.repro/readFileSync.
6-
# documentation signature of readFileSync.
7+
# documentation
8+
# > signature of readFileSync.
79

cmd/scip/tests/snapshots/output/forward-def/forward_def.repro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# ^^^^ forward_definition forward_def.repro/abc#
33
definition abc#
44
# ^^^^ definition forward_def.repro/abc#
5-
# documentation signature of abc#
5+
# documentation
6+
# > signature of abc#
67
reference abc#
78
# ^^^^ reference forward_def.repro/abc#
89

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Test how to implement a symbol from an external workspace.
22
definition bird# implements global implementation animal.repro/animal#
33
# ^^^^^ definition bird.repro/bird#
4-
# documentation signature of bird#
4+
# documentation
5+
# > signature of bird#
56
# relationship implementation animal.repro/animal# implementation
67
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference implementation animal.repro/animal#
78

0 commit comments

Comments
 (0)