mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
sort library globals below user globals
turn on query.guess to get previously used properties of unknown types turn on query.origins to get categorize library globals vs. user globals turn on query.expandWordForward to fix hasOwnProperty bug.
This commit is contained in:
1 parent
aba25e2705
commit
a2598a9753
5 files changed
+49
-24
No files matched your search
@@ -143,6 +143,7 @@ define(function (require, exports, module) {
|
||||
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;
|
||||
@@ -165,6 +166,7 @@ define(function (require, exports, module) {
|
||||
function annotateKeywords(keywords) {
|
||||
return keywords.map(function (t) {
|
||||
t.keyword = true;
|
||||
t.origin = "ecma5";
|
||||
return t;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ define(function (require, exports, module) {
|
||||
var fileState = {}, // directory -> file -> state
|
||||
ternEnvironment = [],
|
||||
pendingTernRequests = {},
|
||||
_builtins = ["ecma5.json", "browser.json"],
|
||||
rootTernDir = null,
|
||||
projectRoot = null,
|
||||
ternPromise = null,
|
||||
@@ -67,14 +68,23 @@ define(function (require, exports, module) {
|
||||
});
|
||||
rootTernDir = dir + "/";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An array of JSON files names contain JavaScript builtins definitions.
|
||||
*
|
||||
* @returns {Array} - array of filenames.
|
||||
*/
|
||||
function getBuiltins() {
|
||||
return _builtins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read in the json files that have type information for the builtins, dom,etc
|
||||
*/
|
||||
function initTernEnv() {
|
||||
var path = module.uri.substring(0, module.uri.lastIndexOf("/") + 1) + "thirdparty/tern/defs/";
|
||||
var files = ["ecma5.json", "browser.json"];//, "plugin/requirejs/requirejs.json", "jquery.json"];
|
||||
|
||||
var files = getBuiltins();
|
||||
|
||||
files.forEach(function (i) {
|
||||
DocumentManager.getDocumentForPath(path + i).done(function (document) {
|
||||
ternEnvironment.push(JSON.parse(document.getText()));
|
||||
@@ -509,7 +519,7 @@ define(function (require, exports, module) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
exports.getBuiltins = getBuiltins;
|
||||
exports.handleEditorChange = handleEditorChange;
|
||||
exports.handleFileChange = handleFileChange;
|
||||
exports.requestJumptoDef = requestJumptoDef;
|
||||
|
||||
@@ -28,7 +28,8 @@ define(function (require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var StringMatch = brackets.getModule("utils/StringMatch"),
|
||||
HintUtils = require("HintUtils");
|
||||
HintUtils = require("HintUtils"),
|
||||
ScopeManager = require("ScopeManager");
|
||||
|
||||
/**
|
||||
* Session objects encapsulate state associated with a hinting session
|
||||
@@ -43,6 +44,17 @@ define(function (require, exports, module) {
|
||||
this.ternHints = [];
|
||||
this.ternProperties = [];
|
||||
this.fnType = null;
|
||||
this.builtins = ScopeManager.getBuiltins().map(function (builtin) {
|
||||
// remove extension from name, if any.
|
||||
var index = builtin.lastIndexOf(".");
|
||||
if (index !== -1) {
|
||||
builtin = builtin.substring(0, index);
|
||||
}
|
||||
|
||||
return builtin;
|
||||
});
|
||||
|
||||
this.builtins.push("requirejs.js"); // consider these globals as well.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,23 +316,13 @@ define(function (require, exports, module) {
|
||||
|
||||
var MAX_DISPLAYED_HINTS = 500;
|
||||
|
||||
/*
|
||||
* Remove the special "<i>" property from the hints.
|
||||
/**
|
||||
* Is the origin one of the builtin files.
|
||||
*
|
||||
* @param {Array} hints - sorted hints
|
||||
* @param {string} origin
|
||||
*/
|
||||
function removeArrayIndexProperty(hints) {
|
||||
var n = hints.length,
|
||||
i;
|
||||
for (i = 0; i < n; i++) {
|
||||
var value = hints[i].label;
|
||||
if (value === "<i>") {
|
||||
hints.splice(i, 1);
|
||||
return;
|
||||
} else if (value > "<i>") {
|
||||
return;
|
||||
}
|
||||
}
|
||||
function isBuiltin(origin) {
|
||||
return builtins.indexOf(origin) !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,6 +343,13 @@ define(function (require, exports, module) {
|
||||
if (hint.depth !== undefined) {
|
||||
searchResult.depth = hint.depth;
|
||||
}
|
||||
|
||||
if (!type.property && !type.showFunctionType && hint.origin &&
|
||||
isBuiltin(hint.origin)) {
|
||||
searchResult.builtin = 1;
|
||||
} else {
|
||||
searchResult.builtin = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return searchResult;
|
||||
@@ -350,6 +359,7 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
var type = this.getType(),
|
||||
builtins = this.builtins,
|
||||
hints;
|
||||
|
||||
if (type.property) {
|
||||
@@ -362,7 +372,6 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
StringMatch.multiFieldSort(hints, { matchGoodness: 0, label: 1 });
|
||||
removeArrayIndexProperty(hints);
|
||||
} else if ( type.showFunctionType ) {
|
||||
hints = this.getFunctionTypeHint();
|
||||
} else { // identifiers, literals, and keywords
|
||||
@@ -370,7 +379,7 @@ define(function (require, exports, module) {
|
||||
hints = hints.concat(HintUtils.LITERALS);
|
||||
hints = hints.concat(HintUtils.KEYWORDS);
|
||||
hints = filterWithQueryAndMatcher(hints, matcher);
|
||||
StringMatch.multiFieldSort(hints, { matchGoodness: 0, depth: 1, label: 2 });
|
||||
StringMatch.multiFieldSort(hints, { matchGoodness: 0, depth: 1, builtin: 2, label: 3 });
|
||||
}
|
||||
|
||||
if (hints.length > MAX_DISPLAYED_HINTS) {
|
||||
|
||||
@@ -127,6 +127,7 @@ define(function (require, exports, module) {
|
||||
} else {
|
||||
$hintObj.text(token.label);
|
||||
}
|
||||
|
||||
$hintObj.data("token", token);
|
||||
|
||||
return $hintObj;
|
||||
|
||||
@@ -97,7 +97,9 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
query.filter = false;
|
||||
query.sort = false;
|
||||
query.depths = true;
|
||||
query.guess = false;
|
||||
query.guess = true;
|
||||
query.origins = true;
|
||||
query.expandWordForward = true;
|
||||
|
||||
var request = {query:query, files:[], offset:offset};
|
||||
request.files.push({type:"full", name:file, text:text});
|
||||
@@ -155,7 +157,8 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
//_log("found " + completions.length + " for " + file + "@" + offset);
|
||||
for (var i = 0; i < data.completions.length; ++i) {
|
||||
var completion = data.completions[i];
|
||||
completions.push({value: completion.name, type: completion.type, depth: completion.depth, guess: completion.guess});
|
||||
completions.push({value: completion.name, type: completion.type, depth: completion.depth,
|
||||
guess: completion.guess, origin: completion.origin});
|
||||
}
|
||||
|
||||
// Post a message back to the main thread with the completions
|
||||
|
||||
Reference in new issue
Block a user