如何在 Visual Studio Code 中按下 Ctrl+点时让导入项显示出来,这是您的问题。

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

How do I get imports to show up when I press ctrl+dot in javascript in vscode?

问题

在编写JSX(或任何Typescript代码)时,如果存在一个尚未导入的可用引用,它下面会出现一个波浪线,您可以按Ctrl+点,然后自动将代码导入为"重构"。

如何在JavaScript中设置这个功能呢?我已经看到别人的VSC截图,它在"更多选项"下可用,所以我很确定这是可能的,但当我按Ctrl+点时什么都没有发生。

注意:我知道可以按Ctrl+空格。但出于两个原因,我不想这样做:(1)按Alt+空格不是很好的用户体验,因为如果你在单词中间按它,即使你已经有了完整的名称,它仍然会自动完成,所以你会得到一个不正确的标签(例如,如果你的光标在Keyboard组件的d之后,你会得到KeyboardRowRow),(2)我想将快速修复重新绑定为Alt+Enter以匹配PyCharm,并希望在Typescript和JavaScript中具有相同的热键和用户体验。

英文:

When writing JSX (or any typescript code really) if you have an available import that's not yet imported, you get a squiggly line under it and can press ctrl+dot on it and then automatically import the code as a "refactoring."

How can I set this up in Javascript? I've seen a screenshot of someone else's VSC where it is available underneath "more options" and so I'm pretty sure it's possible, but when I press ctrl+dot I get nothing.

Note: I'm aware I can press ctrl+space. However, I don't want to do this, for two reasons. (1) alt+space is pretty bad UX because if you press it in the middle of a word it continues to autocomplete even if you already had the full name there and so you are left with an incorrect tag (e.g. if your cursor was after the d in Keyboard for a component called KeyboardRow you are left with KeyboardRowRow) and (2) I want to rebind quick fix to alt+enter to match pycharm; and I want the same hotkey & UX in both Typescript and Javascript.

答案1

得分: 0

我没有太多与JS一起工作的经验,主要是使用TS,但我在我的vscode中安装了两个扩展,在编写纯JS代码时对我有很大帮助。

Path intellisenseAuto import

英文:

I haven't worked too much with JS, mainly with TS, but I have two extensions installed in my vscode that helped me a lot while coding in vanilla JS.

Path intellisense and Auto import

答案2

得分: 0

你可以尝试使用 My Code Actions 来构建这些类型的问题/波浪线的快速修复。

英文:

You can try if My Code Actions can be used to construct a Quick Fix for these types of PROBLEMS/squiggles

答案3

得分: 0

我找到了一个答案。在JavaScript中,使用Ctrl+空格进行导入。此外,为了消除在光标位于单词中间时出现的一些相当奇怪的行为,您可能想要在您的settings.json中启用以下设置:

"editor.suggest.insertMode": "replace",

与用户首选项相关的GitHub问题

英文:

I figured out an answer. Imports are with ctrl+space in javascript. Also, in order to remove some pretty bizarre behavior when your cursor is in the middle of the word, you probably want to enable the following setting in your settings.json:

"editor.suggest.insertMode": "replace",

Relavent github issue related to the user preference

huangapple
  • 本文由 发表于 2023年2月6日 19:52:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75360949.html
匿名

发表评论

匿名网友

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

确定