Skip to content

Commit

Permalink
Save uris
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Jun 19, 2024
1 parent 484e2b3 commit d4135a0
Show file tree
Hide file tree
Showing 14 changed files with 613 additions and 309 deletions.
48 changes: 42 additions & 6 deletions pkgs/record_use/lib/src/data_classes/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ extension UsagesExt on pb.Usages {

pb_storage.Usages _toStorage() {
final usageList = [...calls, ...instances];
final definitions =
usageList.map((usage) => usage.definition).toSet().toList();
final uris = usageList
.expand((usage) => [
usage.definition.identifier.uri,
...usage.references.map((reference) => reference.location.uri)
])
.toSet()
.toList();
final definitions = usageList
.map((usage) => usage.definition.toStorage(uris))
.toSet()
.toList();
return pb_storage.Usages(
metadata: metadata,
definitions: definitions,
Expand All @@ -38,9 +40,9 @@ extension UsagesExt on pb.Usages {

extension UsageExt on pb.Usage {
pb_storage.Usage toStorage(
List<pb_shared.Definition> definitions, List<String> uris) =>
List<pb_storage.Definition> definitions, List<String> uris) =>
pb_storage.Usage(
definition: definitions.indexOf(definition),
definition: definitions.indexOf(definition.toStorage(uris)),
references: references.map((e) => e.toStorage(uris)),
);
}
Expand All @@ -62,6 +64,23 @@ extension LocationExt on pb.Location {
);
}

extension DefinitionExt on pb.Definition {
pb_storage.Definition toStorage(List<String> uris) => pb_storage.Definition(
identifier: identifier.toStorage(uris),
column: column,
line: line,
loadingUnit: hasLoadingUnit() ? loadingUnit : null,
);
}

extension IdentifierExt on pb.Identifier {
pb_storage.Identifier toStorage(List<String> uris) => pb_storage.Identifier(
name: name,
parent: hasParent() ? parent : null,
uri: uris.indexOf(uri),
);
}

extension UsagesStorageExt on pb_storage.Usages {
pb.Usages toApi() => pb.Usages(
metadata: metadata,
Expand All @@ -71,9 +90,9 @@ extension UsagesStorageExt on pb_storage.Usages {
}

extension UsageStorageExt on pb_storage.Usage {
pb.Usage toApi(List<pb_shared.Definition> definitions, List<String> uris) =>
pb.Usage toApi(List<pb_storage.Definition> definitions, List<String> uris) =>
pb.Usage(
definition: definitions[definition],
definition: definitions[definition].toApi(uris),
references: references.map((e) => e.toApi(uris)),
);
}
Expand All @@ -95,6 +114,23 @@ extension LocationStorageExt on pb_storage.Location {
);
}

extension DefinitionStorageExt on pb_storage.Definition {
pb.Definition toApi(List<String> uris) => pb.Definition(
identifier: identifier.toApi(uris),
column: column,
line: line,
loadingUnit: hasLoadingUnit() ? loadingUnit : null,
);
}

extension IdentifierStorageExt on pb_storage.Identifier {
pb.Identifier toApi(List<String> uris) => pb.Identifier(
name: name,
parent: hasParent() ? parent : null,
uri: uris[uri],
);
}

extension FieldValueExt on pb_shared.FieldValue {
Object toObject() => switch (whichValue()) {
pb_shared.FieldValue_Value.intValue => intValue,
Expand Down
218 changes: 212 additions & 6 deletions pkgs/record_use/lib/src/proto/usages_read.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Usages extends $pb.GeneratedMessage {

class Usage extends $pb.GeneratedMessage {
factory Usage({
$0.Definition? definition,
Definition? definition,
$core.Iterable<Reference>? references,
}) {
final $result = create();
Expand All @@ -121,8 +121,8 @@ class Usage extends $pb.GeneratedMessage {
_omitMessageNames ? '' : 'Usage',
package: const $pb.PackageName(_omitMessageNames ? '' : 'usages'),
createEmptyInstance: create)
..aOM<$0.Definition>(1, _omitFieldNames ? '' : 'definition',
subBuilder: $0.Definition.create)
..aOM<Definition>(1, _omitFieldNames ? '' : 'definition',
subBuilder: Definition.create)
..pc<Reference>(2, _omitFieldNames ? '' : 'references', $pb.PbFieldType.PM,
subBuilder: Reference.create)
..hasRequiredFields = false;
Expand All @@ -149,9 +149,9 @@ class Usage extends $pb.GeneratedMessage {
static Usage? _defaultInstance;

@$pb.TagNumber(1)
$0.Definition get definition => $_getN(0);
Definition get definition => $_getN(0);
@$pb.TagNumber(1)
set definition($0.Definition v) {
set definition(Definition v) {
setField(1, v);
}

Expand All @@ -160,7 +160,7 @@ class Usage extends $pb.GeneratedMessage {
@$pb.TagNumber(1)
void clearDefinition() => clearField(1);
@$pb.TagNumber(1)
$0.Definition ensureDefinition() => $_ensure(0);
Definition ensureDefinition() => $_ensure(0);

@$pb.TagNumber(2)
$core.List<Reference> get references => $_getList(1);
Expand Down Expand Up @@ -391,6 +391,212 @@ class Reference extends $pb.GeneratedMessage {
$0.Fields ensureFields() => $_ensure(3);
}

class Definition extends $pb.GeneratedMessage {
factory Definition({
Identifier? identifier,
$core.int? line,
$core.int? column,
$core.String? loadingUnit,
}) {
final $result = create();
if (identifier != null) {
$result.identifier = identifier;
}
if (line != null) {
$result.line = line;
}
if (column != null) {
$result.column = column;
}
if (loadingUnit != null) {
$result.loadingUnit = loadingUnit;
}
return $result;
}
Definition._() : super();
factory Definition.fromBuffer($core.List<$core.int> i,
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
create()..mergeFromBuffer(i, r);
factory Definition.fromJson($core.String i,
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
create()..mergeFromJson(i, r);

static final $pb.BuilderInfo _i = $pb.BuilderInfo(
_omitMessageNames ? '' : 'Definition',
package: const $pb.PackageName(_omitMessageNames ? '' : 'usages'),
createEmptyInstance: create)
..aOM<Identifier>(1, _omitFieldNames ? '' : 'identifier',
subBuilder: Identifier.create)
..a<$core.int>(2, _omitFieldNames ? '' : 'line', $pb.PbFieldType.OU3)
..a<$core.int>(3, _omitFieldNames ? '' : 'column', $pb.PbFieldType.OU3)
..aOS(4, _omitFieldNames ? '' : 'loadingUnit')
..hasRequiredFields = false;

@$core.Deprecated('Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
Definition clone() => Definition()..mergeFromMessage(this);
@$core.Deprecated('Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
Definition copyWith(void Function(Definition) updates) =>
super.copyWith((message) => updates(message as Definition)) as Definition;

$pb.BuilderInfo get info_ => _i;

@$core.pragma('dart2js:noInline')
static Definition create() => Definition._();
Definition createEmptyInstance() => create();
static $pb.PbList<Definition> createRepeated() => $pb.PbList<Definition>();
@$core.pragma('dart2js:noInline')
static Definition getDefault() => _defaultInstance ??=
$pb.GeneratedMessage.$_defaultFor<Definition>(create);
static Definition? _defaultInstance;

@$pb.TagNumber(1)
Identifier get identifier => $_getN(0);
@$pb.TagNumber(1)
set identifier(Identifier v) {
setField(1, v);
}

@$pb.TagNumber(1)
$core.bool hasIdentifier() => $_has(0);
@$pb.TagNumber(1)
void clearIdentifier() => clearField(1);
@$pb.TagNumber(1)
Identifier ensureIdentifier() => $_ensure(0);

@$pb.TagNumber(2)
$core.int get line => $_getIZ(1);
@$pb.TagNumber(2)
set line($core.int v) {
$_setUnsignedInt32(1, v);
}

@$pb.TagNumber(2)
$core.bool hasLine() => $_has(1);
@$pb.TagNumber(2)
void clearLine() => clearField(2);

@$pb.TagNumber(3)
$core.int get column => $_getIZ(2);
@$pb.TagNumber(3)
set column($core.int v) {
$_setUnsignedInt32(2, v);
}

@$pb.TagNumber(3)
$core.bool hasColumn() => $_has(2);
@$pb.TagNumber(3)
void clearColumn() => clearField(3);

@$pb.TagNumber(4)
$core.String get loadingUnit => $_getSZ(3);
@$pb.TagNumber(4)
set loadingUnit($core.String v) {
$_setString(3, v);
}

@$pb.TagNumber(4)
$core.bool hasLoadingUnit() => $_has(3);
@$pb.TagNumber(4)
void clearLoadingUnit() => clearField(4);
}

class Identifier extends $pb.GeneratedMessage {
factory Identifier({
$core.String? uri,
$core.String? parent,
$core.String? name,
}) {
final $result = create();
if (uri != null) {
$result.uri = uri;
}
if (parent != null) {
$result.parent = parent;
}
if (name != null) {
$result.name = name;
}
return $result;
}
Identifier._() : super();
factory Identifier.fromBuffer($core.List<$core.int> i,
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
create()..mergeFromBuffer(i, r);
factory Identifier.fromJson($core.String i,
[$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) =>
create()..mergeFromJson(i, r);

static final $pb.BuilderInfo _i = $pb.BuilderInfo(
_omitMessageNames ? '' : 'Identifier',
package: const $pb.PackageName(_omitMessageNames ? '' : 'usages'),
createEmptyInstance: create)
..aOS(1, _omitFieldNames ? '' : 'uri')
..aOS(2, _omitFieldNames ? '' : 'parent')
..aOS(3, _omitFieldNames ? '' : 'name')
..hasRequiredFields = false;

@$core.Deprecated('Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
Identifier clone() => Identifier()..mergeFromMessage(this);
@$core.Deprecated('Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
Identifier copyWith(void Function(Identifier) updates) =>
super.copyWith((message) => updates(message as Identifier)) as Identifier;

$pb.BuilderInfo get info_ => _i;

@$core.pragma('dart2js:noInline')
static Identifier create() => Identifier._();
Identifier createEmptyInstance() => create();
static $pb.PbList<Identifier> createRepeated() => $pb.PbList<Identifier>();
@$core.pragma('dart2js:noInline')
static Identifier getDefault() => _defaultInstance ??=
$pb.GeneratedMessage.$_defaultFor<Identifier>(create);
static Identifier? _defaultInstance;

@$pb.TagNumber(1)
$core.String get uri => $_getSZ(0);
@$pb.TagNumber(1)
set uri($core.String v) {
$_setString(0, v);
}

@$pb.TagNumber(1)
$core.bool hasUri() => $_has(0);
@$pb.TagNumber(1)
void clearUri() => clearField(1);

@$pb.TagNumber(2)
$core.String get parent => $_getSZ(1);
@$pb.TagNumber(2)
set parent($core.String v) {
$_setString(1, v);
}

@$pb.TagNumber(2)
$core.bool hasParent() => $_has(1);
@$pb.TagNumber(2)
void clearParent() => clearField(2);

@$pb.TagNumber(3)
$core.String get name => $_getSZ(2);
@$pb.TagNumber(3)
set name($core.String v) {
$_setString(2, v);
}

@$pb.TagNumber(3)
$core.bool hasName() => $_has(2);
@$pb.TagNumber(3)
void clearName() => clearField(3);
}

const _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names');
const _omitMessageNames =
$core.bool.fromEnvironment('protobuf.omit_message_names');
Loading

0 comments on commit d4135a0

Please sign in to comment.