@@ -16,7 +16,6 @@ use harp::environment::Environment;
16
16
use harp:: exec:: RFunction ;
17
17
use harp:: exec:: RFunctionExt ;
18
18
use harp:: object:: RObject ;
19
- use harp:: r_lock;
20
19
use harp:: utils:: r_assert_type;
21
20
use harp:: vector:: CharacterVector ;
22
21
use harp:: vector:: Vector ;
@@ -40,6 +39,7 @@ use crate::environment::message::EnvironmentMessageUpdate;
40
39
use crate :: environment:: message:: EnvironmentMessageView ;
41
40
use crate :: environment:: variable:: EnvironmentVariable ;
42
41
use crate :: lsp:: events:: EVENTS ;
42
+ use crate :: r_task;
43
43
44
44
/**
45
45
* The R Environment handler provides the server side of Positron's Environment
@@ -218,14 +218,13 @@ impl REnvironment {
218
218
fn refresh ( & mut self , request_id : Option < String > ) {
219
219
let mut variables: Vec < EnvironmentVariable > = vec ! [ ] ;
220
220
221
- r_lock ! {
221
+ r_task ( || {
222
222
self . update_bindings ( self . bindings ( ) ) ;
223
223
224
224
for binding in & self . current_bindings {
225
225
variables. push ( EnvironmentVariable :: new ( binding) ) ;
226
226
}
227
-
228
- }
227
+ } ) ;
229
228
230
229
// TODO: Avoid serializing the full list of variables if it exceeds a
231
230
// certain threshold
@@ -244,8 +243,7 @@ impl REnvironment {
244
243
*/
245
244
fn clear ( & mut self , include_hidden_objects : bool , request_id : Option < String > ) {
246
245
// try to rm(<env>, list = ls(envir = <env>, all.names = TRUE)))
247
- let result: Result < ( ) , harp:: error:: Error > = r_lock ! {
248
-
246
+ let result: Result < ( ) , harp:: error:: Error > = r_task ( || unsafe {
249
247
let mut list = RFunction :: new ( "base" , "ls" )
250
248
. param ( "envir" , * self . env )
251
249
. param ( "all.names" , Rf_ScalarLogical ( include_hidden_objects as i32 ) )
@@ -264,7 +262,7 @@ impl REnvironment {
264
262
. call ( ) ?;
265
263
266
264
Ok ( ( ) )
267
- } ;
265
+ } ) ;
268
266
269
267
if let Err ( _err) = result {
270
268
error ! ( "Failed to clear the environment" ) ;
@@ -281,8 +279,8 @@ impl REnvironment {
281
279
* Clear the environment. Uses rm(envir = <env>, list = ls(<env>, all.names = TRUE))
282
280
*/
283
281
fn delete ( & mut self , variables : Vec < String > , request_id : Option < String > ) {
284
- r_lock ! {
285
- let variables : Vec <& str > = variables. iter( ) . map( |s| s as & str ) . collect( ) ;
282
+ r_task ( || unsafe {
283
+ let variables: Vec < & str > = variables. iter ( ) . map ( |s| s as & str ) . collect ( ) ;
286
284
287
285
let result = RFunction :: new ( "base" , "rm" )
288
286
. param ( "list" , CharacterVector :: create ( variables) . cast ( ) )
@@ -292,16 +290,15 @@ impl REnvironment {
292
290
if let Err ( _) = result {
293
291
error ! ( "Failed to delete variables from the environment" ) ;
294
292
}
295
- }
293
+ } ) ;
296
294
297
295
// and then update
298
296
self . update ( request_id) ;
299
297
}
300
298
301
299
fn clipboard_format ( & mut self , path : & Vec < String > , format : String , request_id : Option < String > ) {
302
- let clipped = r_lock ! {
303
- EnvironmentVariable :: clip( RObject :: view( * self . env) , & path, & format)
304
- } ;
300
+ let clipped =
301
+ r_task ( || EnvironmentVariable :: clip ( RObject :: view ( * self . env ) , & path, & format) ) ;
305
302
306
303
let msg = match clipped {
307
304
Ok ( content) => {
@@ -319,9 +316,7 @@ impl REnvironment {
319
316
}
320
317
321
318
fn inspect ( & mut self , path : & Vec < String > , request_id : Option < String > ) {
322
- let inspect = r_lock ! {
323
- EnvironmentVariable :: inspect( RObject :: view( * self . env) , & path)
324
- } ;
319
+ let inspect = r_task ( || EnvironmentVariable :: inspect ( RObject :: view ( * self . env ) , & path) ) ;
325
320
let msg = match inspect {
326
321
Ok ( children) => {
327
322
let length = children. len ( ) ;
@@ -340,9 +335,8 @@ impl REnvironment {
340
335
}
341
336
342
337
fn view ( & mut self , path : & Vec < String > , request_id : Option < String > ) {
343
- let data = r_lock ! {
344
- EnvironmentVariable :: resolve_data_object( RObject :: view( * self . env) , & path)
345
- } ;
338
+ let data =
339
+ r_task ( || EnvironmentVariable :: resolve_data_object ( RObject :: view ( * self . env ) , & path) ) ;
346
340
347
341
let msg = match data {
348
342
Ok ( data) => {
@@ -386,7 +380,7 @@ impl REnvironment {
386
380
let old_bindings = & self . current_bindings ;
387
381
let mut new_bindings = vec ! [ ] ;
388
382
389
- r_lock ! {
383
+ r_task ( || {
390
384
new_bindings = self . bindings ( ) ;
391
385
392
386
let mut old_iter = old_bindings. iter ( ) ;
@@ -396,25 +390,20 @@ impl REnvironment {
396
390
let mut new_next = new_iter. next ( ) ;
397
391
398
392
loop {
399
-
400
393
match ( old_next, new_next) {
401
394
// nothing more to do
402
- ( None , None ) => {
403
- break
404
- } ,
395
+ ( None , None ) => break ,
405
396
406
397
// No more old, collect last new into added
407
398
( None , Some ( mut new) ) => {
408
399
loop {
409
- assigned. push(
410
- EnvironmentVariable :: new( & new)
411
- ) ;
400
+ assigned. push ( EnvironmentVariable :: new ( & new) ) ;
412
401
413
402
match new_iter. next ( ) {
414
403
Some ( x) => {
415
404
new = x;
416
405
} ,
417
- None => break
406
+ None => break ,
418
407
} ;
419
408
}
420
409
break ;
@@ -429,7 +418,7 @@ impl REnvironment {
429
418
Some ( x) => {
430
419
old = x;
431
420
} ,
432
- None => break
421
+ None => break ,
433
422
} ;
434
423
}
435
424
@@ -439,25 +428,21 @@ impl REnvironment {
439
428
( Some ( old) , Some ( new) ) => {
440
429
if old. name == new. name {
441
430
if old. value != new. value {
442
- assigned. push(
443
- EnvironmentVariable :: new( & new)
444
- ) ;
431
+ assigned. push ( EnvironmentVariable :: new ( & new) ) ;
445
432
}
446
433
old_next = old_iter. next ( ) ;
447
434
new_next = new_iter. next ( ) ;
448
435
} else if old. name < new. name {
449
436
removed. push ( old. name . to_string ( ) ) ;
450
437
old_next = old_iter. next ( ) ;
451
438
} else {
452
- assigned. push(
453
- EnvironmentVariable :: new( & new)
454
- ) ;
439
+ assigned. push ( EnvironmentVariable :: new ( & new) ) ;
455
440
new_next = new_iter. next ( ) ;
456
441
}
457
- }
442
+ } ,
458
443
}
459
444
}
460
- }
445
+ } ) ;
461
446
462
447
if assigned. len ( ) > 0 || removed. len ( ) > 0 || request_id. is_some ( ) {
463
448
// only update the bindings (and the version)
0 commit comments