简体   繁体   English

IntelliJ IDEA Ultimate:通过简单的脚本标签包含的 JS 代码完成

[英]IntelliJ IDEA Ultimate: Code completion for JS included via simple script tag

I manage to get perfect code completion when working with npm and ES6 modules – but how do I get code completion when I just have a single HTML with the JS included via script tag ?在使用 npm 和 ES6 模块时,我设法获得完美的代码完成 - 但是当我只有一个 HTML 并且通过脚本标记包含 JS 时,我如何获得代码完成

<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example</title>
</head>
<body>
<script src="https://d3js.org/d3.v4.js"></script>
<script>
    d3.select("body") // Unresolved variable or type d3
</script>
</body>

I tried adding D3 as a library (Project Settings > Libraries) – to no avail.我尝试将 D3 添加为库(项目设置 > 库) - 无济于事。

I found this WebStorm blog post to be very helpful.我发现这篇 WebStorm 博客文章非常有帮助。 In summary:总之:

  • <script> tags are just used by the browser; <script>标签只被浏览器使用; they don't influence the IDE's behavior regarding code completion/navigation/error highlighting/etc.它们不会影响 IDE 在代码完成/导航/错误突出显示等方面的行为。
  • Code completion/navigation/error highlighting/etc is determined by JS libraries ( Preferences > Languages & Frameworks > JavaScript > Libraries )代码完成/导航/错误突出显示/等由 JS 库决定( Preferences > Languages & Frameworks > JavaScript > Libraries
  • These libraries can be configured manually , or can be generated via a quick fix: Using the <script src="..."></script> attribute, select the https link, and invoke "Download library".这些库可以手动配置,也可以通过快速修复生成:使用<script src="..."></script>属性,选择 https 链接,然后调用“下载库”。 Illustrated by this screenshot presented in the blog:由博客中提供的此屏幕截图说明:

在此处输入图片说明

This fixes my "Unresolved variable or type d3" problem.这解决了我的“未解析的变量或类型 d3”问题。 IntelliJ IDEA still seems to get confused about chained statements which span across multiple lines. IntelliJ IDEA 似乎仍然对跨越多行的链式语句感到困惑。

<script src="http://d3js.org/d3.v3.min.js"></script>

Make the mouse hover over " http://d3js.org/d3.v3.min.js ".将鼠标悬停在“ http://d3js.org/d3.v3.min.js ”上。 Click “Download library”.点击“下载库”。

…… ……

Wait a minute, then it's OK.等一下,然后就OK了。

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

相关问题 从IntelliJ IDEA中的代码完成中排除JavaScript库 - Exclude javascript library from code completion in IntelliJ IDEA w3.css 框架的 Intellij IDEA 代码完成? - Intellij idea code completion for w3.css framework? 在 IntelliJ IDEA/WebStorm 中定义 JS 脚本的上下文 - Define context of JS script in IntelliJ IDEA/WebStorm 使用 IntelliJ IDEA - Ultimate Edition 的 Cucumber-js 未定义步骤参考 - Cucumber-js undefined step reference using IntelliJ IDEA - Ultimate Edition 通过脚本标记包含vuex.js时的Vuex mapState引用错误 - Vuex mapState reference error when vuex.js is included via script tag JS 文件缓存在通过脚本标记与 GET 包含时有所不同 - JS file caching is different when included via script tag vs GET Firefox扩展:通过脚本标记包含的JavaScript文件无效 - Firefox extension: JavaScript file included via script tag is not working 如何简单地将方法导出到要包含的另一个.js文件中<script> tag? - How to simply export a method to another .js file to be included with <script> tag? IntelliJ IDEA 中的 P5.js? - P5.js in IntelliJ IDEA? 类型不是“ text / javascript”的脚本标记中的Intellij Idea JavaScript识别 - Intellij idea javascript recognition in script tag where type isn't “text/javascript”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM