Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R: Completions: Adding parentheses inside of debug() and undebug() #2338

Closed
juliasilge opened this issue Feb 27, 2024 · 11 comments
Closed

R: Completions: Adding parentheses inside of debug() and undebug() #2338

juliasilge opened this issue Feb 27, 2024 · 11 comments
Assignees
Labels
area: completions Issues related to Completions area: kernels Issues related to Jupyter kernels and LSP servers lang: r

Comments

@juliasilge
Copy link
Contributor

In usability testing with @simonpcouch today, we noticed that using autocomplete inside of debug() or undebug() gets you parentheses that keep it from working. For example, you want:

debug(dplyr::filter)

but what you get with autocomplete is:

debug(dplyr::filter())

which then errors during debugging.

We've done related work in #1563 but we do know we are inside of debug()/undebug() in this situation and could maybe not add the parentheses?

@juliasilge juliasilge added this to the Future milestone Feb 27, 2024
@DavisVaughan
Copy link
Contributor

I think @lionel- wants to eventually tackle this in a generic way with his declare() declaration idea. It would allow debug() (and any other function) to specify that the first argument is expected to be a function. We'd process that information and in the completion engine we'd understand that we were inside a function where this was the case and we'd not add () to functions when that declaration was active

That's a while away though

@DavisVaughan
Copy link
Contributor

In the meantime, RStudio does have a set of base functions where it doesn't add () for, which we can copy
https://github.com/rstudio/rstudio/blob/088dfc97d473d4e3fb1e356d7fc3092a6fb35cfc/src/cpp/session/modules/SessionRCompletions.R#L2923-L2929

@DavisVaughan
Copy link
Contributor

DavisVaughan commented Feb 27, 2024

This heuristic based on the formals is also interesting (i.e. is the argument name f, fn, fun, or func?)
https://github.com/rstudio/rstudio/blob/088dfc97d473d4e3fb1e356d7fc3092a6fb35cfc/src/cpp/session/modules/SessionRCompletions.R#L2935-L2942

@jennybc
Copy link
Member

jennybc commented Feb 28, 2024

I have thought about opening an issue about this as well. lookup::lookup() is another context where you often have to fight to not get parentheses. But debug() is the main place I encounter this.

@jennybc
Copy link
Member

jennybc commented May 10, 2024

I also wish the automatic parentheses were not added when completing a function name after ?. AFAICT they are harmless and yet they still offend me. Below, I submit ?toupper() but I would prefer ?toupper.

Screen.Recording.2024-05-10.at.3.09.56.PM.mov

@lionel- lionel- changed the title R: Autocomplete adding parentheses inside of debug() and undebug() R: Completions: Adding parentheses inside of debug() and undebug() May 16, 2024
@lionel- lionel- added area: kernels Issues related to Jupyter kernels and LSP servers area: completions Issues related to Completions labels May 16, 2024
@jennybc
Copy link
Member

jennybc commented May 20, 2024

Update: I now know the issue of adding parentheses after ? has its own issue: #1818

@jaredlander
Copy link

jaredlander commented Nov 14, 2024

I know this isn't exactly the right issue, but it's related. Can we just turn off parenthesis after autocompletion altogether? I have turned off this feature in RStudio for years and never want the parentheses added. It seems like other VS Code language extensions have options to turn off that feature and I would prefer to disable it here too. Heck, I'd even turn off matching closing parentheses/quotes/brackets too. I know not everyone likes that, but it would be nice to have the option.

@lionel-
Copy link
Contributor

lionel- commented Nov 15, 2024

@jaredlander I think that makes sense, I've opened an issue at #5377

To disable delimiter auto-closing while typing you can set:

"editor.autoClosingBrackets": "never"

@jaredlander
Copy link

I figured out the auto closing thing shortly after posting and even how to do it just for R. Thanks for opening #5377.

@jennybc
Copy link
Member

jennybc commented Feb 10, 2025

QA Notes

In the R Console:

  • Apply the str() or args() function to a function, while accepting a completion for that inner function. Let's use the new.env() function as an example. Start typing args(new.) and allow the completions to pop-up. Accept the completion for new.env. There should be no trailing parenthese. You should complete to args(new.env), which works and reveals the arguments, not to args(new.env()), which just returns NULL.
# GOOD, what you should see
args(new.env)
#> function (hash = TRUE, parent = parent.frame(), size = 29L) 
#> NULL

# BAD, what you should NOT see
args(new.env())
#> NULL
  • This feature currently works off a fixed list of special functions: args(), debug(), debugonce(), help(), trace(), str(), so feel free to experiment with any of these.

Created on 2025-02-10 with reprex v2.1.1

jennybc added a commit that referenced this issue Feb 10, 2025
For:

* posit-dev/ark#680

### Release Notes

#### New Features

- R completions in specific contexts (such as with the `?` help operator
or inside `debug()`) no longer add trailing parentheses to functions
(#1818, #2338).

#### Bug Fixes

- N/A

### QA Notes

In the R Console:

* Request help for a function, such `enc2native()`, using the `?`
operator. Literally, type `?enc2` and allow the completions to pop-up.
Accept the completion for `enc2native`. There should be no trailing
parentheses. You should complete to `?enc2native` and not
`?enc2native()`.
* Apply the `str()` or `args()` function to a function, while accepting
a completion for that function. Let's use the `new.env()` function as an
example. Start typing `args(new.)` and allow the completions to pop-up.
Accept the completion for `new.env`. There should be no trailing
parenthese. You should complete to `args(new.env)`, which works and
reveals the arguments, not to `args(new.env())`, which just returns
`NULL`.

``` r
# GOOD, what you should see
args(new.env)
#> function (hash = TRUE, parent = parent.frame(), size = 29L) 
#> NULL

# BAD, what you should NOT see
args(new.env())
#> NULL
```

<sup>Created on 2025-02-10 with [reprex
v2.1.1](https://reprex.tidyverse.org)</sup>
@juliasilge juliasilge marked this as a duplicate of #6286 Feb 11, 2025
@testlabauto
Copy link
Contributor

Verified Fixed

Positron Version(s) : 2025.03.0-11
OS Version          : OSX

Test scenario(s)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: completions Issues related to Completions area: kernels Issues related to Jupyter kernels and LSP servers lang: r
Projects
None yet
Development

No branches or pull requests

7 participants