Skip to content

Commit

Permalink
Add get-filenames and filenames methods.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timo committed Nov 19, 2024
1 parent e6f5dda commit ef9743b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/MoarVM/Remote.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ our enum MessageType is export <
MT_HandleEquivalenceResponse
MT_HLLSymbolRequest
MT_HLLSymbolResponse
MT_LoadedFilesRequest
MT_FileLoadedNotification
>;

class X::MoarVM::Remote::ProtocolError is Exception {
Expand Down Expand Up @@ -118,6 +120,9 @@ class MoarVM::Remote {

has %!breakpoint-to-event{Any};

has Lock $!filenames-lock .= new;
has @!filenames;

has Lock $!id-lock .= new;
has int32 $!req_id = 1;

Expand Down Expand Up @@ -411,6 +416,33 @@ class MoarVM::Remote {
})
}

method get-filenames() {
if $!remote-version before v1.4 {
fail "get-filenames requires remote version 1.4 or greater, but remote version is $!remote-version";
}
self!send-request(MT_LoadedFilesRequest, :start_watching).then(-> $prom {
note "result from loaded files request: ", $prom.result.&to-json(:pretty) if $!debug;
my $result = $prom.result;
$!filenames-lock.protect({
@!filenames := $result<filenames>.map(*.<path>).Array;
});
%!event-suppliers{$result<id>} = my $sup = Supplier::Preserving.new;
$sup.Supply.tap({
note "notification on the loaded files request supply", $_.raku if $!debug;
$!filenames-lock.protect({
for .<filenames>.list {
if .<path> !(elem) @!filenames {
@!filenames.push: .<path>;
}
}
})
});
my %ret = flat @($result.hash), "notifications" => $sup.Supply;
note %ret.raku if $!debug;
%ret;
});
}

method release-handles(+@handles) {
my @handles-cleaned = @handles.map(+*);
self!send-request(MT_ReleaseHandles, handles => @handles-cleaned).then({
Expand Down Expand Up @@ -513,6 +545,12 @@ class MoarVM::Remote {
});
}
}

method filenames {
$!filenames-lock.protect({
my @ = @!filenames[].eager;
});
}
}

# vim: expandtab shiftwidth=4

0 comments on commit ef9743b

Please sign in to comment.