简体   繁体   English

VS 代码自动完成/智能感知不工作

[英]VS Code autocomplete/intellisense not working

Building my first React project from https://frontendmasters.com/courses/complete-react-v5/ on VS Code for Windows 10.https://frontendmasters.com/courses/complete-react-v5/在 Windows 的 VS Code 上构建我的第一个 React 项目 10.

Have installed prettier, eslint.已经安装了 prettier,eslint。 Using Parcel to transpile the code.使用 Parcel 转译代码。 The intellisense is only working on index.html file.智能感知仅适用于 index.html 文件。 Nothing on js files. js文件上什么都没有。 Have looked through old answers and none of them proved to be helpful.查看了旧答案,但没有一个被证明是有帮助的。 A bit of a noob here, a step by step solution will be helpful这里有点菜鸟,一步一步的解决方案会有所帮助

Screenshot Attaching project files截图附加项目文件

http://www.filedropper.com/adapt-me http://www.filedropper.com/adapt-me

on the right bottom change the language mode Javascript to Javascript React在右下角将语言模式 Javascript 更改为 Javascript React

在此处输入图片说明

You need to specify that the file you working on is of JavaScript React type, currently with .js it is a JavaScript file type.您需要指定您正在处理的文件是JavaScript React类型,目前使用.js它是JavaScript文件类型。

You can see the file type on the bottom Status Bar您可以在底部Status Bar上看到文件类型

在此处输入图片说明

Use Change Language Mode (through command palette) command to change it manually.使用Change Language Mode (通过命令面板)命令手动更改它。

Also, you can provide a config in settings.json to associate it with a file name, for example:此外,您可以在settings.json提供一个配置以将其与文件名相关联,例如:

  "files.associations": {
    "*.react.js": "javascriptreact",
    "*.stories.js": "javascriptreact",
    "*.action.js": "javascriptreact",
    "*.reducer.js": "javascriptreact",
    "*.styles.js": "javascriptreact",
    "*.styles.react.js": "javascriptreact",
    "*.styles.jsx": "javascriptreact",
    "*.svg.js": "javascriptreact",
    "*.jsx": "javascriptreact",
    "*.js": "javascriptreact",
    ".stylelintrc": "jsonc"
  }

It may be a problem with your parcel setup.您的包裹设置可能有问题。 Can you create a Create React App project template CRA and check if the intellisense still doesn't work with the js files in it.您能否创建一个 Create React App 项目模板CRA并检查智能感知是否仍然无法处理其中的 js 文件。

Another alternative is to upgrade your VS code to the latest version if any update is available or else you can download VSCode Insiders and check if the intellisense works as expected.另一种选择是将你的 VS 代码升级到最新版本,如果有任何更新,或者你可以下载VSCode Insiders并检查智能感知是否按预期工作。

One other option is to checkout the code from the commit mentioned at the bottom of this page and check if the intellisense works for this code.另一种选择是从在提交的底部所提及的检出代码页面,并检查智能感知适用于本规范。

如果您的文件扩展名类似于 .js,请将其转换为 .jsx。

I had the same problem trying to get auto-complete using fs functions.我在尝试使用 fs 函数自动完成时遇到了同样的问题。 When I switched from requiring to importing fs, the auto-complete appeared.当我从需要切换到导入 fs 时,自动完成出现了。 Don't know if it's relevant though.不过不知道有没有关系。 Just a complete newbie.只是一个完整的新手。

You need to assign the extension of ".jsx" to "Javascript React" in the bottom right corner of VS Code.您需要将“.jsx”的扩展名分配给VS Code右下角的“Javascript React”。

Click on Configure File Association for '.jsx' :单击Configure File Association for '.jsx'

第1步

Then select Javascript React :然后 select Javascript React

第2步

Now the autocomplete will happen like if it was an html file.现在自动完成会像 html 文件一样发生。

Also, make sure to add ".jsx" extension to your files instead of ".js".另外,请确保将“.jsx”扩展名添加到您的文件而不是“.js”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM