From a07adb984f149a1fc191a07c6c86746a338b266e Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Tue, 15 Aug 2023 11:18:31 -0600 Subject: [PATCH 1/8] fixed issues with cascade references --- lib/src/scip_visitor.dart | 8 +++++--- snapshots/input/basic-project/lib/other.dart | 3 +++ snapshots/output/basic-project/lib/other.dart | 8 ++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index d3002ee..a26fcda 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -107,9 +107,11 @@ class ScipVisitor extends GeneralizingAstVisitor { // 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 (node.parent is CompoundAssignmentExpression) { - final assignmentNode = node.parent as CompoundAssignmentExpression; - element = assignmentNode.readElement ?? assignmentNode.writeElement; + 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/ diff --git a/snapshots/input/basic-project/lib/other.dart b/snapshots/input/basic-project/lib/other.dart index fb31e52..144ad73 100644 --- a/snapshots/input/basic-project/lib/other.dart +++ b/snapshots/input/basic-project/lib/other.dart @@ -2,6 +2,7 @@ import 'more.dart' deferred as more; class Foo { int _far; + bool value; Foo(this._far); } @@ -19,4 +20,6 @@ void main() { more.loadLibrary().then((_) => { Bar('a').someMethod.call() }); + + Foo()..value = false } \ No newline at end of file diff --git a/snapshots/output/basic-project/lib/other.dart b/snapshots/output/basic-project/lib/other.dart index d8eadfe..145c281 100755 --- a/snapshots/output/basic-project/lib/other.dart +++ b/snapshots/output/basic-project/lib/other.dart @@ -10,6 +10,10 @@ // ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int# // ^^^^ definition local 0 // documentation ```dart + bool value; +// ^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/bool.dart/bool# +// ^^^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value. +// documentation ```dart Foo(this._far); // ^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#(). // documentation ```dart @@ -57,4 +61,8 @@ // ^^^ 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()..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#value. } From 43898cdc9f905669c20a2276ec6892a9e7cf5d0d Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Tue, 15 Aug 2023 11:24:13 -0600 Subject: [PATCH 2/8] fmt --- lib/src/scip_visitor.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index a26fcda..b9d2df2 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -108,7 +108,8 @@ class ScipVisitor extends GeneralizingAstVisitor { // 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(); + final assignmentExpr = + node.thisOrAncestorOfType(); if (assignmentExpr == null) return; element = assignmentExpr.readElement ?? assignmentExpr.writeElement; From eb0359516e2c3aa420a2beecb81855c5d75e21bb Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Tue, 15 Aug 2023 15:05:47 -0600 Subject: [PATCH 3/8] fixed issues where .dart_tool symbols were erroring --- lib/src/scip_visitor.dart | 40 +++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index b9d2df2..7f27c5b 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -10,6 +10,7 @@ import 'package:scip_dart/src/gen/scip.pb.dart'; import 'package:scip_dart/src/relationship_generator.dart'; import 'package:scip_dart/src/symbol_generator.dart'; import 'package:scip_dart/src/utils.dart'; +import 'package:path/path.dart' as p; List globalExternalSymbols = []; @@ -156,16 +157,12 @@ class ScipVisitor extends GeneralizingAstVisitor { symbol: symbol, )); - if (!element.source!.fullName.startsWith(_projectRoot)) { - if (!globalExternalSymbols.any( - (symbolInfo) => symbolInfo.symbol == symbol, - )) { - final meta = getSymbolMetadata(element); - globalExternalSymbols.add(SymbolInformation( - symbol: symbol, - documentation: meta.documentation, - )); - } + if (_shouldRegisterAsExternalSymbol(element, symbol)) { + final meta = getSymbolMetadata(element); + globalExternalSymbols.add(SymbolInformation( + symbol: symbol, + documentation: meta.documentation, + )); } } } @@ -194,4 +191,27 @@ class ScipVisitor extends GeneralizingAstVisitor { )); } } + + /// Whether or not the provided [element] and it's correlating [symbol] + /// should be considered an "external" symbol. + bool _shouldRegisterAsExternalSymbol(Element element, String symbol) { + // local symbols cannot be considered "external", since they are local. + final isLocalSymbol = symbol.startsWith('local'); + if (isLocalSymbol) return false; + + // anything within .dart_tool is rarely committed, but can be referenced + // within the codebase. Consider these "external" entities. + // + // if the element is within the project, it also, cannot be external + // and should have a correlating definition + final source = element.source!.fullName; + final isInDartTool = source.startsWith(p.join(_projectRoot, '.dart_tool')); + final isInProject = source.startsWith(_projectRoot); + if (isInDartTool || !isInProject) return false; + + // check if the symbol already has been added to the global symbols + if (globalExternalSymbols.any((s) => s.symbol == symbol)) return false; + + return true; + } } From 7bfebc40fdaa20fb014aecaed3cf50ba3b0e2574 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 17 Aug 2023 22:41:35 -0600 Subject: [PATCH 4/8] fixed error in logic --- lib/src/scip_visitor.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index 7f27c5b..cbcb238 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -207,7 +207,7 @@ class ScipVisitor extends GeneralizingAstVisitor { final source = element.source!.fullName; final isInDartTool = source.startsWith(p.join(_projectRoot, '.dart_tool')); final isInProject = source.startsWith(_projectRoot); - if (isInDartTool || !isInProject) return false; + if (isInDartTool || isInProject) return false; // check if the symbol already has been added to the global symbols if (globalExternalSymbols.any((s) => s.symbol == symbol)) return false; From 8036375651b4a1865df8f1dd55fc349e40f23c53 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 17 Aug 2023 22:42:05 -0600 Subject: [PATCH 5/8] fixed logic again --- lib/src/scip_visitor.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index cbcb238..9541d98 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -207,7 +207,7 @@ class ScipVisitor extends GeneralizingAstVisitor { final source = element.source!.fullName; final isInDartTool = source.startsWith(p.join(_projectRoot, '.dart_tool')); final isInProject = source.startsWith(_projectRoot); - if (isInDartTool || isInProject) return false; + if (!isInDartTool || isInProject) return false; // check if the symbol already has been added to the global symbols if (globalExternalSymbols.any((s) => s.symbol == symbol)) return false; From c5b4efb2c8dfdaa87b5b93861068ef5be68b5efc Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 31 Aug 2023 17:52:55 -0600 Subject: [PATCH 6/8] removed out of scope change --- lib/src/scip_visitor.dart | 42 ++++++++++----------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index 4794ba0..f744b6a 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -10,7 +10,6 @@ import 'package:scip_dart/src/gen/scip.pb.dart'; import 'package:scip_dart/src/relationship_generator.dart'; import 'package:scip_dart/src/symbol_generator.dart'; import 'package:scip_dart/src/utils.dart'; -import 'package:path/path.dart' as p; List globalExternalSymbols = []; @@ -165,12 +164,16 @@ class ScipVisitor extends GeneralizingAstVisitor { symbol: symbol, )); - if (_shouldRegisterAsExternalSymbol(element, symbol)) { - final meta = getSymbolMetadata(element); - globalExternalSymbols.add(SymbolInformation( - symbol: symbol, - documentation: meta.documentation, - )); + if (!element.source!.fullName.startsWith(_projectRoot)) { + if (!globalExternalSymbols.any( + (symbolInfo) => symbolInfo.symbol == symbol, + )) { + final meta = getSymbolMetadata(element); + globalExternalSymbols.add(SymbolInformation( + symbol: symbol, + documentation: meta.documentation, + )); + } } } } @@ -199,27 +202,4 @@ class ScipVisitor extends GeneralizingAstVisitor { )); } } - - /// Whether or not the provided [element] and it's correlating [symbol] - /// should be considered an "external" symbol. - bool _shouldRegisterAsExternalSymbol(Element element, String symbol) { - // local symbols cannot be considered "external", since they are local. - final isLocalSymbol = symbol.startsWith('local'); - if (isLocalSymbol) return false; - - // anything within .dart_tool is rarely committed, but can be referenced - // within the codebase. Consider these "external" entities. - // - // if the element is within the project, it also, cannot be external - // and should have a correlating definition - final source = element.source!.fullName; - final isInDartTool = source.startsWith(p.join(_projectRoot, '.dart_tool')); - final isInProject = source.startsWith(_projectRoot); - if (!isInDartTool || isInProject) return false; - - // check if the symbol already has been added to the global symbols - if (globalExternalSymbols.any((s) => s.symbol == symbol)) return false; - - return true; - } -} +} \ No newline at end of file From 817934473bc2f5f5a158faf228bd06225f8c4451 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 31 Aug 2023 17:53:26 -0600 Subject: [PATCH 7/8] fmt --- lib/src/scip_visitor.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index f744b6a..ce5fcbf 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -202,4 +202,4 @@ class ScipVisitor extends GeneralizingAstVisitor { )); } } -} \ No newline at end of file +} From d533b6b28bc2864518895b7a1d40c257affce927 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Thu, 31 Aug 2023 17:54:57 -0600 Subject: [PATCH 8/8] regen snaps --- snapshots/input/basic-project/lib/other.dart | 10 +++++++- snapshots/output/basic-project/lib/other.dart | 23 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/snapshots/input/basic-project/lib/other.dart b/snapshots/input/basic-project/lib/other.dart index 144ad73..36a9d4c 100644 --- a/snapshots/input/basic-project/lib/other.dart +++ b/snapshots/input/basic-project/lib/other.dart @@ -3,6 +3,8 @@ import 'more.dart' deferred as more; class Foo { int _far; bool value; + String value2; + double value3; Foo(this._far); } @@ -21,5 +23,11 @@ void main() { Bar('a').someMethod.call() }); - Foo()..value = false + Foo()..value = false; + + final someStr = 'someStr'; + Foo() + ..value = true + ..value2 = someStr + ..value3 = 2.15 } \ No newline at end of file diff --git a/snapshots/output/basic-project/lib/other.dart b/snapshots/output/basic-project/lib/other.dart index 145c281..7d0b3d3 100755 --- a/snapshots/output/basic-project/lib/other.dart +++ b/snapshots/output/basic-project/lib/other.dart @@ -14,6 +14,14 @@ // ^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/bool.dart/bool# // ^^^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value. // documentation ```dart + String value2; +// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String# +// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value2. +// documentation ```dart + double value3; +// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/double.dart/double# +// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value3. +// documentation ```dart Foo(this._far); // ^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#(). // documentation ```dart @@ -62,7 +70,20 @@ // ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Bar#someMethod(). }); - Foo()..value = false + Foo()..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#value. + + final someStr = 'someStr'; +// ^^^^^^^ definition local 5 +// documentation ```dart + Foo() +// ^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo# + ..value = true +// ^^^^^ 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 + ..value3 = 2.15 +// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value3. }