From 1120f49b5aa22184b1c48517b5dd6b320fb2c873 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Mon, 28 Aug 2023 20:52:55 -0600 Subject: [PATCH 1/6] fixed functions as parameters --- .vscode/launch.json | 15 +++++++++++++++ lib/src/scip_visitor.dart | 7 +++++++ pubspec.lock | 8 ++++---- 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..e56f8a18 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "scip-dart", + "request": "launch", + "program": "bin/scip_dart.dart", + "type": "dart", + "args": ["./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 d3002ee2..d064dbf8 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -79,6 +79,12 @@ class ScipVisitor extends GeneralizingAstVisitor { final element = node.declaredElement; if (element == null) return; + // if this parameter is a child of another parameter (usually a function + // parameter), don't register it as a declaration, it's references will be + // registered in [_visitSimpleIdentifier] + final parentParameter = node.parent?.thisOrAncestorOfType(); + if (parentParameter != null) return; + if (node is FieldFormalParameter) { final fieldElement = (element as FieldFormalParameterElement).field; _registerAsReference( @@ -146,6 +152,7 @@ class ScipVisitor extends GeneralizingAstVisitor { required int offset, required int length, }) { + final symbol = _symbolGenerator.symbolFor(element); if (symbol != null) { occurrences.add(Occurrence( diff --git a/pubspec.lock b/pubspec.lock index d3c0cd6e..ecdf8539 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,21 +7,21 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "61.0.0" + version: "54.0.0" analyzer: dependency: "direct main" description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "5.13.0" + version: "5.6.0" args: dependency: "direct main" description: name: args url: "https://pub.dartlang.org" source: hosted - version: "2.4.2" + version: "2.4.1" async: dependency: transitive description: @@ -175,7 +175,7 @@ packages: name: glob url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.1.1" graphs: dependency: transitive description: From eb5f3714c06cd88f74c4506948157e27631aaa52 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Mon, 28 Aug 2023 20:56:30 -0600 Subject: [PATCH 2/6] dependabot changes --- .github/dependabot.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 178c5879..57cb375a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,6 +1,7 @@ version: 2 updates: - - package-ecosystem: "pub" - directory: "/" + - package-ecosystem: pub + versioning-strategy: increase + directory: / schedule: - interval: "weekly" \ No newline at end of file + interval: weekly \ No newline at end of file From 44f9c243131922b66e6d1e6910642df048d4bc83 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Mon, 28 Aug 2023 20:57:11 -0600 Subject: [PATCH 3/6] fmt --- lib/src/scip_visitor.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index d064dbf8..2950ab95 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -82,7 +82,8 @@ class ScipVisitor extends GeneralizingAstVisitor { // if this parameter is a child of another parameter (usually a function // parameter), don't register it as a declaration, it's references will be // registered in [_visitSimpleIdentifier] - final parentParameter = node.parent?.thisOrAncestorOfType(); + final parentParameter = + node.parent?.thisOrAncestorOfType(); if (parentParameter != null) return; if (node is FieldFormalParameter) { @@ -152,7 +153,6 @@ class ScipVisitor extends GeneralizingAstVisitor { required int offset, required int length, }) { - final symbol = _symbolGenerator.symbolFor(element); if (symbol != null) { occurrences.add(Occurrence( From 796d0b6b09fe7aef8a970b85eaeedb739b184dd8 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Mon, 28 Aug 2023 21:39:05 -0600 Subject: [PATCH 4/6] fixed edge case of other identifiers --- lib/src/scip_visitor.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index 2950ab95..f080764b 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -79,11 +79,12 @@ class ScipVisitor extends GeneralizingAstVisitor { final element = node.declaredElement; if (element == null) return; - // if this parameter is a child of another parameter (usually a function - // parameter), don't register it as a declaration, it's references will be - // registered in [_visitSimpleIdentifier] + // 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(); + node.parent?.thisOrAncestorOfType(); if (parentParameter != null) return; if (node is FieldFormalParameter) { From 152e8ca19a5e83b8417cc7756778e9b7f4824af5 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Mon, 28 Aug 2023 22:06:27 -0600 Subject: [PATCH 5/6] regen --- snapshots/input/basic-project/lib/more.dart | 5 ++++ snapshots/output/basic-project/lib/more.dart | 28 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/snapshots/input/basic-project/lib/more.dart b/snapshots/input/basic-project/lib/more.dart index 371f09f6..c1b2bd62 100644 --- a/snapshots/input/basic-project/lib/more.dart +++ b/snapshots/input/basic-project/lib/more.dart @@ -67,4 +67,9 @@ void main() { print('The sum of $numbers is $sum'); print(math.Rectangle(1,2,3,4)); + + [1,2].reduce((a, b) => a + b); } + +void test(String Function(int)) {} +void deepTest(String Function(void Function(String test))) {} \ 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 94af943f..008fc21e 100755 --- a/snapshots/output/basic-project/lib/more.dart +++ b/snapshots/output/basic-project/lib/more.dart @@ -188,5 +188,33 @@ // ^^^^^ reference scip-dart pub dart:core 2.18.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.18.0 dart:math/rectangle.dart/Rectangle# + + [1,2].reduce((a, b) => a + b); +// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/iterable.dart/Iterable#reduce(). +// ^ definition local 8 +// documentation ```dart +// ^ definition local 9 +// documentation ```dart +// ^ reference local 8 +// ^ reference local 9 } + void test(String Function(int)) {} +// ^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/test(). +// documentation ```dart +// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# +// ^^^^^^^^ definition local 10 +// documentation ```dart +// ^^^ definition local 11 +// documentation ```dart + void deepTest(String Function(void Function(String test))) {} +// ^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/deepTest(). +// documentation ```dart +// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# +// ^^^^^^^^ definition local 12 +// documentation ```dart +// ^^^^^^^^ definition local 13 +// documentation ```dart +// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# +// ^^^^ definition local 14 +// documentation ```dart From a2b1da0b623148fa58909425087e13af99836f2c Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Mon, 28 Aug 2023 22:07:53 -0600 Subject: [PATCH 6/6] named params --- snapshots/input/basic-project/lib/more.dart | 4 ++-- snapshots/output/basic-project/lib/more.dart | 19 +++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/snapshots/input/basic-project/lib/more.dart b/snapshots/input/basic-project/lib/more.dart index c1b2bd62..7b57fcde 100644 --- a/snapshots/input/basic-project/lib/more.dart +++ b/snapshots/input/basic-project/lib/more.dart @@ -71,5 +71,5 @@ void main() { [1,2].reduce((a, b) => a + b); } -void test(String Function(int)) {} -void deepTest(String Function(void Function(String test))) {} \ No newline at end of file +void test(String Function(int) p) {} +void deepTest(String Function(void Function(String test)) p) {} \ 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 008fc21e..7de9ef01 100755 --- a/snapshots/output/basic-project/lib/more.dart +++ b/snapshots/output/basic-project/lib/more.dart @@ -199,22 +199,17 @@ // ^ reference local 9 } - void test(String Function(int)) {} + void test(String Function(int) p) {} // ^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/test(). // documentation ```dart // ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# -// ^^^^^^^^ definition local 10 -// documentation ```dart -// ^^^ definition local 11 -// documentation ```dart - void deepTest(String Function(void Function(String test))) {} +// ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int# +// ^ definition local 10 +// documentation ```dart + void deepTest(String Function(void Function(String test)) p) {} // ^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/deepTest(). // documentation ```dart // ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# -// ^^^^^^^^ definition local 12 -// documentation ```dart -// ^^^^^^^^ definition local 13 -// documentation ```dart // ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# -// ^^^^ definition local 14 -// documentation ```dart +// ^ definition local 11 +// documentation ```dart