From a0147a71cdcdb999a5945b41a1e63ff30c994659 Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Mon, 25 Dec 2023 07:37:57 -0800 Subject: [PATCH] Include diagnostics in snapshot output (#226) Co-authored-by: Matthew Nitschke Co-authored-by: Varun Gandhi --- bindings/go/scip/testutil/format.go | 36 ++++++++++++------- .../tests/reprolang/bindings/go/repro/scip.go | 9 +++++ .../input/diagnostics/diagnostics.repro | 2 ++ .../output/cyclic-reference/cycle1.repro | 3 +- .../output/cyclic-reference/cycle2.repro | 3 +- .../output/diagnostics/diagnostics.repro | 11 ++++++ .../snapshots/output/diagnostics/dump.lsif | 21 +++++++++++ .../output/duplicates/duplicate.repro | 6 ++-- .../output/forward-def/forward_def.repro | 3 +- .../implementation-cross-repo/bird.repro | 3 +- .../output/implementation/animal.repro | 9 +++-- .../output/local-document/local1.repro | 6 ++-- .../output/relationships/defined_by.repro | 6 ++-- .../output/relationships/mixed.repro | 12 ++++--- .../output/relationships/references.repro | 6 ++-- .../output/relationships/type_defines.repro | 6 ++-- 16 files changed, 109 insertions(+), 33 deletions(-) create mode 100644 cmd/scip/tests/snapshots/input/diagnostics/diagnostics.repro create mode 100755 cmd/scip/tests/snapshots/output/diagnostics/diagnostics.repro create mode 100755 cmd/scip/tests/snapshots/output/diagnostics/dump.lsif diff --git a/bindings/go/scip/testutil/format.go b/bindings/go/scip/testutil/format.go index c99abb44..9ce4fc75 100644 --- a/bindings/go/scip/testutil/format.go +++ b/bindings/go/scip/testutil/format.go @@ -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( @@ -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, @@ -154,6 +153,10 @@ func FormatSnapshot( } } + for _, diagnostic := range occ.Diagnostics { + writeDiagnostic(&b, prefix, diagnostic) + } + b.WriteString("\n") i++ } @@ -161,22 +164,31 @@ 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) +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). diff --git a/cmd/scip/tests/reprolang/bindings/go/repro/scip.go b/cmd/scip/tests/reprolang/bindings/go/repro/scip.go index 10dcbb63..20243b91 100644 --- a/cmd/scip/tests/reprolang/bindings/go/repro/scip.go +++ b/cmd/scip/tests/reprolang/bindings/go/repro/scip.go @@ -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, } } diff --git a/cmd/scip/tests/snapshots/input/diagnostics/diagnostics.repro b/cmd/scip/tests/snapshots/input/diagnostics/diagnostics.repro new file mode 100644 index 00000000..e9376c39 --- /dev/null +++ b/cmd/scip/tests/snapshots/input/diagnostics/diagnostics.repro @@ -0,0 +1,2 @@ +definition deprecatedMethod. +reference deprecatedMethod. diff --git a/cmd/scip/tests/snapshots/output/cyclic-reference/cycle1.repro b/cmd/scip/tests/snapshots/output/cyclic-reference/cycle1.repro index 2572d7b6..711c2ebe 100755 --- a/cmd/scip/tests/snapshots/output/cyclic-reference/cycle1.repro +++ b/cmd/scip/tests/snapshots/output/cyclic-reference/cycle1.repro @@ -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(). diff --git a/cmd/scip/tests/snapshots/output/cyclic-reference/cycle2.repro b/cmd/scip/tests/snapshots/output/cyclic-reference/cycle2.repro index 396e53ca..d9997592 100755 --- a/cmd/scip/tests/snapshots/output/cyclic-reference/cycle2.repro +++ b/cmd/scip/tests/snapshots/output/cyclic-reference/cycle2.repro @@ -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(). diff --git a/cmd/scip/tests/snapshots/output/diagnostics/diagnostics.repro b/cmd/scip/tests/snapshots/output/diagnostics/diagnostics.repro new file mode 100755 index 00000000..81ef168a --- /dev/null +++ b/cmd/scip/tests/snapshots/output/diagnostics/diagnostics.repro @@ -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 + diff --git a/cmd/scip/tests/snapshots/output/diagnostics/dump.lsif b/cmd/scip/tests/snapshots/output/diagnostics/dump.lsif new file mode 100755 index 00000000..526aadc6 --- /dev/null +++ b/cmd/scip/tests/snapshots/output/diagnostics/dump.lsif @@ -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} diff --git a/cmd/scip/tests/snapshots/output/duplicates/duplicate.repro b/cmd/scip/tests/snapshots/output/duplicates/duplicate.repro index c3eb7209..608f145d 100755 --- a/cmd/scip/tests/snapshots/output/duplicates/duplicate.repro +++ b/cmd/scip/tests/snapshots/output/duplicates/duplicate.repro @@ -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. diff --git a/cmd/scip/tests/snapshots/output/forward-def/forward_def.repro b/cmd/scip/tests/snapshots/output/forward-def/forward_def.repro index 049addb5..2e633659 100755 --- a/cmd/scip/tests/snapshots/output/forward-def/forward_def.repro +++ b/cmd/scip/tests/snapshots/output/forward-def/forward_def.repro @@ -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# diff --git a/cmd/scip/tests/snapshots/output/implementation-cross-repo/bird.repro b/cmd/scip/tests/snapshots/output/implementation-cross-repo/bird.repro index d442b402..0be0be06 100755 --- a/cmd/scip/tests/snapshots/output/implementation-cross-repo/bird.repro +++ b/cmd/scip/tests/snapshots/output/implementation-cross-repo/bird.repro @@ -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# diff --git a/cmd/scip/tests/snapshots/output/implementation/animal.repro b/cmd/scip/tests/snapshots/output/implementation/animal.repro index e98d0378..218fa3a6 100755 --- a/cmd/scip/tests/snapshots/output/implementation/animal.repro +++ b/cmd/scip/tests/snapshots/output/implementation/animal.repro @@ -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# diff --git a/cmd/scip/tests/snapshots/output/local-document/local1.repro b/cmd/scip/tests/snapshots/output/local-document/local1.repro index 3509f733..685441ac 100755 --- a/cmd/scip/tests/snapshots/output/local-document/local1.repro +++ b/cmd/scip/tests/snapshots/output/local-document/local1.repro @@ -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 diff --git a/cmd/scip/tests/snapshots/output/relationships/defined_by.repro b/cmd/scip/tests/snapshots/output/relationships/defined_by.repro index 7f3beaee..adbcaa17 100755 --- a/cmd/scip/tests/snapshots/output/relationships/defined_by.repro +++ b/cmd/scip/tests/snapshots/output/relationships/defined_by.repro @@ -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. diff --git a/cmd/scip/tests/snapshots/output/relationships/mixed.repro b/cmd/scip/tests/snapshots/output/relationships/mixed.repro index baf0ef1d..6eb69995 100755 --- a/cmd/scip/tests/snapshots/output/relationships/mixed.repro +++ b/cmd/scip/tests/snapshots/output/relationships/mixed.repro @@ -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 diff --git a/cmd/scip/tests/snapshots/output/relationships/references.repro b/cmd/scip/tests/snapshots/output/relationships/references.repro index 6faaeba2..44c9eab3 100755 --- a/cmd/scip/tests/snapshots/output/relationships/references.repro +++ b/cmd/scip/tests/snapshots/output/relationships/references.repro @@ -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 diff --git a/cmd/scip/tests/snapshots/output/relationships/type_defines.repro b/cmd/scip/tests/snapshots/output/relationships/type_defines.repro index 4962ab24..708bba8f 100755 --- a/cmd/scip/tests/snapshots/output/relationships/type_defines.repro +++ b/cmd/scip/tests/snapshots/output/relationships/type_defines.repro @@ -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