Skip to content

Commit 8931117

Browse files
committed
init
0 parents  commit 8931117

7 files changed

+2173
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/require.intellisense.js

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#requirejs-intellisense
2+
3+
If you are using [RequireJS](http://requirejs.org), include this file to get Visual Studio Intellisense completion for your AMD modules.
4+
5+
Place require.intellisense.js next to your require.js file to enable the magic.
6+
7+
**Be sure** to keep the file named **require.intellisense.js**, otherwise it will not work.
8+
9+
## Demo
10+
11+
To try it out:
12+
13+
* clone this repo
14+
* copy require.intellisense.js to the test directory
15+
* open up the test directory as part of a Visual Studio project.
16+

require.intellisense.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/// <reference path="require.js" />
2+
3+
!function (window) {
4+
var defines = [],
5+
moduleUrls = [],
6+
oldDefine = window.define,
7+
oldRequire = window.require,
8+
oldLoad = requirejs.load;
9+
10+
var loadEvent = document.createEvent("event");
11+
loadEvent.type = "load";
12+
13+
// Ensure that we're only patching require/define
14+
// if RequireJS is the current AMD implementation
15+
if (window.require !== window.requirejs)
16+
return;
17+
18+
intellisense.annotate(window, {
19+
define: function () {
20+
/// <signature>
21+
/// <summary>Defines a named module, with optional dependencies, whose value is determined by executing a callback.</summary>
22+
/// <param name="name" type="String">The name of the module</param>
23+
/// <param name="deps" type="Array" elementType="String" optional="true">An array of modules that this module depends on</param>
24+
/// <param name="callback" type="Function">The callback that will be called when your module is asked to produce a value</param>
25+
/// </signature>
26+
/// <signature>
27+
/// <summary>Defines an anonymous module, with no dependencies, whose value is determined by executing a callback.</summary>
28+
/// <param name="callback" type="Function">The callback that will be called when your module is asked to produce a value</param>
29+
/// </signature>
30+
/// <signature>
31+
/// <summary>Defines an anonymous module, with no dependencies, whose value is an object literal.</summary>
32+
/// <param name="value" type="Object">The object literal that represents the value of this module</param>
33+
/// </signature>
34+
},
35+
require: function () {
36+
/// <signature>
37+
/// <summary>Defines a callback function that will be triggered after a set of dependency modules have been evaluated</summary>
38+
/// <param name="deps" type="Array" elementType="String"></param>
39+
/// <param name="callback" type="Function"></param>
40+
/// </signature>
41+
}
42+
});
43+
44+
requirejs.load = function (context, moduleName, url) {
45+
moduleUrls.push(url);
46+
oldLoad.call(requirejs, context, moduleName, url);
47+
}
48+
49+
window.define = function (name, deps, callback) {
50+
defines.push([deps, callback]);
51+
}
52+
53+
window.define.amd = {
54+
multiversion: true,
55+
plugins: true,
56+
jQuery: true
57+
};
58+
59+
window.require = function (deps, callback) {
60+
setTimeout(function () {
61+
// #1. Call the original require
62+
oldRequire.call(window, deps, callback);
63+
64+
defines.forEach(function (define, index) {
65+
oldDefine.apply(window, define);
66+
67+
var scriptElements = document.getElementsByTagName("script");
68+
69+
for (var i = 0; i < scriptElements.length; i++) {
70+
var script = scriptElements[i];
71+
if (script.src == moduleUrls[index]) {
72+
loadEvent.currentTarget = script;
73+
requirejs.onScriptLoad(loadEvent);
74+
}
75+
}
76+
});
77+
}, 0);
78+
}
79+
80+
// Redirect all of the patched methods back to their originals
81+
intellisense.redirectDefinition(requirejs.load, oldLoad);
82+
intellisense.redirectDefinition(window.define, oldDefine);
83+
intellisense.redirectDefinition(window.require, oldRequire);
84+
}(this);

test/default.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require(["js/test", "js/person"], function (test, person) {
2+
3+
});
4+

test/person.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
define("person", [], function () {
2+
return {
3+
firstName: "Jonathan",
4+
lastName: "Carter",
5+
age: 27
6+
};
7+
});

0 commit comments

Comments
 (0)