@@ -34,6 +34,72 @@ Future<String> Function(Map<String, Object>) mkEmit(IOSink sink) {
3434 };
3535}
3636
37+ Future <void > withinProject (Future <String > Function (Map <String , Object >) emit,
38+ Future Function () inside) async {
39+ await emit ({
40+ "data" : 'project' ,
41+ "type" : 'vertex' ,
42+ "label" : 'event' ,
43+ "kind" : 'begin' ,
44+ "scope" : 'project' ,
45+ });
46+ await emit ({
47+ "type" : 'vertex' ,
48+ "label" : 'project' ,
49+ "kind" : 'dart' ,
50+ });
51+ await inside ();
52+ await emit ({
53+ "data" : 'project' ,
54+ "type" : 'vertex' ,
55+ "label" : 'event' ,
56+ "kind" : 'end' ,
57+ "scope" : 'project' ,
58+ });
59+ }
60+
61+ Future <void > withinDocuments (
62+ Future <String > Function (Map <String , Object >) emit,
63+ Iterable <String > documents,
64+ Future <List <String >> Function (String ) inside) async {
65+ Map <String , String > docToID = {};
66+ await Future .forEach (documents, (String doc) async {
67+ docToID[doc] = await emit ({
68+ "type" : 'vertex' ,
69+ "label" : 'document' ,
70+ // TODO needs to be relative to project root
71+ "uri" : 'file:///' + doc,
72+ "languageId" : 'dart' ,
73+ });
74+ await emit ({
75+ "data" : docToID[doc],
76+ "type" : 'vertex' ,
77+ "label" : 'event' ,
78+ "kind" : 'begin' ,
79+ "scope" : 'document' ,
80+ });
81+ });
82+ Map <String , List <String >> docToRanges = {};
83+ await Future .forEach (documents, (String doc) async {
84+ docToRanges[doc] = await inside (doc);
85+ });
86+ await Future .forEach (documents, (String doc) async {
87+ await emit ({
88+ "type" : 'edge' ,
89+ "label" : 'contains' ,
90+ "outV" : docToID[doc],
91+ "inVs" : docToRanges[doc],
92+ });
93+ await emit ({
94+ "data" : docToID[doc],
95+ "type" : 'vertex' ,
96+ "label" : 'event' ,
97+ "kind" : 'end' ,
98+ "scope" : 'document' ,
99+ });
100+ });
101+ }
102+
37103class LsifGenerator {
38104 final Environment _environment;
39105 final ParsedData _parsedData;
@@ -47,30 +113,38 @@ class LsifGenerator {
47113 await withIOSink (file, (sink) async {
48114 var emit = mkEmit (sink);
49115 await emit ({
50- "type" : "vertex" ,
51- "label" : "document" ,
52- "uri" : 'lalala' ,
53- "languageId" : 'dart'
116+ "id" : 'meta' ,
117+ "type" : 'vertex' ,
118+ "label" : 'metaData' ,
119+ "projectRoot" : 'file:///' ,
120+ "version" : '0.4.0' ,
121+ "positionEncoding" : 'utf-16' ,
122+ "toolInfo" : {"name" : 'crossdart' , "args" : [], "version" : 'dev' }
54123 });
55- await Future .forEach (_parsedData.files.entries,
56- (MapEntry <String , Set <Entity >> entry) async {
57- var absolutePath = entry.key;
58- var entities = entry.value;
59- await emit ({
60- "type" : "vertex" ,
61- "label" : "document" ,
62- "uri" : 'lalala' ,
63- "languageId" : 'dart'
124+ await withinProject (emit, () async {
125+ await withinDocuments (emit, _parsedData.files.keys, (String doc) async {
126+ await Future .forEach (_parsedData.files.entries,
127+ (MapEntry <String , Set <Entity >> entry) async {
128+ var absolutePath = doc;
129+ var entities = _parsedData.files[doc];
130+ await emit ({
131+ "type" : "vertex" ,
132+ "label" : "document" ,
133+ "uri" : 'lalala' ,
134+ "languageId" : 'dart'
135+ });
136+ // String relativePath = _environment.package is Sdk ?
137+ // entities.first.location.package.relativePath(absolutePath) :
138+ // path.join("lib", entities.first.location.package.relativePath(absolutePath));
139+ // result[relativePath] = {
140+ // "references": _getReferencesValues(pubspecLockPath, entities, _environment.package is Sdk, isForGithub).toList()
141+ // };
142+ // if (isForGithub) {
143+ // result[relativePath]["declarations"] = _getDeclarationsValues(pubspecLockPath, entities, _environment.package is Sdk).toList();
144+ // }
145+ });
146+ return [];
64147 });
65- // String relativePath = _environment.package is Sdk ?
66- // entities.first.location.package.relativePath(absolutePath) :
67- // path.join("lib", entities.first.location.package.relativePath(absolutePath));
68- // result[relativePath] = {
69- // "references": _getReferencesValues(pubspecLockPath, entities, _environment.package is Sdk, isForGithub).toList()
70- // };
71- // if (isForGithub) {
72- // result[relativePath]["declarations"] = _getDeclarationsValues(pubspecLockPath, entities, _environment.package is Sdk).toList();
73- // }
74148 });
75149 });
76150 _logger.info ("Saved LSIF output to ${file .path }" );
0 commit comments