-
Notifications
You must be signed in to change notification settings - Fork 2
FEA-1506: Fixed indexing on field parameters and import prefixes #16
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
Changes from all commits
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.dart_tool | ||
.DS_Store | ||
index.scip | ||
index.scip | ||
snapshots/input/staging-project/lib/** | ||
snapshots/output/staging-project/lib/** |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ class ScipVisitor extends GeneralizingAstVisitor { | |
|
||
@override | ||
void visitNode(AstNode node) { | ||
// print(':: $node ${node.runtimeType}'); | ||
if (node is Comment) { | ||
// For now, don't parse anything within comments (this was broken for | ||
// local references). Later update to support this | ||
|
@@ -55,8 +56,8 @@ class ScipVisitor extends GeneralizingAstVisitor { | |
// to correctly parse all [Declaration] ast nodes. | ||
if (node is Declaration) { | ||
_visitDeclaration(node); | ||
} else if (node is SimpleFormalParameter) { | ||
_visitSimpleFormalParameter(node); | ||
} else if (node is NormalFormalParameter) { | ||
_visitNormalFormalParameter(node); | ||
Comment on lines
+59
to
+60
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.
|
||
} else if (node is SimpleIdentifier) { | ||
_visitSimpleIdentifier(node); | ||
} | ||
|
@@ -68,38 +69,26 @@ class ScipVisitor extends GeneralizingAstVisitor { | |
if (node.declaredElement == null) return; | ||
|
||
final element = node.declaredElement!; | ||
|
||
final symbol = _symbolGenerator.symbolFor(element); | ||
if (symbol != null) { | ||
_registerSymbol(symbol, element); | ||
|
||
occurrences.add(Occurrence( | ||
range: _lineInfo.getRange(element.nameOffset, element.nameLength), | ||
symbol: symbol, | ||
symbolRoles: SymbolRole.Definition.value, | ||
)); | ||
} | ||
_registerAsDefinition(element); | ||
} | ||
|
||
void _visitSimpleFormalParameter(SimpleFormalParameter node) { | ||
if (node.declaredElement == null) return; | ||
|
||
final element = node.declaredElement!; | ||
|
||
final symbol = _symbolGenerator.symbolFor(element); | ||
if (symbol != null) { | ||
_registerSymbol(symbol, element); | ||
|
||
occurrences.add(Occurrence( | ||
range: _lineInfo.getRange(element.nameOffset, element.nameLength), | ||
symbol: symbol, | ||
symbolRoles: SymbolRole.Definition.value, | ||
)); | ||
void _visitNormalFormalParameter(NormalFormalParameter node) { | ||
final element = node.declaredElement; | ||
if (element == null) return; | ||
|
||
// FieldFormalParameters reference a field instead of define a declaration | ||
// register them as such | ||
if (element is FieldFormalParameterElement) { | ||
_registerAsReference( | ||
element.field!, | ||
offset: node.name!.offset, | ||
length: node.name!.length, | ||
); | ||
} else { | ||
_registerAsDefinition(element); | ||
} | ||
} | ||
|
||
// references to a type, String, int, SomeClass... anything that can be GoTo'ed | ||
// This will be utilized for defining `Occurrences` | ||
void _visitSimpleIdentifier(SimpleIdentifier node) { | ||
final element = node.staticElement; | ||
|
||
|
@@ -108,16 +97,40 @@ class ScipVisitor extends GeneralizingAstVisitor { | |
// EX: `color(path, front: Styles.YELLOW);` where `color` comes from the chalk-dart package | ||
if (element == null || element.source == null) return; | ||
|
||
if (node.inDeclarationContext()) { | ||
_registerAsDefinition(element); | ||
} else { | ||
_registerAsReference( | ||
element, | ||
offset: node.offset, | ||
length: node.name.length, | ||
); | ||
} | ||
} | ||
|
||
/// Registers the provided [element] as a reference to an existing definition | ||
/// | ||
/// [node] refers to the ast node where the reference exists, [element] | ||
/// is the resolved element of the downstream element. | ||
/// | ||
/// If [element] exists outside of the projects source, it will be added to the | ||
/// [globalExternalSymbols]. | ||
void _registerAsReference( | ||
Element element, { | ||
required int offset, | ||
required int length, | ||
}) { | ||
final symbol = _symbolGenerator.symbolFor(element); | ||
if (symbol != null) { | ||
occurrences.add(Occurrence( | ||
range: _lineInfo.getRange(node.offset, node.name.length), | ||
range: _lineInfo.getRange(offset, length), | ||
symbol: symbol, | ||
)); | ||
|
||
if (!element.source!.fullName.startsWith(_projectRoot)) { | ||
if (globalExternalSymbols | ||
.every((symbolInfo) => symbolInfo.symbol != symbol)) { | ||
if (!globalExternalSymbols.any( | ||
(symbolInfo) => symbolInfo.symbol == symbol, | ||
)) { | ||
final meta = getSymbolMetadata(element); | ||
globalExternalSymbols.add(SymbolInformation( | ||
symbol: symbol, | ||
|
@@ -128,11 +141,24 @@ class ScipVisitor extends GeneralizingAstVisitor { | |
} | ||
} | ||
|
||
void _registerSymbol(String symbol, Element ele) { | ||
final meta = getSymbolMetadata(ele); | ||
symbols.add(SymbolInformation( | ||
symbol: symbol, | ||
documentation: meta.documentation, | ||
)); | ||
/// Registers a provided [element] as a definition | ||
/// | ||
/// This adds both a symbol, and an occurrence for the element and it's | ||
/// name | ||
void _registerAsDefinition(Element element) { | ||
final symbol = _symbolGenerator.symbolFor(element); | ||
if (symbol != null) { | ||
final meta = getSymbolMetadata(element); | ||
symbols.add(SymbolInformation( | ||
symbol: symbol, | ||
documentation: meta.documentation, | ||
)); | ||
|
||
occurrences.add(Occurrence( | ||
range: _lineInfo.getRange(element.nameOffset, element.nameLength), | ||
symbol: symbol, | ||
symbolRoles: SymbolRole.Definition.value, | ||
)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# snapshots/staging-project | ||
|
||
This project is designed to be used as a place to test/stage small implementations of dart source. No changes within `lib/` are committed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Generated by pub | ||
# See https://dart.dev/tools/pub/glossary#lockfile | ||
packages: {} | ||
sdks: | ||
dart: ">=2.18.0 <3.0.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: dart_test | ||
version: 1.0.0 | ||
|
||
environment: | ||
sdk: ">=2.18.0 <3.0.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import 'dart:math'; | ||
import 'dart:math' as math; | ||
// definition scip-dart pub dart_test 1.0.0 lib/more.dart/ | ||
// ^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/math. | ||
// documentation ```dart | ||
Comment on lines
+1
to
+4
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.
Before, |
||
|
||
enum AnimalType { | ||
// ^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/AnimalType# | ||
|
@@ -51,6 +53,8 @@ | |
// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#<constructor>(). | ||
// documentation ```dart | ||
// ^^^^^^ 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. | ||
Comment on lines
+56
to
+57
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. Main fix in this pr, instead of skipping field parameters, they are indexed These are not private, so they are not considered to be |
||
switch (type) { | ||
// ^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#type. | ||
case AnimalType.cat: | ||
|
@@ -169,5 +173,10 @@ | |
// ^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/print.dart/print(). | ||
// ^^^^^^^ reference local 3 | ||
// ^^^ reference local 4 | ||
|
||
print(math.Rectangle(1,2,3,4)); | ||
// ^^^^^ reference scip-dart pub dart:core 2.18.0 lib/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 lib/math/rectangle.dart/Rectangle# | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ | |
// ^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#<constructor>(). | ||
// documentation ```dart | ||
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo# | ||
// ^^^^ reference local 0 | ||
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. named field parameters are now indexed, this is a |
||
} | ||
|
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.
#nit leftover print