Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions bindings/go/scip/testutil/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func FormatSnapshots(
var documentErrors error
for _, document := range index.Documents {
sourceFilePath := filepath.Join(localSourcesRoot, document.RelativePath)
snapshot, err := FormatSnapshot(document, index, commentSyntax, symbolFormatter, sourceFilePath)
snapshot, err := FormatSnapshot(document, commentSyntax, symbolFormatter, sourceFilePath)
err = symbolFormatter.OnError(err)
if err != nil {
documentErrors = errors.CombineErrors(
Expand All @@ -64,7 +64,6 @@ func FormatSnapshots(
// that is suitable for snapshot testing.
func FormatSnapshot(
document *scip.Document,
index *scip.Index,
commentSyntax string,
formatter scip.SymbolFormatter,
sourceFilePath string,
Expand Down Expand Up @@ -154,29 +153,42 @@ func FormatSnapshot(
}
}

for _, diagnostic := range occ.Diagnostics {
writeDiagnostic(&b, prefix, diagnostic)
}

b.WriteString("\n")
i++
}
}
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)
func writeMultiline(b *strings.Builder, prefix string, paragraph string) {
for _, s := range strings.Split(paragraph, "\n") {
b.WriteString(prefix)
b.WriteString("> ")
b.WriteString(s)
}
}

func writeDocumentation(b *strings.Builder, documentation string, prefix string, override bool) {
b.WriteString(prefix)
if override {
b.WriteString("override_")
}
b.WriteString("documentation ")
b.WriteString("documentation")

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

func writeDiagnostic(b *strings.Builder, prefix string, diagnostic *scip.Diagnostic) {
b.WriteString(prefix)
b.WriteString("diagnostic ")
b.WriteString(diagnostic.Severity.String())
b.WriteRune(':')

writeMultiline(b, prefix, diagnostic.Message)
}

// isRangeLess compares two SCIP ranges (which are encoded as []int32).
Expand Down
9 changes: 9 additions & 0 deletions cmd/scip/tests/reprolang/bindings/go/repro/scip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ import (
)

func (i *identifier) occurrence(roles scip.SymbolRole) *scip.Occurrence {
var diagnostics []*scip.Diagnostic
if strings.HasPrefix(i.value, "deprecated") {
diagnostics = []*scip.Diagnostic{{
Severity: scip.Severity_Warning,
Message: "deprecated identifier",
}}
}

return &scip.Occurrence{
Range: i.position.SCIPRange(),
Symbol: i.symbol,
SymbolRoles: int32(roles),
Diagnostics: diagnostics,
}
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/scip/tests/snapshots/input/diagnostics/diagnostics.repro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
definition deprecatedMethod.
reference deprecatedMethod.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Test cyclic references between files.
definition hello().
# ^^^^^^^^ definition cycle1.repro/hello().
# documentation signature of hello().
# documentation
# > signature of hello().
reference hello().
# ^^^^^^^^ reference cycle1.repro/hello().
reference hello2().
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Test cyclic references between files.
definition hello2().
# ^^^^^^^^^ definition cycle2.repro/hello2().
# documentation signature of hello2().
# documentation
# > signature of hello2().
reference hello().
# ^^^^^^^^ reference cycle1.repro/hello().
reference hello2().
Expand Down
11 changes: 11 additions & 0 deletions cmd/scip/tests/snapshots/output/diagnostics/diagnostics.repro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
definition deprecatedMethod.
# ^^^^^^^^^^^^^^^^^ definition diagnostics.repro/deprecatedMethod.
# documentation
# > signature of deprecatedMethod.
# diagnostic Warning:
# > deprecated identifier
reference deprecatedMethod.
# ^^^^^^^^^^^^^^^^^ reference diagnostics.repro/deprecatedMethod.
# diagnostic Warning:
# > deprecated identifier

21 changes: 21 additions & 0 deletions cmd/scip/tests/snapshots/output/diagnostics/dump.lsif
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{"id":1,"version":"0.4.3","projectRoot":"file:/root","positionEncoding":"utf-8","toolInfo":{"name":"reprolang","version":"1.0.0"},"type":"vertex","label":"metaData"}
{"id":2,"type":"vertex","label":"definitionResult"}
{"id":3,"type":"vertex","label":"resultSet"}
{"id":4,"type":"vertex","label":"referenceResult"}
{"id":5,"type":"vertex","label":"hoverResult","result":{"contents":{"kind":"markdown","value":"signature of deprecatedMethod."}}}
{"id":6,"type":"edge","label":"textDocument/definition","inV":2,"outV":3}
{"id":7,"type":"edge","label":"textDocument/references","inV":4,"outV":3}
{"id":8,"type":"edge","label":"textDocument/hover","inV":5,"outV":3}
{"id":9,"type":"vertex","label":"moniker","identifier":"reprolang repro_manager diagnostics 1.0.0 diagnostics.repro/deprecatedMethod.","kind":"export","scheme":"reprolang"}
{"id":10,"type":"edge","label":"moniker","inV":9,"outV":3}
{"id":11,"name":"diagnostics","version":"1.0.0","manager":"repro_manager","type":"vertex","label":"packageInformation"}
{"id":12,"type":"edge","label":"packageInformation","inV":11,"outV":9}
{"id":13,"type":"vertex","label":"document","uri":"file:/root/diagnostics.repro"}
{"id":14,"type":"vertex","label":"range","start":{"line":0,"character":11},"end":{"line":0,"character":28}}
{"id":15,"type":"edge","label":"next","inV":3,"outV":14}
{"id":16,"type":"edge","label":"item","inVs":[14],"outV":2,"document":13}
{"id":17,"type":"edge","label":"item","inVs":[14],"outV":4,"document":13}
{"id":18,"type":"vertex","label":"range","start":{"line":1,"character":10},"end":{"line":1,"character":27}}
{"id":19,"type":"edge","label":"next","inV":3,"outV":18}
{"id":20,"type":"edge","label":"item","inVs":[18],"outV":4,"document":13}
{"id":21,"type":"edge","label":"contains","inVs":[14,18],"outV":13}
6 changes: 4 additions & 2 deletions cmd/scip/tests/snapshots/output/duplicates/duplicate.repro
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
definition readFileSync.
# ^^^^^^^^^^^^^ definition duplicate.repro/readFileSync.
# documentation signature of readFileSync.
# documentation
# > signature of readFileSync.
definition readFileSync.
# ^^^^^^^^^^^^^ definition duplicate.repro/readFileSync.
# documentation signature of readFileSync.
# documentation
# > signature of readFileSync.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# ^^^^ forward_definition forward_def.repro/abc#
definition abc#
# ^^^^ definition forward_def.repro/abc#
# documentation signature of abc#
# documentation
# > signature of abc#
reference abc#
# ^^^^ reference forward_def.repro/abc#

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Test how to implement a symbol from an external workspace.
definition bird# implements global implementation animal.repro/animal#
# ^^^^^ definition bird.repro/bird#
# documentation signature of bird#
# documentation
# > signature of bird#
# relationship implementation animal.repro/animal# implementation
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference implementation animal.repro/animal#

9 changes: 6 additions & 3 deletions cmd/scip/tests/snapshots/output/implementation/animal.repro
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Test how to implement a symbol within the same workspace.
definition animal#
# ^^^^^^^ definition animal.repro/animal#
# documentation signature of animal#
# documentation
# > signature of animal#
definition dog# implements animal#
# ^^^^ definition animal.repro/dog#
# documentation signature of dog#
# documentation
# > signature of dog#
# relationship animal.repro/animal# implementation
# ^^^^^^^ reference animal.repro/animal#
definition cat# implements animal#
# ^^^^ definition animal.repro/cat#
# documentation signature of cat#
# documentation
# > signature of cat#
# relationship animal.repro/animal# implementation
# ^^^^^^^ reference animal.repro/animal#

6 changes: 4 additions & 2 deletions cmd/scip/tests/snapshots/output/local-document/local1.repro
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# docstring: local is a local method
definition localExample
# ^^^^^^^^^^^^ definition local Example
# documentation signature of localExample
# documentation : local is a local method
# documentation
# > signature of localExample
# documentation
# > : local is a local method
reference localExample
# ^^^^^^^^^^^^ reference local Example

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
definition M_f.
# ^^^^ definition defined_by.repro/M_f.
# documentation signature of M_f.
# documentation
# > signature of M_f.

definition C1_f.
# ^^^^^ definition defined_by.repro/C1_f.
# documentation signature of C1_f.
# documentation
# > signature of C1_f.

reference C2_f.
# ^^^^^ reference defined_by.repro/C1_f.
Expand Down
12 changes: 8 additions & 4 deletions cmd/scip/tests/snapshots/output/relationships/mixed.repro
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
definition local1
# ^^^^^^ definition local 1
# documentation signature of local1
# documentation
# > signature of local1
definition local2
# ^^^^^^ definition local 2
# documentation signature of local2
# documentation
# > signature of local2
definition local3
# ^^^^^^ definition local 3
# documentation signature of local3
# documentation
# > signature of local3
definition local4 implements local1 references local2 type_defines local3
# ^^^^^^ definition local 4
# documentation signature of local4
# documentation
# > signature of local4
# relationship local 1 implementation
# relationship local 2 reference
# relationship local 3 type_definition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
definition local1
# ^^^^^^ definition local 1
# documentation signature of local1
# documentation
# > signature of local1
definition local2 references local1
# ^^^^^^ definition local 2
# documentation signature of local2
# documentation
# > signature of local2
# relationship local 1 reference
# ^^^^^^ reference local 1

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
definition local1
# ^^^^^^ definition local 1
# documentation signature of local1
# documentation
# > signature of local1
definition local2 type_defines local1
# ^^^^^^ definition local 2
# documentation signature of local2
# documentation
# > signature of local2
# relationship local 1 type_definition
# ^^^^^^ reference local 1