gpt4 book ai didi

javascript - 如何在 VS Code 中启用智能感知

转载 作者:行者123 更新时间:2023-11-28 04:15:00 25 4
gpt4 key购买 nike

如何在 VS Code 中为自定义 .js 文件启用智能感知? This site据说 JavaScript IntelllSense 已经可以工作,但如果您想获得有关代码完成的更多信息,可以使用

  • 基于类型推断的 IntelliSense
  • 基于 JSDoc 的智能感知
  • 基于 TypeScript 声明文件的 IntelliSense

我不需要更多信息。只是想看看一些建议。例如,我在文件a.js中编写了一些函数。当我在 b.js 文件中工作时,如何启用 intellsense(引用 a.js)。

最佳答案

我曾经添加/// <reference path="ScriptFile1.js" />在 .js 文件之上并且它可以工作,我还曾经将文件从解决方案资源管理器拖放到 js 文件中创建此引用线,但它不再在我当前的 VS 版本上工作。

更多相关信息请参见: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" />

此外,这篇文章也值得阅读以获得其他一些想法:https://madskristensen.net/post/the-story-behind-_referencesjs

关于javascript - 如何在 VS Code 中启用智能感知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45936904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com