Disambiguous source URI for a Dart declaration?

22 views
Skip to first unread message

Patt O'Brien

unread,
Aug 19, 2024, 11:09:53 PM8/19/24
to Dart Analyzer Discussion
Hi everyone -

Is there a particular URI format that can be used to encode Dart declaration locations? (bonus points if there's a public utility for creating / validating it)

I'm creating a package that creates JSON Schemas from Dart declarations, and want to know the best way to calculate Ref URIs.

I assumed that such a URI would encode the type of the declaration within it (e.g. `MyClass::staticMember` vs. `MyClass.instanceMember`), but when using the analyzer's `element.location.encoding` property, it not only doesn't differentiate, but I actually found it to leave ambiguity, like in the following snippet:

```dart
class MyClass {
MyClass();
factory MyClass.foo() => MyClass(); // my_class.dart;MyClass;foo
String get foo => 'foo'; // my_class.dart;MyClass;foo
}
```
 
I have the following assumptions about what a "good URI" would be for a Dart declaration, and wondering the team's thoughts / if there's anything else I may be missing:
- URIs should be resolved to either `dart` or `package` URIs (relative paths should be converted to `package`
  - this would mean that non `lib` declarations would not be supported, which seems desirable
- declarations should be locatable from just the URI (i.e. without need of a "x-dart-type" property of the schema) - 0 disambiguation

Thanks so much in advance!

Brian Wilkerson

unread,
Aug 20, 2024, 1:19:40 PM8/20/24
to analyzer...@dartlang.org
Is there a particular URI format that can be used to encode Dart declaration locations?

There isn't any native support for this in the `analyzer` package. I can't speak to other packages layered on top of the `analyzer` package.

I will note that `element.location.encoding` is not producing a URI, nor is it intended to be used that way, and we make no guarantees that the result won't change over time.

--
You received this message because you are subscribed to the Google Groups "Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzer-discu...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/analyzer-discuss/b62b828f-2adf-424d-b23e-be10e484e02en%40dartlang.org.
Reply all
Reply to author
Forward
0 new messages