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
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/install-jq-action@v2.0.2

- 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,
Comment on lines -42 to +41
Copy link
Contributor Author

@matthewnitschke-wk matthewnitschke-wk Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the specific node we pass in here isn't always the offset of the specific entity. For example, some elements are indexed by some analyzed element instead of the ast node at the specific depth

For this reason, just pass the offset as an int, so the errors can be correctly calculated where necessary

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