Skip to content

Commit 09f5141

Browse files
authored
Add get-filenames and filenames methods. (#6)
As of now, the caller should make sure to only call get-filenames once, and to have called get-filenames before expecting the filenames method to return values.
1 parent 4c9154b commit 09f5141

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

lib/MoarVM/Remote.rakumod

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5961
class 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

Comments
 (0)