radian icon indicating copy to clipboard operation
radian copied to clipboard

Provide option to have tab apply completion

Open mskar opened this issue 4 years ago • 9 comments

In #224, I requested a feature that adds parentheses after functions completed with Tab or Enter.

I decided the best solution will be to use rchitect to identify functions based on the string returned by the completer.

This pull request implements the feature I requested (function completion with added parentheses), but also strives to make autocompletion work like in RStudio or the VSCode R extension. In VSCode and RStudio, tab applies completion instead of cycling through completion options, like in bash or zsh.

Currently, this feature is disabled by default, but it has to be enabled by adding

options(radian.auto_complete_commit_on_tab = TRUE)

to .radian_profile.

For more information, please take a look at this comment in #387.

To install radian with the tab_apply_completion feature, run python -m pip install git+https://github.com/mskar/radian.git@tab_apply_completion

Note: This also completely changes how completion works: Tab:

  • does not cycle thru completion options and instead
  • accepts completion if there is only one completion option
  • starts completion if there are multiple options and the completion menu is not showing
  • accepts the selected completion option if an option is selected
  • accepts the first completion option if the completion menu is showing and no option is selected

Enter:

  • accepts the selected completion option if an option is selected
  • accepts the first completion option if the completion menu is showing and no option is selected

TLDR:

previous behavior:

  • tab cycles completion
  • function completion does not add parentheses

proposed behavior:

  • tab applies completion
  • function completion adds parentheses

Changes:

Changed: when triggering completion with Tab, insert text that all options have in common Changed: use Tab to accept only option or accept selected Changed: do not move through options with not Tab and Shift-Tab Unchanged: use Enter to accept if completion menu is showing Unchanged: move through options with c-n and c-p Unchanged: cancel completion with c-g

mskar avatar Oct 10 '20 20:10 mskar

I don't mind having the feature of committing completion with tab, but I don't think it is a good idea to set it as default because it is a breaking change. By the way, could you rename the setting as auto_complete_commit_on_tab which is the setting name inspired by Sublime Text?

randy3k avatar Oct 10 '20 23:10 randy3k

By the way, thank you for the contribution.

randy3k avatar Oct 10 '20 23:10 randy3k

@randy3k, thanks for the great feedback. With https://github.com/randy3k/radian/pull/229/commits/65210eec29e829922bd80d6bc36e9dd9ee969614, the feature is no longer enabled by default and the setting is renamed to auto_complete_commit_on_tab. If there are any other changes that need to be made, please let me know.

mskar avatar Oct 11 '20 02:10 mskar

@randy3k, thanks for merging in #227. I pulled the latest changes from the master branch into this PR.

mskar avatar Oct 11 '20 02:10 mskar

I feel like tab to commit completion and adding parentheses after functions are two separate features. We should be able to enable one and disable the other and now you have tied the two features together.

randy3k avatar Oct 12 '20 20:10 randy3k

Yes, I agree with you, @randy3k, it will be better to have two independent features controlled by two independent settings.

I will edit this PR to

  • [ ] maintain the current behavior of tab if auto_complete_commit_on_tab is disabled
  • [ ] have tab to commit completion without adding parentheses after functions if auto_complete_commit_on_tab is enabled
  • [ ] include a new setting for adding parentheses after functions that works regardless of whether auto_complete_commit_on_tab is enabled or disabled.

What should the new setting be called? Ideally, the two settings would have similar names, e.g.

  • auto_complete_commit_on_tab
  • auto_complete_function_parentheses

mskar avatar Oct 12 '20 22:10 mskar

The plan looks good to me.

randy3k avatar Oct 14 '20 17:10 randy3k

@randy3k, I split the original feature into 5 independent features. Each feature has its own setting to allow for granular control of completion behavior:

  1. auto_complete_function_parentheses:
  • Tab: Unchanged unless combined with one of the settings that end in _option_on_tab.
  • Enter: Accepts selected completion and add parentheses to functions
  1. auto_complete_selected_option_on_tab:
  • Tab: Accepts the selected completion option if an option is selected
  • Enter: Unchanged
  1. auto_complete_top_option_on_enter:
  • Tab: Unchanged
  • Enter: Accepts the first completion option if the completion menu is showing
  1. auto_complete_top_option_on_tab:
  • Tab: Accepts the first completion option if the completion menu is showing and no option is selected
  • Enter: Unchanged
  1. auto_complete_only_option_on_tab:
  • Tab: Accepts completion if there is only one completion option or starts completion if there are multiple options
  • Enter: Unchanged

These features can be combined. Enabling all of the features makes completion behave like in RStudio.

Is 5 settings too many? Would it be a good idea to add another setting that combined 2-5 (auto_complete_[selected,top,only]_option_on_[tab,enter])?

Please let me know if any of the settings should be renamed.

mskar avatar Oct 17 '20 20:10 mskar

So I can't break the habit of trying tab for completions. Any advice to apply these changes to my local radian or a local repo, but then how to compile it?

psobolewskiPhD avatar Feb 26 '21 21:02 psobolewskiPhD