Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions lib/src/symbol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,9 @@ class SymbolGenerator {
}

String _sdkPackageSymbolFor(Element element) {
final path = element.source!.fullName;

final searchPrefix = 'dart-sdk/lib/';
if (!path.contains(searchPrefix)) {
throw Exception('Dart sdk path was not incorrect format: ${path}');
}
final partialPath =
path.substring(path.indexOf(searchPrefix) + searchPrefix.length);
final dependencyName = partialPath.substring(0, partialPath.indexOf('/'));

final packageName = 'dart:$dependencyName';
final packageName = _pathForSdkElement(element).split('/').first;
final packageVersion = element.library!.languageVersion.package.toString();

return 'pub $packageName $packageVersion';
return 'pub ${packageName} $packageVersion';
}

String _currentPackageSymbolFor(Element element) {
Expand Down Expand Up @@ -155,10 +144,8 @@ class SymbolGenerator {
String filePath;
if (sourcePath.startsWith(_projectRoot)) {
filePath = sourcePath.substring('${_projectRoot}/'.length);
} else if (element.library?.isInSdk == true) {
// TODO: there has to be a better way to get the path to a 'dart:*' file
filePath = sourcePath
.substring(sourcePath.indexOf('dart-sdk/lib/') + 'dart-sdk/'.length);
} else if (_isInSdk(element)) {
filePath = _pathForSdkElement(element);
} else {
final config = _packageConfig.packageOf(Uri.file(sourcePath));
if (config == null) {
Expand Down Expand Up @@ -257,6 +244,15 @@ class SymbolGenerator {
return element.library?.isInSdk == true;
}

String _pathForSdkElement(Element element) {
if (element.enclosingElement?.source?.uri != null) {
return element.enclosingElement!.source!.uri.toString();
} else {
throw Exception(
'Unable to find path to dart sdk element: ${element.source!.fullName}');
}
}

bool _isInCurrentPackage(Element element) {
return element.source!.fullName.startsWith(_projectRoot);
}
Expand Down
12 changes: 6 additions & 6 deletions snapshots/output/basic-project/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
/// Takes a number
/// Returns a number
int fib(int n) {
//^^^ reference scip-dart pub dart:core 2.18.0 lib/core/int.dart/int#
//^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
// ^^^ definition scip-dart pub dart_test 1.0.0 lib/main.dart/fib().
// documentation ```dart
// documentation This is a fib function
// ^^^ reference scip-dart pub dart:core 2.18.0 lib/core/int.dart/int#
// ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
// ^ definition local 0
// documentation ```dart
if (n <= 1) return 0;
Expand All @@ -23,11 +23,11 @@
void print_fib(int a) {
// ^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/main.dart/print_fib().
// documentation ```dart
// ^^^ reference scip-dart pub dart:core 2.18.0 lib/core/int.dart/int#
// ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
// ^ definition local 1
// documentation ```dart
print(fib(a));
// ^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/print.dart/print().
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/main.dart/fib().
// ^ reference local 1
}
Expand All @@ -36,7 +36,7 @@
// ^ definition scip-dart pub dart_test 1.0.0 lib/main.dart/y.
// documentation ```dart
String capture() {
//^^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/string.dart/String#
//^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String#
// ^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/main.dart/capture().
// documentation ```dart
return y;
Expand All @@ -61,7 +61,7 @@
// ^ definition local 3
// documentation ```dart
print(i);
// ^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/print.dart/print().
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
// ^ reference local 3
}

Expand Down
40 changes: 20 additions & 20 deletions snapshots/output/basic-project/lib/more.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// ^^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/SleepMixin#sleep().
// documentation ```dart
print('zzz...');
// ^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/print.dart/print().
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
}
}

Expand All @@ -37,7 +37,7 @@
// documentation ```dart
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/SleepMixin#
String name;
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/string.dart/String#
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String#
// ^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#name.
// documentation ```dart
AnimalType type;
Expand All @@ -61,23 +61,23 @@
// ^^^^^^^^^^ 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:core 2.18.0 lib/core/print.dart/print().
// ^^^^^ reference scip-dart pub dart:core 2.18.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:core 2.18.0 lib/core/print.dart/print().
// ^^^^^ reference scip-dart pub dart:core 2.18.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:core 2.18.0 lib/core/print.dart/print().
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
break;
default:
soundMaker = () => print('Unknown animal type');
// ^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/print.dart/print().
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
}
}

Expand All @@ -89,9 +89,9 @@
}

@override
// ^^^^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/annotations.dart/override.
// ^^^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/annotations.dart/override.
String toString() {
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/string.dart/String#
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String#
// ^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/Animal#toString().
// documentation ```dart
return '$name the $type';
Expand All @@ -101,16 +101,16 @@
}

int calculateSum(List<int> numbers) {
//^^^ reference scip-dart pub dart:core 2.18.0 lib/core/int.dart/int#
//^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
// ^^^^^^^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/calculateSum().
// documentation ```dart
// ^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/list.dart/List#
// ^^^ reference scip-dart pub dart:core 2.18.0 lib/core/int.dart/int#
// ^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/list.dart/List#
// ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
// ^^^^^^^ definition local 0
// documentation ```dart
return numbers.reduce((value, element) => value + element);
// ^^^^^^^ reference local 0
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/iterable.dart/Iterable#reduce().
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/iterable.dart/Iterable#reduce().
// ^^^^^ definition local 1
// documentation ```dart
// ^^^^^^^ definition local 2
Expand All @@ -123,12 +123,12 @@
// ^^^^ definition scip-dart pub dart_test 1.0.0 lib/more.dart/main().
// documentation ```dart
List<int> numbers = [1, 2, 3, 4, 5];
// ^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/list.dart/List#
// ^^^ reference scip-dart pub dart:core 2.18.0 lib/core/int.dart/int#
// ^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/list.dart/List#
// ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
// ^^^^^^^ definition local 3
// documentation ```dart
int sum = calculateSum(numbers);
// ^^^ reference scip-dart pub dart:core 2.18.0 lib/core/int.dart/int#
// ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
// ^^^ definition local 4
// documentation ```dart
// ^^^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/calculateSum().
Expand Down Expand Up @@ -164,19 +164,19 @@
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/more.dart/SleepMixin#sleep().

print(cat);
// ^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/print.dart/print().
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
// ^^^ reference local 5
print(dog);
// ^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/print.dart/print().
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/print.dart/print().
// ^^^ reference local 6
print('The sum of $numbers is $sum');
// ^^^^^ reference scip-dart pub dart:core 2.18.0 lib/core/print.dart/print().
// ^^^^^ reference scip-dart pub dart:core 2.18.0 dart: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: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 lib/math/rectangle.dart/Rectangle#
// ^^^^^^^^^ reference scip-dart pub dart:math 2.18.0 dart:math/rectangle.dart/Rectangle#
}

2 changes: 1 addition & 1 deletion snapshots/output/basic-project/lib/other.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#
// documentation ```dart
int _far;
// ^^^ reference scip-dart pub dart:core 2.18.0 lib/core/int.dart/int#
// ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
// ^^^^ definition local 0
// documentation ```dart
Foo(this._far);
Expand Down