阻止 Visual Studio Code 中的 R 代码自动完成建议 “%>%” 时出现 “%in%”。

huangapple go评论72阅读模式
英文:

Prevent R code autocomplete for "%>%" in Visual Studio Code from suggesting "%in%"

问题

使用Visual Studio Code的R扩展时,代码补全始终建议在以magrittr管道%>%结尾的行上使用%in%%>%中的最后一个%触发了%in%的自动补全建议。

在编写代码块时,发生以下情况:

library(dplyr)
mtcars %>%
    select(mpg, cyl) %>%

是否有任何方法可以修复这个问题?如果我键入"enter"以换行,就像在任何其他文本编辑器中一样,Visual Studio Code会在行尾插入%in%,这显然不是我想要的。

我不确定在哪里可以调整配置 - 无论是在Visual Studio Code中,还是在R扩展中,还是在R语言服务器中。

英文:

When using the R Extension for Visual Studio Code the code completion always suggests %in% for a line that ends with the magrittr pipe %>%. The final % in %>% triggers an autocomplete suggestion of %in%.

Here's what happens when writing a code block:

library(dplyr)
mtcars %>%
    select(mpg, cyl) %>%

阻止 Visual Studio Code 中的 R 代码自动完成建议 “%>%” 时出现 “%in%”。

Is there anyway to fix this? If I type "enter" for a newline like I normally would in any other text editor, visual studio code inserts the %in% at the end of the line, which clearly isn't what I want.

I'm not sure where I can tweak any configurations - whether in visual studio code, or the R extension, or the R language server.

答案1

得分: 0

由于已接受的答案没有用处(而MangoHands的评论很有用),我将他的评论重新发布为一个单独的答案:

您可以通过禁用“回车”按钮的建议接受,而只使用“Tab”键来接受建议,我认为这很直观。

为此,请在Visual Studio的“首选项:打开用户设置(JSON)”选项中添加以下行(使用“Ctrl+Shift+P”/“Cmd+Shift+P”打开命令面板,搜索“首选项:打开用户设置(JSON)”):

"editor.acceptSuggestionOnEnter": false

附注:使用管道的快捷键(“Cmd+Shift+M”)很可爱,直到您意识到它在终端中无法工作-至少在“radian”中不行-(而是切换到“问题”选项卡),这对我来说是一个巨大而令人恼火的问题。

英文:

Since the accepted answer isn't useful (whereas MangoHands comment is), I'm reposting his comment as a separate answer:

You can disable the acceptance of suggestions via the enter button which and instead use (only) tab to accept suggestions, which I find intuitive.

To this end add the following line into the Preferences: Open User Settings (JSON) option from visual studio (Use Ctrl+Shift+P/Cmd+Shift+P to open the command palette and search for Preferences: Open User Settings (JSON)):

"editor.acceptSuggestionOnEnter": false

PS: Using the shortcut for the pipe (Cmd+Shift+M) is cute until you realize that it won't work in the terminal - at least noy in radian- (instead you shift to the 'problems' tab), which for me is a huge and annoying issue.

答案2

得分: -1

尝试在你的 settings.json 中使用以下内容。它应该可以防止不必要的字符串注释建议以及 %>%%in%

  "[r]": {
    "editor.quickSuggestions": {
      "other": false,
      "comments": false,
      "strings": false
    }
  }
英文:

Try this in your settings.json. It should prevent from suggestion of unnecessary strings comments and also %>% or %in%.

  "[r]": {
    "editor.quickSuggestions": {
      "other": false,
      "comments": false,
      "strings": false
    }
  }

huangapple
  • 本文由 发表于 2023年1月9日 00:22:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75049419.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定