如何在VSCode中启用Node.js代码自动完成功能?
我已经安装了Visual Studio Code和Node.js,它们都可以正常工作,但是自动完成功能不能(完全)正常工作.如果我输入"console".我确实确实看到了一个列表弹出窗口.同样,如果我这样做:const http = require("http");http.
I have installed Visual Studio Code and Node.js and both basically work, but autocomplete is not (completely) working. If I type 'console.' I do indeed see a list popup. Likewise if I do: const http = require("http"); http.
但是,如果我只是简单地键入"process".我什么也没看到.实际上,只要我键入."代码自动将过程"完成为"ProcessingInstruction".我期待看到argv以及您在Node提示符下键入'process'时看到的所有其他内容.
But if I simply type 'process.' I don't see anything. In fact as soon as I type '.' Code autocompletes 'process' to 'ProcessingInstruction'. I was expecting to see argv pop up, along with all the other stuff you see if you type 'process' at a Node prompt.
这是我输入控制台"时看到的内容:是的-它有效!
Here's what I see when I type 'console.': Yay -- it works!
但是,这是我输入"process"时看到的内容.(我必须将自动完成的"ProcessingInstruction"更改回"process"):嘘-它不知道过程"!:(
But here's what I see when I type 'process.' (I have to change the autocompleted 'ProcessingInstruction' back to 'process'): Boo -- it doesn't know 'process'! :(
您将需要向VS Code讲解Node JS中的类型(在注释中打您自己).为此,您可以为运行以下命令的节点安装类型(假设您已经运行了 npm init
):
You will need to tell VS Code about the types in Node JS (as you hit at yourself in the comment). To do this you can install the types for node running the following command (assuming you have already run npm init
):
npm install --save-dev @types/node
它将安装Node JS的类型,VS Code会自动选择该类型,并且您将自动完成所有特定于Node JS的操作.您甚至不必重新启动VS Code.
It will install the types for Node JS, which VS Code automatically picks up and you'll be auto-completing all Node JS-specific things going forward. You don't even have to restart VS Code.
当您向项目中添加更多依赖项时(如果这样做).他们中的许多人还具有@ types/X软件包(如果它们尚未包含在软件包中),这也将允许自动完成.
As you are adding more dependencies to your project (if you will be doing so). Many of them have a @types/X package as well (if they don't have the already included in the package), which will allow autocomplete as well.