Skip to content

Commit

Permalink
Merge pull request #100 from Workiva/added_diagnostics_snapshot_test
Browse files Browse the repository at this point in the history
Diagnostic bug fixes (and snapshot tests)
  • Loading branch information
rm-astro-wf authored Nov 2, 2023
2 parents fe6dde9 + c4b190a commit c97eac8
Show file tree
Hide file tree
Showing 10 changed files with 340 additions and 64 deletions.
38 changes: 37 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,43 @@ jobs:
echo "No changes to snapshot files"
else
echo
echo "Snapshot diff detected differences, run 'make run snap' to re-generate snapshots"
echo "Snapshot diff detected differences, run 'make gen-snaps' to re-generate snapshots"
git status --short ./snapshots/output
echo
exit 1
fi
snapshots-diagnostics:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install scip cli
run: |
bash -c 'curl -L "https://github.com/sourcegraph/scip/releases/download/v0.3.0/scip-linux-amd64.tar.gz"' | tar xzf - scip
./scip --version
- uses: dart-lang/setup-dart@v1
with:
sdk: 2.18.7
- name: pub get scip-dart package
run: dart pub get

- name: pub get diagnostics directory
run: dart pub get
working-directory: ./snapshots/input/diagnostics

- name: Install jq
uses: dcarbone/[email protected]

- name: Snapshots Diff Check
run: |
make gen-snap_diagnostics
if [[ -z "$(git status --porcelain ./snapshots/output)" ]];
then
echo "No changes to snapshot files"
else
echo
echo "Snapshot diff detected differences, run 'make gen-snaps' to re-generate snapshots"
git status --short ./snapshots/output
echo
exit 1
Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
regen-snapshots:
gen-snaps:
make gen-snap_basic-project
make gen-snap_relationships-project
make gen-snap_diagnostics

gen-snap_basic-project:
dart run scip_dart ./snapshots/input/basic-project
scip snapshot --to ./snapshots/output/basic-project

gen-snap_relationships-project:
dart run scip_dart --index-relationships ./snapshots/input/relationships-project
scip snapshot --to ./snapshots/output/relationships-project

gen-snap_diagnostics:
dart run scip_dart ./snapshots/input/diagnostics
scip print --json ./index.scip | jq '.documents[].occurrences[] | select(.diagnostics)' | jq -s . > ./snapshots/output/diagnostics/output.json


run:
dart run scip_dart ./snapshots/input/staging-project --verbose

Expand Down
5 changes: 2 additions & 3 deletions lib/src/metadata.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/error/error.dart';
Expand Down Expand Up @@ -39,7 +38,7 @@ class SymbolMetadata {
/// within the protobuf schema for scip
SymbolMetadata getSymbolMetadata(
Element element,
AstNode node,
int offset,
List<AnalysisError> analysisErrors,
) {
final displayString = element.getDisplayString(
Expand All @@ -53,7 +52,7 @@ SymbolMetadata getSymbolMetadata(
);

final diagnostics = analysisErrors
.where((error) => error.offset == node.offset)
.where((error) => error.offset == offset)
.map((error) => proto.Diagnostic(
code: error.errorCode.name,
message: error.message,
Expand Down
7 changes: 4 additions & 3 deletions lib/src/scip_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ScipVisitor extends GeneralizingAstVisitor {
}) {
final symbol = _symbolGenerator.symbolFor(element);
if (symbol != null) {
final meta = getSymbolMetadata(element, node, _analysisErrors);
final meta = getSymbolMetadata(element, offset, _analysisErrors);
occurrences.add(Occurrence(
range: _lineInfo.getRange(offset, length),
symbol: symbol,
Expand All @@ -177,7 +177,7 @@ class ScipVisitor extends GeneralizingAstVisitor {
if (!globalExternalSymbols.any(
(symbolInfo) => symbolInfo.symbol == symbol,
)) {
final meta = getSymbolMetadata(element, node, _analysisErrors);
final meta = getSymbolMetadata(element, offset, _analysisErrors);
globalExternalSymbols.add(SymbolInformation(
symbol: symbol,
documentation: meta.documentation,
Expand All @@ -198,7 +198,8 @@ class ScipVisitor extends GeneralizingAstVisitor {
}) {
final symbol = _symbolGenerator.symbolFor(element);
if (symbol != null) {
final meta = getSymbolMetadata(element, node, _analysisErrors);
final meta =
getSymbolMetadata(element, element.nameOffset, _analysisErrors);
symbols.add(SymbolInformation(
symbol: symbol,
documentation: meta.documentation,
Expand Down
Loading

0 comments on commit c97eac8

Please sign in to comment.