From 8c052dcd8f7b7aa9368fc97a8d374e3422b2af3e Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 19 Dec 2024 09:48:06 -0700 Subject: [PATCH 1/7] fixed logic for constructor references --- lib/src/scip_visitor.dart | 9 +++++++++ lib/src/symbol_generator.dart | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index c1d1156c..4bccbe5f 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -53,6 +53,12 @@ class ScipVisitor extends GeneralizingAstVisitor { // to correctly parse all [Declaration] ast nodes. if (node is Declaration) { _visitDeclaration(node); + + // A constructor's ast has a reference to the class declaration in its children + // we only want to mark the direct constructor for this, and skip the child + // reference. Stop cascading into children in this case + if (node is ConstructorDeclaration) return; + } else if (node is NormalFormalParameter) { _visitNormalFormalParameter(node); } else if (node is SimpleIdentifier) { @@ -103,6 +109,9 @@ class ScipVisitor extends GeneralizingAstVisitor { final element = _symbolGenerator.elementFor(node); if (element == null) return; + // print('$node - ${node.runtimeType} - ${node.offset} - ${element.runtimeType}'); + print('${node.parent} - ${node.parent!.parent.runtimeType}'); + if (node.inDeclarationContext()) { _registerAsDefinition(element, node); } else { diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index 76b80c86..575d58ac 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -44,6 +44,13 @@ class SymbolGenerator { } else if (node is SimpleIdentifier) { var element = node.staticElement; + // 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(); + if (parentConstructor != null) { + 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) { From cfb838853c7aa7c7686a8fbbb3665a9ac93d494d Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 19 Dec 2024 09:48:29 -0700 Subject: [PATCH 2/7] removed print --- lib/src/scip_visitor.dart | 3 -- snapshots/output/basic-project/lib/main.dart | 2 +- snapshots/output/basic-project/lib/more.dart | 29 +++---------------- snapshots/output/basic-project/lib/other.dart | 18 ++---------- 4 files changed, 8 insertions(+), 44 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index 4bccbe5f..7d978019 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -109,9 +109,6 @@ class ScipVisitor extends GeneralizingAstVisitor { final element = _symbolGenerator.elementFor(node); if (element == null) return; - // print('$node - ${node.runtimeType} - ${node.offset} - ${element.runtimeType}'); - print('${node.parent} - ${node.parent!.parent.runtimeType}'); - if (node.inDeclarationContext()) { _registerAsDefinition(element, node); } else { diff --git a/snapshots/output/basic-project/lib/main.dart b/snapshots/output/basic-project/lib/main.dart index 37fd5659..e9933d30 100755 --- a/snapshots/output/basic-project/lib/main.dart +++ b/snapshots/output/basic-project/lib/main.dart @@ -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#``(). // ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value) // ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value2) } diff --git a/snapshots/output/basic-project/lib/more.dart b/snapshots/output/basic-project/lib/more.dart index 5254e4f5..3a9c3895 100755 --- a/snapshots/output/basic-project/lib/more.dart +++ b/snapshots/output/basic-project/lib/more.dart @@ -40,40 +40,19 @@ Animal(this.name, {required this.type}) { // ^^^^^^ definition 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# -// ^^^^ 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#``().(type) print(AnimalType.values); -// ^^^^^ 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`/AnimalType# switch (type) { -// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#type. case AnimalType.cat: -// ^^^^^^^^^^ 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. soundMaker = () => print('Meow!'); -// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#soundMaker. -// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). break; case AnimalType.dog: -// ^^^^^^^^^^ 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. soundMaker = () => print('Woof!'); -// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#soundMaker. -// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). break; case AnimalType.bird: -// ^^^^^^^^^^ 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. soundMaker = () => print('Chirp!'); -// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#soundMaker. -// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). break; default: soundMaker = () => print('Unknown animal type'); -// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#soundMaker. -// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). } } @@ -125,14 +104,14 @@ Animal cat = Animal('Kitty', type: AnimalType.cat); // ^^^^^^ 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#``(). // ^^^^ 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`/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 -// ^^^^^^ 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#``(). // ^^^^ 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`/AnimalType# // ^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/AnimalType#dog. @@ -164,8 +143,8 @@ 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#``(). +// ^^^^^^^^^ reference scip-dart pub dart:math 2.19.0 dart:math/`rectangle.dart`/Rectangle#``(). [1,2].reduce((a, b) => a + b); // ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`iterable.dart`/Iterable#reduce(). diff --git a/snapshots/output/basic-project/lib/other.dart b/snapshots/output/basic-project/lib/other.dart index ae042664..3492de9c 100755 --- a/snapshots/output/basic-project/lib/other.dart +++ b/snapshots/output/basic-project/lib/other.dart @@ -18,22 +18,12 @@ // ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value3. Foo( // ^^^ definition 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# this._far, { -// ^^^^ reference local 0 required this.value, -// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value. -// ^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value) required this.value2, -// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value2. -// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value2) this.value3, -// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value3. -// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value3) }) { print(_far); -// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). -// ^^^^ reference local 0 } } @@ -44,8 +34,6 @@ // ^^^^^^^^^^ definition local 1 Bar(this._someValue); // ^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar#``(). -// ^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar# -// ^^^^^^^^^^ reference local 1 void someMethod() { // ^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar#someMethod(). @@ -64,12 +52,12 @@ // ^^^^ reference scip-dart pub dart:async 2.19.0 dart:async/`future.dart`/Future#then(). // ^ definition local 2 Bar('a').someMethod.call() -// ^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar# +// ^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar#``(). // ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar#someMethod(). }); Foo(1, value: true, value2: 'asdf')..value = false; -// ^^^ 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#``(). // ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value) // ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value2) // ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value. @@ -77,7 +65,7 @@ final someStr = 'someStr'; // ^^^^^^^ definition local 3 Foo(2, value: false, value2: 'some Val!') -// ^^^ 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#``(). // ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value) // ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value2) ..value = true From 169275af67ed3e5dc0d326ea4ccf1cfe5e2f9f91 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 19 Dec 2024 09:58:08 -0700 Subject: [PATCH 3/7] fixed bug where all constructor parameters stopped indexing --- Makefile | 5 ++++- lib/src/scip_visitor.dart | 6 ------ lib/src/symbol_generator.dart | 7 +++++++ snapshots/output/basic-project/lib/more.dart | 20 +++++++++++++++++++ snapshots/output/basic-project/lib/other.dart | 10 ++++++++++ 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index bdf91850..ae1a16ab 100644 --- a/Makefile +++ b/Makefile @@ -21,4 +21,7 @@ gen-proto: protoc --dart_out=. ./lib/src/gen/scip.proto print: - scip print ./index.scip \ No newline at end of file + scip print ./index.scip + +print-ast: + dart run ./tool/ast_printer.dart ./snapshots/input/staging-project \ No newline at end of file diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index 7d978019..c1d1156c 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -53,12 +53,6 @@ class ScipVisitor extends GeneralizingAstVisitor { // to correctly parse all [Declaration] ast nodes. if (node is Declaration) { _visitDeclaration(node); - - // A constructor's ast has a reference to the class declaration in its children - // we only want to mark the direct constructor for this, and skip the child - // reference. Stop cascading into children in this case - if (node is ConstructorDeclaration) return; - } else if (node is NormalFormalParameter) { _visitNormalFormalParameter(node); } else if (node is SimpleIdentifier) { diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index 575d58ac..97fa118e 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -44,6 +44,13 @@ 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(); diff --git a/snapshots/output/basic-project/lib/more.dart b/snapshots/output/basic-project/lib/more.dart index 3a9c3895..79aed98d 100755 --- a/snapshots/output/basic-project/lib/more.dart +++ b/snapshots/output/basic-project/lib/more.dart @@ -40,19 +40,39 @@ Animal(this.name, {required this.type}) { // ^^^^^^ definition 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#``().(type) print(AnimalType.values); +// ^^^^^ 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`/AnimalType# switch (type) { +// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#type. case AnimalType.cat: +// ^^^^^^^^^^ 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. soundMaker = () => print('Meow!'); +// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#soundMaker. +// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). break; case AnimalType.dog: +// ^^^^^^^^^^ 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. soundMaker = () => print('Woof!'); +// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#soundMaker. +// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). break; case AnimalType.bird: +// ^^^^^^^^^^ 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. soundMaker = () => print('Chirp!'); +// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#soundMaker. +// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). break; default: soundMaker = () => print('Unknown animal type'); +// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#soundMaker. +// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). } } diff --git a/snapshots/output/basic-project/lib/other.dart b/snapshots/output/basic-project/lib/other.dart index 3492de9c..30a16588 100755 --- a/snapshots/output/basic-project/lib/other.dart +++ b/snapshots/output/basic-project/lib/other.dart @@ -19,11 +19,20 @@ Foo( // ^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``(). this._far, { +// ^^^^ reference local 0 required this.value, +// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value. +// ^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value) required this.value2, +// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value2. +// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value2) this.value3, +// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value3. +// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#``().(value3) }) { print(_far); +// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). +// ^^^^ reference local 0 } } @@ -34,6 +43,7 @@ // ^^^^^^^^^^ definition local 1 Bar(this._someValue); // ^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar#``(). +// ^^^^^^^^^^ reference local 1 void someMethod() { // ^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar#someMethod(). From d29d6855c103d7c2a84ff87692df5889141e25c7 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 19 Dec 2024 10:28:00 -0700 Subject: [PATCH 4/7] fixed constructor declarations in prefixed identifiers --- lib/src/symbol_generator.dart | 13 +++++ snapshots/input/basic-project/lib/more.dart | 13 +++-- .../basic-project/lib/relationships.dart | 2 +- snapshots/output/basic-project/lib/more.dart | 58 ++++++++++++------- .../basic-project/lib/relationships.dart | 4 +- 5 files changed, 63 insertions(+), 27 deletions(-) diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index 97fa118e..a35074f5 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -55,6 +55,19 @@ class SymbolGenerator { // as the element to annotate instead of the reference to the Class final parentConstructor = node.thisOrAncestorOfType(); if (parentConstructor != null) { + // ConstructorNames can also include a PrefixIdentifier: `math.Rectangle()` + // both 'math' and 'Rectangle' are simple identifiers. We only want + // the constructor element fo 'Rectangle' in this case + final parentPrefixIdentifier = node.thisOrAncestorOfType(); + if (parentPrefixIdentifier != null) { + if (parentPrefixIdentifier.identifier == node) { + return parentConstructor.staticElement; + } + return element; + } + + // Otherwise, element is just `Rectangle()`, so simply return the + // constructor's element return parentConstructor.staticElement; } diff --git a/snapshots/input/basic-project/lib/more.dart b/snapshots/input/basic-project/lib/more.dart index ae1ccf43..678db4ff 100644 --- a/snapshots/input/basic-project/lib/more.dart +++ b/snapshots/input/basic-project/lib/more.dart @@ -36,6 +36,8 @@ class Animal with SleepMixin { } } + factory Animal.cat() => Animal('Timmy', type: AnimalType.cat); + void makeSound() { soundMaker?.call(); } @@ -54,16 +56,19 @@ void main() { List numbers = [1, 2, 3, 4, 5]; int sum = calculateSum(numbers); - Animal cat = Animal('Kitty', type: AnimalType.cat); + Animal bird = Animal('Kitty', type: AnimalType.bird); Animal dog = Animal('Buddy', type: AnimalType.dog); + Animal cat = Animal.cat(); - cat.makeSound(); - cat.sleep(); + bird.makeSound(); + bird.sleep(); dog.makeSound(); dog.sleep(); - print(cat); + cat.makeSound(); + + print(bird); print(dog); print('The sum of $numbers is $sum'); diff --git a/snapshots/input/basic-project/lib/relationships.dart b/snapshots/input/basic-project/lib/relationships.dart index 1ad99239..9218058c 100644 --- a/snapshots/input/basic-project/lib/relationships.dart +++ b/snapshots/input/basic-project/lib/relationships.dart @@ -26,5 +26,5 @@ class Dog extends Animal with SwimAction { String get someGetter => 'value'; @override - set someSetter(String v) {}; + set someSetter(String v) => print(v); } \ No newline at end of file diff --git a/snapshots/output/basic-project/lib/more.dart b/snapshots/output/basic-project/lib/more.dart index 79aed98d..56d7e5fd 100755 --- a/snapshots/output/basic-project/lib/more.dart +++ b/snapshots/output/basic-project/lib/more.dart @@ -76,6 +76,13 @@ } } + factory Animal.cat() => Animal('Timmy', type: AnimalType.cat); +// ^^^ 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#``(). +// ^^^^ 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`/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(); @@ -121,13 +128,13 @@ // ^^^^^^^^^^^^ 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#``().(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#``(). +// ^^^^ 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`/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 @@ -135,13 +142,18 @@ // ^^^^ 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`/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#cat(). +// ^^^ 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 @@ -150,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 @@ -163,24 +179,24 @@ 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:math 2.19.0 dart:math/`rectangle.dart`/Rectangle#``(). +// ^^^^ 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#``(). [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 diff --git a/snapshots/output/basic-project/lib/relationships.dart b/snapshots/output/basic-project/lib/relationships.dart index dc6a8d99..11b0e1ff 100755 --- a/snapshots/output/basic-project/lib/relationships.dart +++ b/snapshots/output/basic-project/lib/relationships.dart @@ -67,9 +67,11 @@ @override // ^^^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`annotations.dart`/override. - set someSetter(String v) {}; + set someSetter(String v) => print(v); // ^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Dog#`someSetter`. // relationship scip-dart pub dart_test 1.0.0 lib/`relationships.dart`/Mammal#`someSetter`. implementation reference // ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String# // ^ definition local 1 +// ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). +// ^ reference local 1 } From f003e51e36cb20dd257c2fac0ad6567c7e835154 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 19 Dec 2024 10:47:55 -0700 Subject: [PATCH 5/7] fixed named constructors --- lib/src/symbol_generator.dart | 21 ++++++++++++-------- snapshots/output/basic-project/lib/more.dart | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index a35074f5..d982bff7 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -55,18 +55,23 @@ class SymbolGenerator { // as the element to annotate instead of the reference to the Class final parentConstructor = node.thisOrAncestorOfType(); if (parentConstructor != null) { - // ConstructorNames can also include a PrefixIdentifier: `math.Rectangle()` - // both 'math' and 'Rectangle' are simple identifiers. We only want - // the constructor element fo 'Rectangle' in this case + + // 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 final parentPrefixIdentifier = node.thisOrAncestorOfType(); - if (parentPrefixIdentifier != null) { - if (parentPrefixIdentifier.identifier == node) { - return parentConstructor.staticElement; - } + 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; + } if (parentConstructor.name != null) { return element; } - // Otherwise, element is just `Rectangle()`, so simply return the + // Otherwise, constructor is just `Foo()`, so simply return the // constructor's element return parentConstructor.staticElement; } diff --git a/snapshots/output/basic-project/lib/more.dart b/snapshots/output/basic-project/lib/more.dart index 56d7e5fd..22bf7d7d 100755 --- a/snapshots/output/basic-project/lib/more.dart +++ b/snapshots/output/basic-project/lib/more.dart @@ -145,7 +145,7 @@ 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#cat(). +// ^^^^^^ 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(). bird.makeSound(); From 3c62e212da816ac1cc157a81ceb5f2330c8ab4e6 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 19 Dec 2024 10:49:00 -0700 Subject: [PATCH 6/7] fmt --- lib/src/symbol_generator.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index d982bff7..cb7addc4 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -55,22 +55,22 @@ class SymbolGenerator { // as the element to annotate instead of the reference to the Class final parentConstructor = node.thisOrAncestorOfType(); 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 - final parentPrefixIdentifier = node.thisOrAncestorOfType(); + final parentPrefixIdentifier = + node.thisOrAncestorOfType(); 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 + // reference the class if (parentConstructor.name == node) { return parentConstructor.staticElement; - } if (parentConstructor.name != null) { + } else if (parentConstructor.name != null) { return element; } - + // Otherwise, constructor is just `Foo()`, so simply return the // constructor's element return parentConstructor.staticElement; From 69bb98d00f2528e0ae139d443c8d9de3df377eea Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 2 Jan 2025 12:39:41 -0700 Subject: [PATCH 7/7] documentation updates --- lib/src/symbol_generator.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index cb7addc4..b2aa73f2 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -45,8 +45,7 @@ class SymbolGenerator { 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 + // is the reference to the class itself. Skip this declaration if (node.parent is ConstructorDeclaration) { return null; } @@ -57,7 +56,7 @@ class SymbolGenerator { 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 + // element for 'Rectangle' in this case final parentPrefixIdentifier = node.thisOrAncestorOfType(); if (parentPrefixIdentifier?.prefix == node) return element;