简体   繁体   中英

How enable intellsense in VS Code

How I can enable intellsense in VS Code for custom .js files? This site talks that JavaScript IntellSense already working, but if you want to get more information about code completion you can use

  • IntelliSense based on type inference
  • IntelliSense based on JSDoc
  • IntelliSense based on TypeScript Declaration Files

I don't need more information. Just want to see some suggestions. For example I wrote some function in file a.js . How can i enable intellsense (references to a.js ) when I'am working in b.js file.

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.

More about it here: https://msdn.microsoft.com/en-us/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.
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. You create a reference directive in the form of an XML comment.
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).
/// <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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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