-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEDX-2227: Fixed logic for constructor references #165
Changes from 6 commits
8c052dc
cfb8388
169275a
d29d685
f003e51
3c62e21
69bb98d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,38 @@ class SymbolGenerator { | |
} else if (node is SimpleIdentifier) { | ||
var element = node.staticElement; | ||
|
||
// A SimpleIdentifier with a direct parent of a ConstructorDeclaration | ||
// is the reference to the class itself. In scip, we want to ignore | ||
// this as the constructor has its own definition, and only that | ||
if (node.parent is ConstructorDeclaration) { | ||
return null; | ||
} | ||
|
||
// if we're nested under a ConstructorName identifier, use the constructor | ||
// as the element to annotate instead of the reference to the Class | ||
final parentConstructor = node.thisOrAncestorOfType<ConstructorName>(); | ||
if (parentConstructor != null) { | ||
// ConstructorNames can also include an import PrefixIdentifier: `math.Rectangle()` | ||
// both 'math' and 'Rectangle' are SimpleIdentifiers. We only want the constructor | ||
// element fo 'Rectangle' in this case | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spelling nit: 'fo' |
||
final parentPrefixIdentifier = | ||
node.thisOrAncestorOfType<PrefixedIdentifier>(); | ||
if (parentPrefixIdentifier?.prefix == node) return element; | ||
|
||
// Constructors can be named: `Foo.bar()`, both `Foo` and `bar` are SimpleIdentifiers | ||
// When the constructor is named, 'bar' is the constructor reference and `Foo` should | ||
// reference the class | ||
if (parentConstructor.name == node) { | ||
return parentConstructor.staticElement; | ||
} else if (parentConstructor.name != null) { | ||
return element; | ||
} | ||
|
||
// Otherwise, constructor is just `Foo()`, so simply return the | ||
// constructor's element | ||
return parentConstructor.staticElement; | ||
} | ||
|
||
// Both `.loadLibrary()`, and `.call()` are synthetic functions that | ||
// have no definition. These should therefore should not be indexed. | ||
if (element is FunctionElement && element.isSynthetic) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ | |
// ^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`int.dart`/int# | ||
// ^^^^^ definition local 5 | ||
Foo(1, value: true, value2: ''); | ||
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo# | ||
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#`<constructor>`(). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we're correctly referencing |
||
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#`<constructor>`().(value) | ||
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#`<constructor>`().(value2) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,6 @@ | |
|
||
Animal(this.name, {required this.type}) { | ||
// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`(). | ||
// ^^^^^^ 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. | ||
// ^^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`().(type) | ||
|
@@ -77,6 +76,13 @@ | |
} | ||
} | ||
|
||
factory Animal.cat() => Animal('Timmy', type: AnimalType.cat); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very frustratingly, in named constructors, This isn't the case for SimpleIdentifiers for the call sight, but only the constructor declarations The result of this, is we can only index a single element here, and I've decided to index, the arguably more important, definition for factory Animal.cat() => ...
// ^^^^^^ NOT INDEXED
// ^^^ definition ... Animal#cat(). Solving this is a problem for another day... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a ticket to track this here: #166 |
||
// ^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#cat(). | ||
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`(). | ||
// ^^^^ 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. | ||
|
||
void makeSound() { | ||
// ^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#makeSound(). | ||
soundMaker?.call(); | ||
|
@@ -122,27 +128,32 @@ | |
// ^^^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/calculateSum(). | ||
// ^^^^^^^ reference local 3 | ||
|
||
Animal cat = Animal('Kitty', type: AnimalType.cat); | ||
Animal bird = Animal('Kitty', type: AnimalType.bird); | ||
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal# | ||
// ^^^ definition local 5 | ||
// ^^^^^^ 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#`<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. | ||
// ^^^^ definition local 5 | ||
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#`<constructor>`(). | ||
// ^^^^ 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#bird. | ||
Animal dog = Animal('Buddy', type: AnimalType.dog); | ||
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal# | ||
// ^^^ definition local 6 | ||
// ^^^^^^ 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#`<constructor>`(). | ||
// ^^^^ 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. | ||
Animal cat = Animal.cat(); | ||
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal# | ||
// ^^^ definition local 7 | ||
// ^^^^^^ 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#cat(). | ||
|
||
cat.makeSound(); | ||
// ^^^ reference local 5 | ||
// ^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#makeSound(). | ||
cat.sleep(); | ||
// ^^^ reference local 5 | ||
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/SleepMixin#sleep(). | ||
bird.makeSound(); | ||
// ^^^^ reference local 5 | ||
// ^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#makeSound(). | ||
bird.sleep(); | ||
// ^^^^ reference local 5 | ||
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/SleepMixin#sleep(). | ||
|
||
dog.makeSound(); | ||
// ^^^ reference local 6 | ||
|
@@ -151,9 +162,13 @@ | |
// ^^^ reference local 6 | ||
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/SleepMixin#sleep(). | ||
|
||
print(cat); | ||
cat.makeSound(); | ||
// ^^^ reference local 7 | ||
// ^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#makeSound(). | ||
|
||
print(bird); | ||
// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). | ||
// ^^^ reference local 5 | ||
// ^^^^ reference local 5 | ||
print(dog); | ||
// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). | ||
// ^^^ reference local 6 | ||
|
@@ -165,23 +180,23 @@ | |
print(math.Rectangle(1,2,3,4)); | ||
// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). | ||
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/math. | ||
// ^^^^^^^^^ reference scip-dart pub dart:math 2.19.0 dart:math/`rectangle.dart`/Rectangle# | ||
// ^^^^^^^^^ reference scip-dart pub dart:math 2.19.0 dart:math/`rectangle.dart`/Rectangle#`<constructor>`(). | ||
|
||
[1,2].reduce((a, b) => a + b); | ||
// ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`iterable.dart`/Iterable#reduce(). | ||
// ^ definition local 7 | ||
// ^ definition local 8 | ||
// ^ reference local 7 | ||
// ^ reference local 8 | ||
// ^ definition local 8 | ||
// ^ definition local 9 | ||
// ^ reference local 8 | ||
// ^ reference local 9 | ||
} | ||
|
||
void test(String Function(int) p) {} | ||
// ^^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/test(). | ||
// ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String# | ||
// ^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`int.dart`/int# | ||
// ^ definition local 9 | ||
// ^ definition local 10 | ||
void deepTest(String Function(void Function(String test)) p) {} | ||
// ^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/deepTest(). | ||
// ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String# | ||
// ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String# | ||
// ^ definition local 10 | ||
// ^ definition local 11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a missing end of sentence here?