Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
81ef26d
Add submodules for tern and acorn
Mar 18, 2013
832aaa2
prototyping hooking up ternjs to power codehints.
Mar 18, 2013
4369247
Update tern submodule to pick up recent bugfixes
Mar 20, 2013
cb4e0c6
Fix up tern completions - format changed slightly
Mar 20, 2013
3c874bf
Hook up multiple files for ternjs hinting.
Mar 21, 2013
9689288
Update to latest tern - at least one infinite loop fixed
Mar 21, 2013
d648572
Fix problem where hints are displayed before tern has finished comput…
Mar 21, 2013
dd63429
Update to latest tern - fixes a hang on some files
eztierney Mar 22, 2013
46365a6
Find builtin .json files in new location.
eztierney Mar 22, 2013
f4bcdfc
case insensitive matches, middle matching, and use tern rawCompletion…
Mar 25, 2013
7361589
Merge remote-tracking branch 'upstream/tern-experiments' into tern-ex…
Mar 26, 2013
e4a1855
change tern query not to sort or filter the results
Mar 26, 2013
412dedf
Move tern server into a web-worker.
eztierney Mar 26, 2013
8032353
use eztierney fork of tern.git
Mar 26, 2013
3d253d8
change tern submodule url from http:// to https://
Mar 26, 2013
f9bb81f
merge in changes from eztierney/brackets
Mar 26, 2013
25069f3
remove console.log
Mar 26, 2013
33579f6
roll back tern submodule to avoid hang
eztierney Mar 26, 2013
7bfaedf
Use tern to sort ids by depth, remove scope info
Mar 28, 2013
97a977c
Merge pull request #2 from dloverin/more-tern
eztierney Mar 28, 2013
7ac5459
fix bug where hints disappear on first character
Mar 28, 2013
a0ee374
fix bug where hints disappear after first key press
Mar 28, 2013
fcd7782
Merge pull request #3 from dloverin/more-tern
eztierney Mar 28, 2013
98d05fd
Update to version of tern with bugfixes to avoid hang when requesting…
eztierney Mar 28, 2013
4e6c8f5
Update to tern with getfile fixes
eztierney Mar 29, 2013
9a21f42
Add license file for requirejs
eztierney Mar 29, 2013
963474a
Merge branch 'master' into tern-experiments, to bring tern work up to…
eztierney Mar 29, 2013
d947130
Add alphabetical secondary sort when bringing prefix matches to the top
Mar 29, 2013
bf7404a
Add alphabetical secondary sort when bringing prefix matches to the top
Mar 29, 2013
01f6b2c
add browser.json to tern environment by default
Mar 29, 2013
9bf0b9f
fix bug where no hints would be provided after '('
Mar 29, 2013
8a6d29f
Merge pull request #4 from dloverin/more-tern
eztierney Mar 29, 2013
0746864
Remove espirma and related scope info code
Mar 29, 2013
08f356c
Merge pull request #5 from dloverin/cleanup-esprima
eztierney Mar 29, 2013
63c89f4
Add support for hinting function types.
eztierney Apr 2, 2013
98e37b1
Merge branch 'master' into tern-experiments
eztierney Apr 3, 2013
c1f1e44
Update to latest tern and acorn
eztierney Apr 3, 2013
7ed099f
Update submodule to latest tern
eztierney Apr 4, 2013
6666bd7
Switch submodules to point to the real acorn and tern instead of my fork
eztierney Apr 4, 2013
c05e551
Merge branch 'tern-experiments' of https://github.com/eztierney/brack…
eztierney Apr 5, 2013
d371c0f
Fix JSHint warnings and exclude tern and acorn related files from grunt.
petetronic Apr 5, 2013
ee09d6a
Removing unnecessary exclude from grunt.
petetronic Apr 5, 2013
3107c97
Merge pull request #1 from pfarland/js-code-intelligence
eztierney Apr 5, 2013
c887e87
new guessing
Apr 3, 2013
dac2002
Add guesses to code hints
Apr 5, 2013
9d56227
remove requestProperties
Apr 5, 2013
aab1d58
more grunt cleanup
eztierney Apr 5, 2013
ecfb080
Remove left over debugging code
eztierney Apr 5, 2013
d545327
fixes #2 and #4 - function type hinting
eztierney Apr 5, 2013
7af5378
Merge pull request #9 from eztierney/iss-2-4
Apr 5, 2013
bef501f
Update to latest tern - fixes issue #3
eztierney Apr 8, 2013
af9a7f0
Added Goto Definition.
jeffkenton Apr 8, 2013
7bb13ce
Code cleanup from Erik's review.
jeffkenton Apr 8, 2013
42ad4f7
Cleanup grunt complaints.
jeffkenton Apr 9, 2013
7d52361
Add StringUtils.htmlEscape() back in.
Apr 9, 2013
87de92d
Hook up initial requirejs support.
eztierney Apr 10, 2013
fdb8f5b
Merge pull request #16 from eztierney/js-code-intelligence
Apr 10, 2013
c097d19
log error for tern 'type' request
Apr 11, 2013
fa2bebc
Cleanup - mostly deleting unused code
eztierney Apr 11, 2013
8131900
Some unit test cleanup
eztierney Apr 11, 2013
c3919ed
Fix timing problem.
eztierney Apr 11, 2013
ee2dd1d
Fix for issue when multiple requests were made
eztierney Apr 11, 2013
cf26938
Update to newest tern to pick up some bugfixes
eztierney Apr 12, 2013
0bab9dc
Make Jump-To-Definition switch to new file when definition isn't loca…
jeffkenton Apr 12, 2013
5faff1d
Merge pull request #22 from jeffkenton/js-code-intelligence
eztierney Apr 12, 2013
40e1599
Remove tern and acorn from current location
eztierney Apr 12, 2013
1c62677
Move tern and acorn submodules into thirdparty directory.
eztierney Apr 12, 2013
5e11b5a
Updates to expected results.
eztierney Apr 12, 2013
51edab6
Fix Jump-To-Definition bug: trying to open new file when search fails.
jeffkenton Apr 12, 2013
e46d260
Get all unit tests passing
eztierney Apr 12, 2013
05e0640
Update tern to pick up a bugfix around Object properties
eztierney Apr 12, 2013
aeee6aa
If we can't find a file relative to the current dir, look relative to…
eztierney Apr 12, 2013
ec9a5af
Remember the resolved path we used with tern so that jump to definiti…
petetronic Apr 12, 2013
2e357e6
Merge branch 'master' into js-code-intelligence
eztierney Apr 12, 2013
d7adb07
Fix merge snafu
eztierney Apr 12, 2013
aba25e2
use StringMatch class to sort hints
Apr 10, 2013
a2598a9
sort library globals below user globals
Apr 12, 2013
6f19820
Remove refreshOuterScope
Apr 13, 2013
ab0b372
Get hint value from 'label' property instead of 'value' property
Apr 13, 2013
3eee0be
use .value instead of .label to reduce confusion
Apr 13, 2013
d96d73d
cleanup jslint warnings
eztierney Apr 15, 2013
e0c551d
remove unused hinting for globals
Apr 15, 2013
77a1b7f
Grunt cleanup, and deleted more unused code
eztierney Apr 15, 2013
9037188
Merge branch 'js-code-intelligence' into 'master'
eztierney Apr 15, 2013
e5e028e
remove pending requests and send message from tern-worker on Tern errors
Apr 15, 2013
20423c9
fix grunt warning
Apr 15, 2013
dbb7d3f
Merge branch 'js-code-intelligence' to pick up fix for Issue #30
eztierney Apr 15, 2013
33a016d
Change for-in loop to Collections.forEach to satify JSLint (looks lik…
Apr 15, 2013
daa64a3
cleanup from code review
eztierney Apr 16, 2013
ebc6b64
Add some more unit tests
eztierney Apr 16, 2013
0f43f54
remove CollectionsUtils.hasProperty inside of CollectionUtils.forEach
Apr 16, 2013
c5052f8
Add a couple of unit tests for jump to definition
eztierney Apr 16, 2013
725a1e8
remove Collections.forEach loop
Apr 17, 2013
f6a073c
When typing, only automatically show hints for the "." character and …
Apr 17, 2013
5a2efdf
add jquery api to hints
Apr 17, 2013
7b31da7
fix problem where jQuery was not recognized as a builtin
Apr 18, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
[submodule "src/thirdparty/mustache"]
path = src/thirdparty/mustache
url = https://github.com/janl/mustache.js.git
[submodule "src/extensions/default/JavaScriptCodeHints/thirdparty/tern"]
path = src/extensions/default/JavaScriptCodeHints/thirdparty/tern
url = https://github.com/marijnh/tern.git
[submodule "src/extensions/default/JavaScriptCodeHints/thirdparty/acorn"]
path = src/extensions/default/JavaScriptCodeHints/thirdparty/acorn
url = https://github.com/marijnh/acorn.git
258 changes: 38 additions & 220 deletions src/extensions/default/JavaScriptCodeHints/HintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@
define(function (require, exports, module) {
"use strict";

var LANGUAGE_ID = "javascript",
SCOPE_MSG_TYPE = "outerScope",
SINGLE_QUOTE = "\'",
DOUBLE_QUOTE = "\"";
var LANGUAGE_ID = "javascript",
SINGLE_QUOTE = "'",
DOUBLE_QUOTE = "\"",
TERN_INIT_MSG = "Init",
TERN_JUMPTODEF_MSG = "JumptoDef",
TERN_COMPLETIONS_MSG = "Completions",
TERN_GET_FILE_MSG = "GetFile",
TERN_GET_PROPERTIES_MSG = "Properties",
TERN_CALLED_FUNC_TYPE_MSG = "FunctionType";

/**
* Create a hint token with name value that occurs at the given list of
Expand All @@ -57,9 +62,7 @@ define(function (require, exports, module) {
* @return {boolean} - could key be a valid identifier?
*/
function maybeIdentifier(key) {
return (/[0-9a-z_.\$]/i).test(key) ||
(key.indexOf(SINGLE_QUOTE) === 0) ||
(key.indexOf(DOUBLE_QUOTE) === 0);
return (/[0-9a-z_\$]/i).test(key);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obviously not a regression from current behavior, but I do wonder if this code is going to fail on valid identifiers. Ahh, I see. It does fail some in that if I have a variable called façade, if I type faç the hinting stops until I hit the a. Anyhow, it's a minor point and nothing to fix now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thats obviously not going to work.

I filed adobe-research#38 - we probably just want to ask the token if it is an identifier, since the token should have the correct info.

}

/**
Expand All @@ -78,7 +81,18 @@ define(function (require, exports, module) {
return true;
}
}


/**
* Determine if hints should be displayed for the given key.
*
* @param {string} key - key entered by the user
* @return {boolean} true if the hints should be shown for the key,
* false otherwise.
*/
function hintableKey(key) {
return (key === null || key === "." || maybeIdentifier(key));
}

/**
* Divide a path into directory and filename parts
*
Expand All @@ -89,7 +103,7 @@ define(function (require, exports, module) {
function splitPath(path) {
var index = path.lastIndexOf("/"),
dir = path.substring(0, index),
file = path.substring(index, path.length);
file = path.substring(index + 1, path.length);

return {dir: dir, file: file };
}
Expand All @@ -106,93 +120,36 @@ define(function (require, exports, module) {
return name + "." + EVENT_TAG;
}

/*
* Annotate list of identifiers with their scope level.
*
* @param {Array.<Object>} identifiers - list of identifier tokens to be
* annotated
* @param {Scope} scope - scope object used to determine the scope level of
* each identifier token in the previous list.
* @return {Array.<Object>} - the input array; to each object in the array a
* new level {number} property has been added to indicate its scope
* level.
*/
function annotateWithScope(identifiers, scope) {
return identifiers.map(function (t) {
var level = scope.contains(t.value);

if (level >= 0) {
t.level = level;
} else {
t.level = -1;
}
return t;
});
}

/*
* Annotate a list of properties with their association level
*
* @param {Array.<Object>} properties - list of property tokens
* @param {Association} association - an object that maps property
* names to the number of times it occurs in a particular context
* @return {Array.<Object>} - the input array; to each object in the array a
* new level {number} property has been added to indicate the number
* of times the property has occurred in the association context.
*/
function annotateWithAssociation(properties, association) {
return properties.map(function (t) {
if (association[t.value] > 0) {
t.level = 0;
}
return t;
});
}

/*
* Annotate a list of tokens as being global variables
*
* @param {Array.<Object>} globals - list of identifier tokens
* @return {Array.<Object>} - the input array; to each object in the array a
* new global {boolean} property has been added to indicate that it is
* a global variable.
*/
function annotateGlobals(globals) {
return globals.map(function (t) {
t.global = true;
return t;
});
}

/*
* Annotate a list of tokens as literals of a particular kind;
* if string literals, annotate with an appropriate delimiter.
*
* if string literals, annotate with an appropriate delimiter.
*
* @param {Array.<Object>} literals - list of hint tokens
* @param {string} kind - the kind of literals in the list (e.g., "string")
* @return {Array.<Object>} - the input array; to each object in the array a
* new literal {boolean} property has been added to indicate that it
* is a literal hint, and also a new kind {string} property to indicate
* the literal kind. For string literals, a delimiter property is also
* added to indicate what the default delimiter should be (viz. a
* added to indicate what the default delimiter should be (viz. a
* single or double quotation mark).
*/
function annotateLiterals(literals, kind) {
return literals.map(function (t) {
t.literal = true;
t.kind = kind;
t.origin = "ecma5";
if (kind === "string") {
if (/[\\\\]*[^\\]"/.test(t.value)) {
t.delimeter = SINGLE_QUOTE;
t.delimiter = SINGLE_QUOTE;
} else {
t.delimeter = DOUBLE_QUOTE;
t.delimiter = DOUBLE_QUOTE;
}
}
return t;
});
}

/*
/*
* Annotate a list of tokens as keywords
*
* @param {Array.<Object>} keyword - list of keyword tokens
Expand All @@ -203,31 +160,11 @@ define(function (require, exports, module) {
function annotateKeywords(keywords) {
return keywords.map(function (t) {
t.keyword = true;
t.origin = "ecma5";
return t;
});
}

/*
* Annotate a list of tokens with a path name
*
* @param {Array.<Object>} tokens - list of hint tokens
* @param {string} dir - directory with which to annotate the hints
* @param {string} file - file name with which to annotate the hints
* @return {Array.<Object>} - the input array; to each object in the array a
* new path {string} property has been added, equal to dir + file.
*/
function annotateWithPath(tokens, dir, file) {
var path = dir + file;

return tokens.map(function (t) {
t.path = path;
return t;
});
}

// TODO 1: The definitions below should be defined in a separate JSON file.
// TODO 2: Add properties and associations for the builtin globals.

var KEYWORD_NAMES = [
"break", "case", "catch", "continue", "debugger", "default", "delete",
"do", "else", "finally", "for", "function", "if", "in", "instanceof",
Expand All @@ -247,141 +184,22 @@ define(function (require, exports, module) {
}),
LITERALS = annotateLiterals(LITERAL_TOKENS);

var JSL_GLOBAL_NAMES = [
"clearInterval", "clearTimeout", "document", "event", "frames",
"history", "Image", "location", "name", "navigator", "Option",
"parent", "screen", "setInterval", "setTimeout", "window",
"XMLHttpRequest", "alert", "confirm", "console", "Debug", "opera",
"prompt", "WSH", "Buffer", "exports", "global", "module", "process",
"querystring", "require", "__filename", "__dirname", "defineClass",
"deserialize", "gc", "help", "load", "loadClass", "print", "quit",
"readFile", "readUrl", "runCommand", "seal", "serialize", "spawn",
"sync", "toint32", "version", "ActiveXObject", "CScript", "Enumerator",
"System", "VBArray", "WScript"
],
JSL_GLOBAL_TOKENS = annotateGlobals(JSL_GLOBAL_NAMES.map(function (t) {
return makeToken(t, []);
})),
JSL_GLOBALS = JSL_GLOBAL_TOKENS.reduce(function (prev, curr) {
prev[curr.value] = curr;
return prev;
}, {}); // builds an object from the array of tokens.

// Predefined sets of globals as defined by JSLint
var JSL_GLOBALS_BROWSER = [
JSL_GLOBALS.clearInterval,
JSL_GLOBALS.clearTimeout,
JSL_GLOBALS.document,
JSL_GLOBALS.event,
JSL_GLOBALS.frames,
JSL_GLOBALS.history,
JSL_GLOBALS.Image,
JSL_GLOBALS.location,
JSL_GLOBALS.name,
JSL_GLOBALS.navigator,
JSL_GLOBALS.Option,
JSL_GLOBALS.parent,
JSL_GLOBALS.screen,
JSL_GLOBALS.setInterval,
JSL_GLOBALS.setTimeout,
JSL_GLOBALS.window,
JSL_GLOBALS.XMLHttpRequest
],
JSL_GLOBALS_DEVEL = [
JSL_GLOBALS.alert,
JSL_GLOBALS.confirm,
JSL_GLOBALS.console,
JSL_GLOBALS.Debug,
JSL_GLOBALS.opera,
JSL_GLOBALS.prompt,
JSL_GLOBALS.WSH
],
JSL_GLOBALS_NODE = [
JSL_GLOBALS.Buffer,
JSL_GLOBALS.clearInterval,
JSL_GLOBALS.clearTimeout,
JSL_GLOBALS.console,
JSL_GLOBALS.exports,
JSL_GLOBALS.global,
JSL_GLOBALS.module,
JSL_GLOBALS.process,
JSL_GLOBALS.querystring,
JSL_GLOBALS.require,
JSL_GLOBALS.setInterval,
JSL_GLOBALS.setTimeout,
JSL_GLOBALS.__filename,
JSL_GLOBALS.__dirname
],
JSL_GLOBALS_RHINO = [
JSL_GLOBALS.defineClass,
JSL_GLOBALS.deserialize,
JSL_GLOBALS.gc,
JSL_GLOBALS.help,
JSL_GLOBALS.load,
JSL_GLOBALS.loadClass,
JSL_GLOBALS.print,
JSL_GLOBALS.quit,
JSL_GLOBALS.readFile,
JSL_GLOBALS.readUrl,
JSL_GLOBALS.runCommand,
JSL_GLOBALS.seal,
JSL_GLOBALS.serialize,
JSL_GLOBALS.spawn,
JSL_GLOBALS.sync,
JSL_GLOBALS.toint32,
JSL_GLOBALS.version
],
JSL_GLOBALS_WINDOWS = [
JSL_GLOBALS.ActiveXObject,
JSL_GLOBALS.CScript,
JSL_GLOBALS.Debug,
JSL_GLOBALS.Enumerator,
JSL_GLOBALS.System,
JSL_GLOBALS.VBArray,
JSL_GLOBALS.WScript,
JSL_GLOBALS.WSH
];

var JSL_GLOBAL_DEFS = {
browser : JSL_GLOBALS_BROWSER,
devel : JSL_GLOBALS_DEVEL,
node : JSL_GLOBALS_NODE,
rhino : JSL_GLOBALS_RHINO,
windows : JSL_GLOBALS_WINDOWS
};

var BUILTIN_GLOBAL_NAMES = [
"Array", "Boolean", "Date", "Function", "Iterator", "Number", "Object",
"RegExp", "String", "ArrayBuffer", "DataView", "Float32Array",
"Float64Array", "Int16Array", "Int32Array", "Int8Array", "Uint16Array",
"Uint32Array", "Uint8Array", "Uint8ClampedArray", "Error", "EvalError",
"InternalError", "RangeError", "ReferenceError", "StopIteration",
"SyntaxError", "TypeError", "URIError", "decodeURI",
"decodeURIComponent", "encodeURI", "encodeURIComponent", "eval",
"isFinite", "isNaN", "parseFloat", "parseInt", "uneval", "Infinity",
"JSON", "Math", "NaN"
],
BUILTIN_GLOBAL_TOKENS = BUILTIN_GLOBAL_NAMES.map(function (t) {
return makeToken(t, []);
}),
BUILTIN_GLOBALS = annotateGlobals(BUILTIN_GLOBAL_TOKENS);

exports.makeToken = makeToken;
exports.hintable = hintable;
exports.hintableKey = hintableKey;
exports.maybeIdentifier = maybeIdentifier;
exports.splitPath = splitPath;
exports.eventName = eventName;
exports.annotateWithPath = annotateWithPath;
exports.annotateLiterals = annotateLiterals;
exports.annotateGlobals = annotateGlobals;
exports.annotateWithScope = annotateWithScope;
exports.annotateWithAssociation = annotateWithAssociation;
exports.JSL_GLOBAL_DEFS = JSL_GLOBAL_DEFS;
exports.BUILTIN_GLOBALS = BUILTIN_GLOBALS;
exports.KEYWORDS = KEYWORDS;
exports.LITERALS = LITERALS;
exports.LANGUAGE_ID = LANGUAGE_ID;
exports.SCOPE_MSG_TYPE = SCOPE_MSG_TYPE;
exports.SINGLE_QUOTE = SINGLE_QUOTE;
exports.DOUBLE_QUOTE = DOUBLE_QUOTE;
exports.TERN_JUMPTODEF_MSG = TERN_JUMPTODEF_MSG;
exports.TERN_COMPLETIONS_MSG = TERN_COMPLETIONS_MSG;
exports.TERN_INIT_MSG = TERN_INIT_MSG;
exports.TERN_GET_FILE_MSG = TERN_GET_FILE_MSG;
exports.TERN_GET_PROPERTIES_MSG = TERN_GET_PROPERTIES_MSG;
exports.TERN_CALLED_FUNC_TYPE_MSG = TERN_CALLED_FUNC_TYPE_MSG;
});
Loading