Skip to content

Commit c2a144d

Browse files
Merge pull request #77 from Workiva/put_relationship_indexing_behind_alpha
FEA-2357: Put relationship indexing behind a flag
2 parents dfe1f29 + 11c62c6 commit c2a144d

File tree

11 files changed

+68
-29
lines changed

11 files changed

+68
-29
lines changed

.github/workflows/tests.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v3
1515
- name: Install scip cli
1616
run: |
17-
bash -c 'curl -L "https://github.com/sourcegraph/scip/releases/download/v0.2.3/scip-linux-amd64.tar.gz"' | tar xzf - scip
17+
bash -c 'curl -L "https://github.com/sourcegraph/scip/releases/download/v0.3.0/scip-linux-amd64.tar.gz"' | tar xzf - scip
1818
./scip --version
1919
2020
- uses: dart-lang/setup-dart@v1
@@ -24,15 +24,22 @@ jobs:
2424
- name: pub get scip-dart package
2525
run: dart pub get
2626

27-
- name: pub get snapshots directory
27+
- name: pub get basic-project directory
2828
run: dart pub get
2929
working-directory: ./snapshots/input/basic-project
3030

31+
- name: pub get relationships-project directory
32+
run: dart pub get
33+
working-directory: ./snapshots/input/relationships-project
34+
3135
- name: Snapshots Diff Check
3236
run: |
3337
dart run scip_dart ./snapshots/input/basic-project
3438
./scip snapshot --to ./snapshots/output/basic-project
3539
40+
dart run scip_dart --index-relationships ./snapshots/input/relationships-project
41+
./scip snapshot --to ./snapshots/output/relationships-project
42+
3643
if [[ -z "$(git status --porcelain ./snapshots/output)" ]];
3744
then
3845
echo "No changes to snapshot files"

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
regen-snapshots:
2-
dart run scip_dart ./snapshots/input/basic-project --verbose
2+
dart run scip_dart ./snapshots/input/basic-project
33
scip snapshot --to ./snapshots/output/basic-project
44

5+
dart run scip_dart --index-relationships ./snapshots/input/relationships-project
6+
scip snapshot --to ./snapshots/output/relationships-project
7+
58
run:
69
dart run scip_dart ./snapshots/input/staging-project --verbose
710

bin/scip_dart.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import 'package:scip_dart/src/version.dart';
1010

1111
Future<void> main(List<String> args) async {
1212
final result = (ArgParser()
13+
..addFlag(
14+
'index-relationships',
15+
defaultsTo: false,
16+
help: 'Whether or not to index symbol relationships. '
17+
'This functionality is currently in alpha, and should not be '
18+
'considered stable and accurate.',
19+
)
1320
..addFlag(
1421
'performance',
1522
aliases: ['perf'],
@@ -22,8 +29,11 @@ Future<void> main(List<String> args) async {
2229
defaultsTo: false,
2330
help: 'Whether or not to display debugging text during indexing',
2431
)
25-
..addFlag('version',
26-
defaultsTo: false, help: 'Display the current version of scip-dart')
32+
..addFlag(
33+
'version',
34+
defaultsTo: false,
35+
help: 'Display the current version of scip-dart',
36+
)
2737
..addMultiOption(
2838
'path',
2939
abbr: 'p',

lib/src/flags.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ class Flags {
77
bool get performance => _performance;
88
bool _performance = false;
99

10+
bool get indexRelationships => _indexRelationships;
11+
bool _indexRelationships = false;
12+
1013
void init(ArgResults results) {
1114
_verbose = results['verbose'] as bool? ?? false;
1215
_performance = results['performance'] as bool? ?? false;
16+
_indexRelationships = results['index-relationships'] as bool? ?? false;
1317
}
1418

1519
static Flags get instance => _instance;

lib/src/scip_visitor.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:analyzer/dart/element/element.dart';
44
import 'package:analyzer/source/line_info.dart';
55
import 'package:package_config/package_config.dart';
66
import 'package:pubspec_parse/pubspec_parse.dart';
7+
import 'package:scip_dart/src/flags.dart';
78
import 'package:scip_dart/src/metadata.dart';
89
import 'package:scip_dart/src/gen/scip.pb.dart';
910
import 'package:scip_dart/src/relationship_generator.dart';
@@ -62,9 +63,15 @@ class ScipVisitor extends GeneralizingAstVisitor {
6263
if (node.declaredElement == null) return;
6364

6465
final element = node.declaredElement!;
66+
67+
List<Relationship>? relationships;
68+
if (Flags.instance.indexRelationships) {
69+
relationships = relationshipsFor(node, element, _symbolGenerator);
70+
}
71+
6572
_registerAsDefinition(
6673
element,
67-
relationships: relationshipsFor(node, element, _symbolGenerator),
74+
relationships: relationships,
6875
);
6976
}
7077

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ packages:
2121
name: args
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "2.4.2"
24+
version: "2.4.1"
2525
async:
2626
dependency: transitive
2727
description:
@@ -175,7 +175,7 @@ packages:
175175
name: glob
176176
url: "https://pub.dartlang.org"
177177
source: hosted
178-
version: "2.1.2"
178+
version: "2.1.1"
179179
graphs:
180180
dependency: transitive
181181
description:
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Generated by pub
2+
# See https://dart.dev/tools/pub/glossary#lockfile
3+
packages: {}
4+
sdks:
5+
dart: ">=2.18.0 <3.0.0"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: dart_test
2+
version: 1.0.0
3+
4+
environment:
5+
sdk: ">=2.18.0 <3.0.0"

snapshots/output/basic-project/lib/more.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
class Animal with SleepMixin {
3636
// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#
3737
// documentation ```dart
38-
// relationship scip-dart pub dart_test 1.0.0 lib/more.dart/SleepMixin# implementation
3938
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/SleepMixin#
4039
String name;
4140
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String#
@@ -103,7 +102,6 @@
103102
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String#
104103
// ^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#toString().
105104
// documentation ```dart
106-
// relationship scip-dart pub dart:core 2.18.0 dart:core/object.dart/Object#toString(). implementation reference
107105
return '$name the $type';
108106
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#name.
109107
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#type.

0 commit comments

Comments
 (0)