@@ -54,6 +54,8 @@ our enum MessageType is export <
5454 MT_HandleEquivalenceResponse
5555 MT_HLLSymbolRequest
5656 MT_HLLSymbolResponse
57+ MT_LoadedFilesRequest
58+ MT_FileLoadedNotification
5759> ;
5860
5961class X::MoarVM::Remote::ProtocolError is Exception {
@@ -118,6 +120,9 @@ class MoarVM::Remote {
118120
119121 has % ! breakpoint-to-event {Any };
120122
123+ has Lock $ ! filenames-lock .= new ;
124+ has @ ! filenames ;
125+
121126 has Lock $ ! id-lock .= new ;
122127 has int32 $ ! req_id = 1 ;
123128
@@ -411,6 +416,33 @@ class MoarVM::Remote {
411416 })
412417 }
413418
419+ method get-filenames () {
420+ if $ ! remote-version before v1. 4 {
421+ fail " get-filenames requires remote version 1.4 or greater, but remote version is $ ! remote-version" ;
422+ }
423+ self ! send-request(MT_LoadedFilesRequest, : start_watching). then(-> $ prom {
424+ note " result from loaded files request: " , $ prom . result. & to-json (: pretty) if $ ! debug ;
425+ my $ result = $ prom . result;
426+ $ ! filenames-lock . protect({
427+ @ ! filenames := $ result <filenames >. map (*. <path >). Array ;
428+ });
429+ % ! event-suppliers {$ result <id >} = my $ sup = Supplier::Preserving. new ;
430+ $ sup . Supply . tap ({
431+ note " notification on the loaded files request supply" , $ _ . raku if $ ! debug ;
432+ $ ! filenames-lock . protect({
433+ for . <filenames >. list {
434+ if . <path > !(elem) @ ! filenames {
435+ @ ! filenames . push : . <path >;
436+ }
437+ }
438+ })
439+ });
440+ my % ret = flat @ ($ result . hash), " notifications" => $ sup . Supply ;
441+ note % ret . raku if $ ! debug ;
442+ % ret ;
443+ });
444+ }
445+
414446 method release-handles (+ @ handles ) {
415447 my @ handles-cleaned = @ handles . map (+* );
416448 self ! send-request(MT_ReleaseHandles, handles => @ handles-cleaned ). then({
@@ -513,6 +545,12 @@ class MoarVM::Remote {
513545 });
514546 }
515547 }
548+
549+ method filenames {
550+ $ ! filenames-lock . protect({
551+ my @ = @ ! filenames []. eager ;
552+ });
553+ }
516554}
517555
518556# vim: expandtab shiftwidth=4
0 commit comments