[英]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.<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.