简体   繁体   English

如何在VS Code中启用智能

[英]How enable intellsense in VS Code

How I can enable intellsense in VS Code for custom .js files? 如何在VS Code中为自定义.js文件启用智能感知? This site talks that JavaScript IntellSense already working, but if you want to get more information about code completion you can use 这个网站说JavaScript IntellSense已经可以使用,但是如果您想获得有关代码完成的更多信息,可以使用

  • IntelliSense based on type inference 基于类型推断的IntelliSense
  • IntelliSense based on JSDoc 基于JSDoc的IntelliSense
  • IntelliSense based on TypeScript Declaration Files 基于TypeScript声明文件的IntelliSense

I don't need more information. 我不需要更多信息。 Just want to see some suggestions. 只想看一些建议。 For example I wrote some function in file a.js . 例如,我在文件a.js中编写了一些函数。 How can i enable intellsense (references to a.js ) when I'am working in b.js file. 当我在b.js文件中工作时,如何启用智能(引用a.js )。

I used to add /// <reference path="ScriptFile1.js" /> on top of the .js file and it works, I also used to drag and drop the file from the solution explorer to the js file creates this reference line, but It is not working on my current VS version anymore. 我曾经在.js文件顶部添加/// <reference path="ScriptFile1.js" /> ,并且可以正常工作,我还曾经将文件从解决方案资源管理器拖放到js文件中,从而创建了此参考行,但是现在我的VS版本不再起作用。

More about it here: https://msdn.microsoft.com/en-us/library/bb385682.aspx 有关更多信息,请访问: https : //msdn.microsoft.com/zh-cn/library/bb385682.aspx

Reference Directives 参考指令

A reference directive enables Visual Studio to establish a relationship between the script you are currently editing and other scripts. 通过引用指令,Visual Studio可以在当前正在编辑的脚本和其他脚本之间建立关系。
The reference directive lets you include a script file in the scripting context of the current script file. 通过引用指令,可以将脚本文件包含在当前脚本文件的脚本上下文中。 This enables IntelliSense to reference externally defined functions, types, and fields as you code. 这使IntelliSense可以在编码时引用外部定义的函数,类型和字段。 You create a reference directive in the form of an XML comment. 您以XML注释的形式创建参考指令。
The directive must be declared earlier in the file than any script. 该指令必须在文件中比任何脚本更早声明。

A reference directive can include a disk-based script reference, an assembly-based script reference, a service-based script reference, or a page-based script reference. 参考指令可以包括基于磁盘的脚本参考,基于程序集的脚本参考,基于服务的脚本参考或基于页面的脚本参考。

The following example shows examples of using disk-based reference directives. 以下示例显示了使用基于磁盘的引用指令的示例。 In the first example, the language service looks for the file in the same folder that contains the project file (for example, .jsproj). 在第一个示例中,语言服务在包含项目文件的同一文件夹(例如,.jsproj)中查找文件。
/// <reference path="ScriptFile1.js" />
/// <reference path="Scripts/ScriptFile2.js"/>
/// <reference path="../ScriptFile3.js" />
/// <reference path="~/Scripts/ScriptFile4.js" />

Also this article is worth reading for some other ideas: https://madskristensen.net/post/the-story-behind-_referencesjs 同样,本文也值得其他一些想法阅读: https : //madskristensen.net/post/the-story-behind-_referencesjs

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

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