这个问题特别针对在 VS Code 中转向 TypeScript 的其他 C# 开发人员。
我爱上了 VS C# 中的代码完成功能。为了说明,假设我正在尝试写:
console.log('hello')
使用 C#,我会:
- 输入“con”
- 将出现一个建议列表,可能以“console”开头
- 因为它已突出显示并且是我想要的,所以点击“.”会写出“唯一”。所以现在我有:
console.
- 输入“l”,“log”是第一个建议
- 键入“(”,现在我有:
console.log('')
- 光标现在在''
- 输入“你好”
目前在我的 VS Code 设置中,每次我想接受建议时,在 JS/TS 中点击 tab
可以实现同样的事情。但只需按下一个标点符号继续操作就真的很不错,如果你原谅我关心它,“很有趣”。我想念它。并且我所知道的语言没有技术限制会禁止这种行为。
有人知道是否有任何扩展或设置可用于启用此功能吗?或者,此对话可能发生在其他什么地方?
最佳答案
可以使用 macros extension 自行实现.为此:
创建调用 acceptSelectedSuggestion 操作的宏,然后键入
.
。这是我的 Settings.json 的样子:{ "editor.wordWrap": "on", "window.zoomLevel": 0, "git.enableSmartCommit": true, "macros": { "accept.": [ "acceptSelectedSuggestion", {"command": "type", "args": {"text": "."}} ], "accept(": [ "acceptSelectedSuggestion", {"command": "type", "args": {"text": "("}} ], "accept=": [ "acceptSelectedSuggestion", {"command": "type", "args": {"text": "="}} ] } }
将这些宏中的每一个添加到 keybindings.json 中的键绑定(bind)。我的附加键绑定(bind)如下所示:
{ "key": ".", "command": "macros.accept.", "when": "editorTextFocus && suggestWidgetVisible" }, { "key": "shift+9", "command": "macros.accept(", "when": "editorTextFocus && suggestWidgetVisible" }, { "key": "=", "command": "macros.accept=", "when": "editorTextFocus && suggestWidgetVisible" }
这为这 3 个特定的后续键启用了经典的 VS C# 完成行为。任何其他我想到的都可以在我记得的时候添加。
关于javascript - 是否可以将 VS Code 代码完成配置为接受标点符号建议?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46452085/