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
17 changes: 9 additions & 8 deletions lib/src/scip_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,20 @@ class ScipVisitor extends GeneralizingAstVisitor {
final element = node.declaredElement;
if (element == null) return;

// FieldFormalParameters reference a field instead of define a declaration
// register them as such
if (element is FieldFormalParameterElement) {
if (node is FieldFormalParameter) {
final fieldElement = (element as FieldFormalParameterElement).field;
_registerAsReference(
element.field!,
offset: node.name!.offset,
length: node.name!.length,
fieldElement!,
offset: node.thisKeyword.offset,
length: node.thisKeyword.length,
);
} else {
_registerAsDefinition(element);
}

_registerAsDefinition(element);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All parameters are definitions now, this is for parity with IDE navigation/analysis

}



void _visitSimpleIdentifier(SimpleIdentifier node) {
final element = node.staticElement;

Expand Down
6 changes: 3 additions & 3 deletions snapshots/input/basic-project/lib/more.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Animal with SleepMixin {
AnimalType type;
SoundMaker? soundMaker;

Animal(this.name, this.type) {
Animal(this.name, {required this.type}) {
switch (type) {
case AnimalType.cat:
soundMaker = () => print('Meow!');
Expand Down Expand Up @@ -53,8 +53,8 @@ void main() {
List<int> numbers = [1, 2, 3, 4, 5];
int sum = calculateSum(numbers);

Animal cat = Animal('Kitty', AnimalType.cat);
Animal dog = Animal('Buddy', AnimalType.dog);
Animal cat = Animal('Kitty', type: AnimalType.cat);
Animal dog = Animal('Buddy', type: AnimalType.dog);

cat.makeSound();
cat.sleep();
Expand Down
62 changes: 34 additions & 28 deletions snapshots/output/basic-project/lib/more.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@
// ^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#soundMaker.
// documentation ```dart

Animal(this.name, this.type) {
Animal(this.name, {required this.type}) {
// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#<constructor>().
// documentation ```dart
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#name.
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#type.
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#name.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is targeting the this keyword, referencing the field, not the parameter definition

// ^^^^ definition local 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is targeting the parameter itself, hence its local definition (not accessible outside of the file)

// documentation ```dart
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#type.
// ^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#<constructor>().(type)
// documentation ```dart
switch (type) {
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#type.
case AnimalType.cat:
Expand Down Expand Up @@ -106,17 +110,17 @@
// documentation ```dart
// ^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/list.dart/List#
// ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
// ^^^^^^^ definition local 0
// ^^^^^^^ definition local 1
// documentation ```dart
return numbers.reduce((value, element) => value + element);
// ^^^^^^^ reference local 0
// ^^^^^^^ reference local 1
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/iterable.dart/Iterable#reduce().
// ^^^^^ definition local 1
// ^^^^^ definition local 2
// documentation ```dart
// ^^^^^^^ definition local 2
// ^^^^^^^ definition local 3
// documentation ```dart
// ^^^^^ reference local 1
// ^^^^^^^ reference local 2
// ^^^^^ reference local 2
// ^^^^^^^ reference local 3
}

void main() {
Expand All @@ -125,54 +129,56 @@
List<int> numbers = [1, 2, 3, 4, 5];
// ^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/list.dart/List#
// ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
// ^^^^^^^ definition local 3
// ^^^^^^^ definition local 4
// documentation ```dart
int sum = calculateSum(numbers);
// ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
// ^^^ definition local 4
// ^^^ definition local 5
// documentation ```dart
// ^^^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/calculateSum().
// ^^^^^^^ reference local 3
// ^^^^^^^ reference local 4

Animal cat = Animal('Kitty', AnimalType.cat);
Animal cat = Animal('Kitty', type: AnimalType.cat);
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#
// ^^^ definition local 5
// ^^^ definition local 6
// documentation ```dart
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/AnimalType#
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/AnimalType#cat.
Animal dog = Animal('Buddy', AnimalType.dog);
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#<constructor>().(type)
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/AnimalType#
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/AnimalType#cat.
Animal dog = Animal('Buddy', type: AnimalType.dog);
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#
// ^^^ definition local 6
// ^^^ definition local 7
// documentation ```dart
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/AnimalType#
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/AnimalType#dog.
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#<constructor>().(type)
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/AnimalType#
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/AnimalType#dog.

cat.makeSound();
// ^^^ reference local 5
// ^^^ reference local 6
// ^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#makeSound().
cat.sleep();
// ^^^ reference local 5
// ^^^ reference local 6
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/SleepMixin#sleep().

dog.makeSound();
// ^^^ reference local 6
// ^^^ reference local 7
// ^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#makeSound().
dog.sleep();
// ^^^ reference local 6
// ^^^ reference local 7
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/SleepMixin#sleep().

print(cat);
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
// ^^^ reference local 5
// ^^^ reference local 6
print(dog);
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
// ^^^ reference local 6
// ^^^ reference local 7
print('The sum of $numbers is $sum');
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
// ^^^^^^^ reference local 3
// ^^^ reference local 4
// ^^^^^^^ reference local 4
// ^^^ reference local 5

print(math.Rectangle(1,2,3,4));
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
Expand Down
4 changes: 3 additions & 1 deletion snapshots/output/basic-project/lib/other.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// ^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#<constructor>().
// documentation ```dart
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#
// ^^^^ reference local 0
// ^^^^ reference local 0
// ^^^^ definition local 1
// documentation ```dart
}