jimhester/lookup

Issues with rstudioapi::navigateToFile and .c functions?

Closed this issue · 2 comments

When I attach lookup, Rstudio triggers a navigateToFile event for no evident reason on functions that call compiled code. I can't figure out exactly what functions cause it (list does reliably, quote less so. Interpreted functions seem to be fine). It happens in both the console as well as the file edit pane. It steals focus, so it's disruptive. Perhaps it relates to auto-completion or tooltips in Rstudio calling print?

I tried to trace lookup:::print.compiled from R studio's console, but that doesn't seem to be where the Rstudio event loop runs so hasn't revealed anything. I'm also not totally confident this isn't some weird site issue for me, though it occurs when I comment out all of my .Rprofile except a call to suppressMessages(library(lookup)) (I'm unsure how make Rstudio run with --vanilla).


> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.4

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] devtools_1.13.1   lookup_0.0.0.9000

loaded via a namespace (and not attached):
 [1] compiler_3.4.0      httr_1.2.1          R6_2.2.1            tools_3.4.0        
 [5] withr_1.0.2         rstudioapi_0.6      curl_2.6            memoise_1.1.0      
 [9] crayon_1.3.2        Rcpp_0.12.11        gh_1.0.0            codetools_0.2-15   
[13] highlite_0.0.0.9000 digest_0.6.12       jsonlite_1.4 

kapture 2017-06-01 at 18 03 30

Something in RStudio's completion system must be calling print on the function, likely to figure out arguments for the completion. It should really be doing this with formals, I don't know why it is using print, perhaps for primitive functions.

Attaching lookup defines print.function to call lookup::lookup on the function, which produces the behavior you observe.

In particular the call is at https://github.com/rstudio/rstudio/blob/0fa9d0a66500295236203d50b8d3de6ffc8c11d3/src/cpp/session/modules/SessionCodeTools.R#L501.

I sent a fix upstream, and also added a workaround, so this will no longer happen.