From 0575e794d50bab7ee56127a39ce809b8fde33c27 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Sun, 7 Jul 2024 19:08:14 -0600 Subject: [PATCH 1/7] localized element selection logic to the symbol generator --- lib/src/scip_visitor.dart | 84 +++++++++-------------------------- lib/src/symbol_generator.dart | 70 +++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 63 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index 8d0fb2e0..0f8ceb71 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -62,9 +62,8 @@ class ScipVisitor extends GeneralizingAstVisitor { } void _visitDeclaration(Declaration node) { - if (node.declaredElement == null) return; - - final element = node.declaredElement!; + final element = _symbolGenerator.elementFor(node); + if (element == null) return; final relationships = relationshipsFor(node, element, _symbolGenerator); @@ -76,21 +75,12 @@ class ScipVisitor extends GeneralizingAstVisitor { } void _visitNormalFormalParameter(NormalFormalParameter node) { - final element = node.declaredElement; + final element = _symbolGenerator.elementFor(node); if (element == null) return; - // if this parameter is a child of a GenericFunctionType (can be a - // typedef, or a function as a parameter), we don't want to index it - // as a definition (nothing is defined, just referenced). Return false - // and let the [_visitSimpleIdentifier] declare the reference - final parentParameter = - node.parent?.thisOrAncestorOfType(); - if (parentParameter != null) return; - if (node is FieldFormalParameter) { - final fieldElement = (element as FieldFormalParameterElement).field; _registerAsReference( - fieldElement!, + element, node, offset: node.name.offset, length: node.name.length, @@ -102,39 +92,8 @@ class ScipVisitor extends GeneralizingAstVisitor { } void _visitSimpleIdentifier(SimpleIdentifier node) { - var element = node.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) { - if ([ - FunctionElement.LOAD_LIBRARY_NAME, - FunctionElement.CALL_METHOD_NAME, - ].contains(element.name)) return; - } - - // [element] for assignment fields is null. If the parent node - // is a `CompoundAssignmentExpression`, we know this node is referring - // to an assignment line. In that case, use the read/write element attached - // to this node instead of the [node]'s element - if (element == null) { - final assignmentExpr = - node.thisOrAncestorOfType(); - if (assignmentExpr == null) return; - - element = assignmentExpr.readElement ?? assignmentExpr.writeElement; - } - - // When the identifier is a field, the analyzer creates synthetic getters/ - // setters for it. We need to get the backing field. - if (element?.isSynthetic == true && element is PropertyAccessorElement) { - element = element.variable; - } - - // element is null if there's nothing really to do for this node. Example: `void` - // TODO: One weird issue found: named parameters of external symbols were element.source - // EX: `color(path, front: Styles.YELLOW);` where `color` comes from the chalk-dart package - if (element == null || element.source == null) return; + final element = _symbolGenerator.elementFor(node); + if (element == null) return; if (node.inDeclarationContext()) { _registerAsDefinition(element, node); @@ -195,22 +154,21 @@ class ScipVisitor extends GeneralizingAstVisitor { List? relationships, }) { final symbol = _symbolGenerator.symbolFor(element); - if (symbol != null) { - final meta = - getSymbolMetadata(element, element.nameOffset, _analysisErrors); - symbols.add(SymbolInformation( - symbol: symbol, - documentation: meta.documentation, - relationships: relationships, - signatureDocumentation: meta.signatureDocumentation, - )); + if (symbol == null) return null; - occurrences.add(Occurrence( - range: _lineInfo.getRange(element.nameOffset, element.nameLength), - symbol: symbol, - symbolRoles: SymbolRole.Definition.value, - diagnostics: meta.diagnostics, - )); - } + final meta = getSymbolMetadata(element, element.nameOffset, _analysisErrors); + symbols.add(SymbolInformation( + symbol: symbol, + documentation: meta.documentation, + relationships: relationships, + signatureDocumentation: meta.signatureDocumentation, + )); + + occurrences.add(Occurrence( + range: _lineInfo.getRange(element.nameOffset, element.nameLength), + symbol: symbol, + symbolRoles: SymbolRole.Definition.value, + diagnostics: meta.diagnostics, + )); } } diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index 9aaf1bca..63ee1522 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -1,3 +1,4 @@ +import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:pubspec_parse/pubspec_parse.dart'; import 'package:package_config/package_config.dart'; @@ -22,6 +23,73 @@ class SymbolGenerator { SymbolGenerator(this._packageConfig, this._pubspec); + /// For a given [AstNode], returns the correlating [Element] type + /// that should be used to generate the symbol + Element? elementFor(AstNode node) { + if (node is Declaration) { + return node.declaredElement; + } else if (node is NormalFormalParameter) { + + // if this parameter is a child of a GenericFunctionType (can be a + // typedef, or a function as a parameter), we don't want to index it + // as a definition (nothing is defined, just referenced). Return false + // and let the [_visitSimpleIdentifier] declare the reference + final parentParameter = node.parent?.thisOrAncestorOfType(); + if (parentParameter != null) return null; + + var element = node.declaredElement; + if (element == null) return null; + + if (node is FieldFormalParameter) { + return (element as FieldFormalParameterElement).field; + } + return element; + } else if (node is SimpleIdentifier) { + var element = node.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) { + if ([ + FunctionElement.LOAD_LIBRARY_NAME, + FunctionElement.CALL_METHOD_NAME, + ].contains(element.name)) return null; + } + + // [element] for assignment fields is null. If the parent node + // is a `CompoundAssignmentExpression`, we know this node is referring + // to an assignment line. In that case, use the read/write element attached + // to this node instead of the [node]'s element + if (element == null) { + final assignmentExpr = + node.thisOrAncestorOfType(); + if (assignmentExpr == null) return null; + + element = assignmentExpr.readElement ?? assignmentExpr.writeElement; + } + + // When the identifier is a field, the analyzer creates synthetic getters/ + // setters for it. We need to get the backing field. + if (element?.isSynthetic == true && element is PropertyAccessorElement) { + element = element.variable; + } + + // element is null if there's nothing really to do for this node. Example: `void` + // TODO: One weird issue found: named parameters of external symbols were element.source + // EX: `color(path, front: Styles.YELLOW);` where `color` comes from the chalk-dart package + if (element == null || element.source == null) return null; + + return node.staticElement; + } + + display( + 'WARN: Received unknown ast node type in elementFor: ' + '${node.runtimeType} ($node). Skipping' + ); + + return null; +} + /// For a given `Element` returns the scip symbol form. /// /// Returns [null] if symbol cannot be created for provided element @@ -237,3 +305,5 @@ class SymbolGenerator { } } } + + From c37dc026f87f98624a2bc8148ed25551c9a97c1a Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Sun, 7 Jul 2024 19:19:30 -0600 Subject: [PATCH 2/7] fixed broken snaps --- lib/src/scip_visitor.dart | 3 ++- lib/src/symbol_generator.dart | 22 +++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index 0f8ceb71..0085ae0f 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -156,7 +156,8 @@ class ScipVisitor extends GeneralizingAstVisitor { final symbol = _symbolGenerator.symbolFor(element); if (symbol == null) return null; - final meta = getSymbolMetadata(element, element.nameOffset, _analysisErrors); + final meta = + getSymbolMetadata(element, element.nameOffset, _analysisErrors); symbols.add(SymbolInformation( symbol: symbol, documentation: meta.documentation, diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index 63ee1522..70f78398 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -29,12 +29,12 @@ class SymbolGenerator { if (node is Declaration) { return node.declaredElement; } else if (node is NormalFormalParameter) { - // if this parameter is a child of a GenericFunctionType (can be a // typedef, or a function as a parameter), we don't want to index it // as a definition (nothing is defined, just referenced). Return false // and let the [_visitSimpleIdentifier] declare the reference - final parentParameter = node.parent?.thisOrAncestorOfType(); + final parentParameter = + node.parent?.thisOrAncestorOfType(); if (parentParameter != null) return null; var element = node.declaredElement; @@ -77,18 +77,16 @@ class SymbolGenerator { // element is null if there's nothing really to do for this node. Example: `void` // TODO: One weird issue found: named parameters of external symbols were element.source // EX: `color(path, front: Styles.YELLOW);` where `color` comes from the chalk-dart package - if (element == null || element.source == null) return null; + if (element?.source == null) return null; - return node.staticElement; - } + return element; + } - display( - 'WARN: Received unknown ast node type in elementFor: ' - '${node.runtimeType} ($node). Skipping' - ); + display('WARN: Received unknown ast node type in elementFor: ' + '${node.runtimeType} ($node). Skipping'); - return null; -} + return null; + } /// For a given `Element` returns the scip symbol form. /// @@ -305,5 +303,3 @@ class SymbolGenerator { } } } - - From 72ff06f0491cc30ce949f52303a626b105fbadd2 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Sun, 7 Jul 2024 19:38:44 -0600 Subject: [PATCH 3/7] fixed enum.values indexing --- lib/src/symbol_generator.dart | 6 ++++++ snapshots/input/basic-project/lib/more.dart | 1 + snapshots/output/basic-project/lib/more.dart | 3 +++ 3 files changed, 10 insertions(+) diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index 70f78398..31f1bc30 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -71,6 +71,12 @@ class SymbolGenerator { // When the identifier is a field, the analyzer creates synthetic getters/ // setters for it. We need to get the backing field. if (element?.isSynthetic == true && element is PropertyAccessorElement) { + // The values field on enums is synthetic, and has no explicit definition like + // other fields do. Skip indexing for this case. + if (element.enclosingElement is EnumElement && element.name == 'values') { + return null; + } + element = element.variable; } diff --git a/snapshots/input/basic-project/lib/more.dart b/snapshots/input/basic-project/lib/more.dart index 7b57fcde..ae1ccf43 100644 --- a/snapshots/input/basic-project/lib/more.dart +++ b/snapshots/input/basic-project/lib/more.dart @@ -20,6 +20,7 @@ class Animal with SleepMixin { SoundMaker? soundMaker; Animal(this.name, {required this.type}) { + print(AnimalType.values); switch (type) { case AnimalType.cat: soundMaker = () => print('Meow!'); diff --git a/snapshots/output/basic-project/lib/more.dart b/snapshots/output/basic-project/lib/more.dart index 4b8c8894..28866ea4 100755 --- a/snapshots/output/basic-project/lib/more.dart +++ b/snapshots/output/basic-project/lib/more.dart @@ -43,6 +43,9 @@ // ^^^^^^ 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. + 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: From 4f2cc407fcb4b9f4ef40c98fcb6acf2dd7829f0b Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Sun, 7 Jul 2024 19:47:48 -0600 Subject: [PATCH 4/7] fixed field formal constructor params --- lib/src/scip_visitor.dart | 6 ++++-- lib/src/symbol_generator.dart | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index 0085ae0f..a5b4b86c 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -78,14 +78,16 @@ class ScipVisitor extends GeneralizingAstVisitor { final element = _symbolGenerator.elementFor(node); if (element == null) return; + // if the parameter is a `this.someFieldOnThClass`, we need to register + // it as a reference to said field, as well as a declaration of a parameter. if (node is FieldFormalParameter) { + final fieldElement = (element as FieldFormalParameterElement).field; _registerAsReference( - element, + fieldElement!, node, offset: node.name.offset, length: node.name.length, ); - return; } _registerAsDefinition(element, node); diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index 31f1bc30..27479c7e 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -73,7 +73,8 @@ class SymbolGenerator { if (element?.isSynthetic == true && element is PropertyAccessorElement) { // The values field on enums is synthetic, and has no explicit definition like // other fields do. Skip indexing for this case. - if (element.enclosingElement is EnumElement && element.name == 'values') { + if (element.enclosingElement is EnumElement && + element.name == 'values') { return null; } From ab47f1dc299f47370249693dabfaa4bb3d5d3a3f Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Sun, 7 Jul 2024 19:50:06 -0600 Subject: [PATCH 5/7] regen --- lib/src/symbol_generator.dart | 6 +-- snapshots/output/basic-project/lib/more.dart | 52 ++++++++++--------- snapshots/output/basic-project/lib/other.dart | 21 +++++--- 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index 27479c7e..8f4b2bb7 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -40,9 +40,6 @@ class SymbolGenerator { var element = node.declaredElement; if (element == null) return null; - if (node is FieldFormalParameter) { - return (element as FieldFormalParameterElement).field; - } return element; } else if (node is SimpleIdentifier) { var element = node.staticElement; @@ -73,8 +70,7 @@ class SymbolGenerator { if (element?.isSynthetic == true && element is PropertyAccessorElement) { // The values field on enums is synthetic, and has no explicit definition like // other fields do. Skip indexing for this case. - if (element.enclosingElement is EnumElement && - element.name == 'values') { + if (element.enclosingElement is EnumElement && element.name == 'values') { return null; } diff --git a/snapshots/output/basic-project/lib/more.dart b/snapshots/output/basic-project/lib/more.dart index 28866ea4..35bd8319 100755 --- a/snapshots/output/basic-project/lib/more.dart +++ b/snapshots/output/basic-project/lib/more.dart @@ -42,7 +42,9 @@ // ^^^^^^ 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. +// ^^^^ definition local 0 // ^^^^ 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# @@ -99,14 +101,14 @@ // ^^^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/calculateSum(). // ^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`list.dart`/List# // ^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`int.dart`/int# -// ^^^^^^^ definition local 0 +// ^^^^^^^ definition local 1 return numbers.reduce((value, element) => value + element); -// ^^^^^^^ reference local 0 +// ^^^^^^^ reference local 1 // ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`iterable.dart`/Iterable#reduce(). -// ^^^^^ definition local 1 -// ^^^^^^^ definition local 2 -// ^^^^^ reference local 1 -// ^^^^^^^ reference local 2 +// ^^^^^ definition local 2 +// ^^^^^^^ definition local 3 +// ^^^^^ reference local 2 +// ^^^^^^^ reference local 3 } void main() { @@ -114,52 +116,52 @@ List numbers = [1, 2, 3, 4, 5]; // ^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`list.dart`/List# // ^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`int.dart`/int# -// ^^^^^^^ definition local 3 +// ^^^^^^^ definition local 4 int sum = calculateSum(numbers); // ^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`int.dart`/int# -// ^^^ definition local 4 +// ^^^ definition local 5 // ^^^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/calculateSum(). -// ^^^^^^^ reference local 3 +// ^^^^^^^ reference local 4 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 // ^^^^^^ 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 +// ^^^ 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#``().(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.19.0 dart:core/`print.dart`/print(). -// ^^^ reference local 5 +// ^^^ reference local 6 print(dog); // ^^^^^ reference scip-dart pub dart:core 2.19.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.19.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.19.0 dart:core/`print.dart`/print(). @@ -168,19 +170,19 @@ [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/other.dart b/snapshots/output/basic-project/lib/other.dart index 8bd2eef0..6e43618f 100755 --- a/snapshots/output/basic-project/lib/other.dart +++ b/snapshots/output/basic-project/lib/other.dart @@ -21,12 +21,16 @@ // ^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo# this._far, { // ^^^^ reference local 0 +// ^^^^ definition local 1 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(). @@ -38,19 +42,20 @@ // ^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar# String _someValue; // ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String# -// ^^^^^^^^^^ definition local 1 +// ^^^^^^^^^^ definition local 2 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 +// ^^^^^^^^^^ reference local 2 +// ^^^^^^^^^^ definition local 3 void someMethod() { // ^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar#someMethod(). _someValue = 'asdf'; -// ^^^^^^^^^^ reference local 1 +// ^^^^^^^^^^ reference local 2 print(_someValue); // ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). -// ^^^^^^^^^^ reference local 1 +// ^^^^^^^^^^ reference local 2 } } @@ -59,7 +64,7 @@ more.loadLibrary().then((_) => { // ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/more. // ^^^^ reference scip-dart pub dart:async 2.19.0 dart:async/`future.dart`/Future#then(). -// ^ definition local 2 +// ^ definition local 4 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#someMethod(). @@ -72,7 +77,7 @@ // ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value. final someStr = 'someStr'; -// ^^^^^^^ definition local 3 +// ^^^^^^^ definition local 5 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#``().(value) @@ -81,12 +86,12 @@ // ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value. ..value2 = someStr // ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value2. -// ^^^^^^^ reference local 3 +// ^^^^^^^ reference local 5 ..value3 = 2.15; // ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value3. more.test((_) => 'val'); // ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/more. // ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/test(). -// ^ definition local 4 +// ^ definition local 6 } From ec616828f43120e50c989c1d580fd90ae4809597 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Mon, 8 Jul 2024 09:40:19 -0600 Subject: [PATCH 6/7] fmt --- lib/src/symbol_generator.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/symbol_generator.dart b/lib/src/symbol_generator.dart index 8f4b2bb7..648ef18c 100644 --- a/lib/src/symbol_generator.dart +++ b/lib/src/symbol_generator.dart @@ -70,7 +70,8 @@ class SymbolGenerator { if (element?.isSynthetic == true && element is PropertyAccessorElement) { // The values field on enums is synthetic, and has no explicit definition like // other fields do. Skip indexing for this case. - if (element.enclosingElement is EnumElement && element.name == 'values') { + if (element.enclosingElement is EnumElement && + element.name == 'values') { return null; } From 64fd45f4009527de3078389502fb22b557d0b769 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Mon, 8 Jul 2024 10:43:26 -0600 Subject: [PATCH 7/7] resolved non-named field formal parameter declarations --- lib/src/scip_visitor.dart | 5 ++ snapshots/output/basic-project/lib/more.dart | 51 +++++++++---------- snapshots/output/basic-project/lib/other.dart | 18 +++---- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index a5b4b86c..20da4d30 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -88,6 +88,11 @@ class ScipVisitor extends GeneralizingAstVisitor { offset: node.name.offset, length: node.name.length, ); + + // non-named parameters are considered 'local' symbols, and when combined + // with field formal parameters (this.foo), do not contain a declaration. + // if its not named, do not register it as a definition as well. + if (!node.isNamed) return; } _registerAsDefinition(element, node); diff --git a/snapshots/output/basic-project/lib/more.dart b/snapshots/output/basic-project/lib/more.dart index 35bd8319..5254e4f5 100755 --- a/snapshots/output/basic-project/lib/more.dart +++ b/snapshots/output/basic-project/lib/more.dart @@ -42,7 +42,6 @@ // ^^^^^^ 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. -// ^^^^ definition local 0 // ^^^^ 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); @@ -101,14 +100,14 @@ // ^^^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`more.dart`/calculateSum(). // ^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`list.dart`/List# // ^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`int.dart`/int# -// ^^^^^^^ definition local 1 +// ^^^^^^^ definition local 0 return numbers.reduce((value, element) => value + element); -// ^^^^^^^ reference local 1 +// ^^^^^^^ reference local 0 // ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`iterable.dart`/Iterable#reduce(). -// ^^^^^ definition local 2 -// ^^^^^^^ definition local 3 -// ^^^^^ reference local 2 -// ^^^^^^^ reference local 3 +// ^^^^^ definition local 1 +// ^^^^^^^ definition local 2 +// ^^^^^ reference local 1 +// ^^^^^^^ reference local 2 } void main() { @@ -116,52 +115,52 @@ List numbers = [1, 2, 3, 4, 5]; // ^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`list.dart`/List# // ^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`int.dart`/int# -// ^^^^^^^ definition local 4 +// ^^^^^^^ definition local 3 int sum = calculateSum(numbers); // ^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`int.dart`/int# -// ^^^ definition local 5 +// ^^^ definition local 4 // ^^^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/calculateSum(). -// ^^^^^^^ reference local 4 +// ^^^^^^^ reference local 3 Animal cat = Animal('Kitty', type: AnimalType.cat); // ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal# -// ^^^ definition local 6 +// ^^^ 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. Animal dog = Animal('Buddy', type: AnimalType.dog); // ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal# -// ^^^ definition local 7 +// ^^^ 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#``().(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 6 +// ^^^ reference local 5 // ^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#makeSound(). cat.sleep(); -// ^^^ reference local 6 +// ^^^ reference local 5 // ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/SleepMixin#sleep(). dog.makeSound(); -// ^^^ reference local 7 +// ^^^ reference local 6 // ^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/Animal#makeSound(). dog.sleep(); -// ^^^ reference local 7 +// ^^^ reference local 6 // ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/SleepMixin#sleep(). print(cat); // ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). -// ^^^ reference local 6 +// ^^^ reference local 5 print(dog); // ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). -// ^^^ reference local 7 +// ^^^ reference local 6 print('The sum of $numbers is $sum'); // ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). -// ^^^^^^^ reference local 4 -// ^^^ reference local 5 +// ^^^^^^^ reference local 3 +// ^^^ reference local 4 print(math.Rectangle(1,2,3,4)); // ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). @@ -170,19 +169,19 @@ [1,2].reduce((a, b) => a + b); // ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`iterable.dart`/Iterable#reduce(). -// ^ definition local 8 -// ^ definition local 9 -// ^ reference local 8 -// ^ reference local 9 +// ^ definition local 7 +// ^ definition local 8 +// ^ reference local 7 +// ^ reference local 8 } 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 10 +// ^ definition local 9 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 11 +// ^ definition local 10 diff --git a/snapshots/output/basic-project/lib/other.dart b/snapshots/output/basic-project/lib/other.dart index 6e43618f..ae042664 100755 --- a/snapshots/output/basic-project/lib/other.dart +++ b/snapshots/output/basic-project/lib/other.dart @@ -21,7 +21,6 @@ // ^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo# this._far, { // ^^^^ reference local 0 -// ^^^^ definition local 1 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) @@ -42,20 +41,19 @@ // ^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar# String _someValue; // ^^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`string.dart`/String# -// ^^^^^^^^^^ definition local 2 +// ^^^^^^^^^^ 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 2 -// ^^^^^^^^^^ definition local 3 +// ^^^^^^^^^^ reference local 1 void someMethod() { // ^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/`other.dart`/Bar#someMethod(). _someValue = 'asdf'; -// ^^^^^^^^^^ reference local 2 +// ^^^^^^^^^^ reference local 1 print(_someValue); // ^^^^^ reference scip-dart pub dart:core 2.19.0 dart:core/`print.dart`/print(). -// ^^^^^^^^^^ reference local 2 +// ^^^^^^^^^^ reference local 1 } } @@ -64,7 +62,7 @@ more.loadLibrary().then((_) => { // ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/more. // ^^^^ reference scip-dart pub dart:async 2.19.0 dart:async/`future.dart`/Future#then(). -// ^ definition local 4 +// ^ 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#someMethod(). @@ -77,7 +75,7 @@ // ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value. final someStr = 'someStr'; -// ^^^^^^^ definition local 5 +// ^^^^^^^ 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#``().(value) @@ -86,12 +84,12 @@ // ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value. ..value2 = someStr // ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value2. -// ^^^^^^^ reference local 5 +// ^^^^^^^ reference local 3 ..value3 = 2.15; // ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/Foo#value3. more.test((_) => 'val'); // ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`other.dart`/more. // ^^^^ reference scip-dart pub dart_test 1.0.0 lib/`more.dart`/test(). -// ^ definition local 6 +// ^ definition local 4 }