mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Merge branch 'master' of https://github.com/adobe/brackets into jumptodef
Conflicts: src/extensions/default/JavaScriptCodeHints/main.js
This commit is contained in:
commit
476bc5d41c
75 files changed
+3206
-1374
No files matched your search
@@ -38,6 +38,12 @@ define(function (require, exports, module) {
|
||||
TERN_GET_GUESSES_MSG = "GetGuesses",
|
||||
TERN_WORKER_READY = "WorkerReady";
|
||||
|
||||
// Message parameter constants
|
||||
var TERN_FILE_INFO_TYPE_PART = "part",
|
||||
TERN_FILE_INFO_TYPE_FULL = "full",
|
||||
TERN_FILE_INFO_TYPE_EMPTY = "empty";
|
||||
|
||||
|
||||
exports.TERN_ADD_FILES_MSG = TERN_ADD_FILES_MSG;
|
||||
exports.TERN_JUMPTODEF_MSG = TERN_JUMPTODEF_MSG;
|
||||
exports.TERN_COMPLETIONS_MSG = TERN_COMPLETIONS_MSG;
|
||||
@@ -47,6 +53,10 @@ define(function (require, exports, module) {
|
||||
exports.TERN_PRIME_PUMP_MSG = TERN_PRIME_PUMP_MSG;
|
||||
exports.TERN_GET_GUESSES_MSG = TERN_GET_GUESSES_MSG;
|
||||
exports.TERN_UPDATE_FILE_MSG = TERN_UPDATE_FILE_MSG;
|
||||
exports.TERN_WORKER_READY = TERN_WORKER_READY;
|
||||
exports.TERN_FILE_INFO_TYPE_PART = TERN_FILE_INFO_TYPE_PART;
|
||||
exports.TERN_FILE_INFO_TYPE_FULL = TERN_FILE_INFO_TYPE_FULL;
|
||||
exports.TERN_FILE_INFO_TYPE_EMPTY = TERN_FILE_INFO_TYPE_EMPTY;
|
||||
});
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -51,7 +51,8 @@ define(function (require, exports, module) {
|
||||
cachedHints = null, // sorted hints for the current hinting session
|
||||
cachedType = null, // describes the lookup type and the object context
|
||||
cachedToken = null, // the token used in the current hinting session
|
||||
matcher = null; // string matcher for hints
|
||||
matcher = null, // string matcher for hints
|
||||
ignoreChange; // can ignore next "change" event if true;
|
||||
|
||||
/**
|
||||
* Get the value of current session.
|
||||
@@ -374,6 +375,8 @@ define(function (require, exports, module) {
|
||||
// Compute fresh hints if none exist, or if the session
|
||||
// type has changed since the last hint computation
|
||||
if (this.needNewHints(session)) {
|
||||
ScopeManager.handleFileChange({from: cursor, to: cursor, text: [key]});
|
||||
ignoreChange = true;
|
||||
var scopeResponse = ScopeManager.requestHints(session, session.editor.document);
|
||||
|
||||
if (scopeResponse.hasOwnProperty("promise")) {
|
||||
@@ -527,8 +530,11 @@ define(function (require, exports, module) {
|
||||
if (editor && HintUtils.isSupportedLanguage(LanguageManager.getLanguageForPath(editor.document.file.fullPath).getId())) {
|
||||
initializeSession(editor, previousEditor, true);
|
||||
$(editor)
|
||||
.on(HintUtils.eventName("change"), function () {
|
||||
ScopeManager.handleFileChange(editor.document);
|
||||
.on(HintUtils.eventName("change"), function (event, editor, changeList) {
|
||||
if (!ignoreChange) {
|
||||
ScopeManager.handleFileChange(changeList);
|
||||
}
|
||||
ignoreChange = false;
|
||||
});
|
||||
} else {
|
||||
session = null;
|
||||
@@ -609,7 +615,7 @@ define(function (require, exports, module) {
|
||||
* Helper for QuickEdit jump-to-definition request.
|
||||
*/
|
||||
function quickEditHelper() {
|
||||
var offset = session.getOffset(),
|
||||
var offset = session.getCursor(),
|
||||
response = ScopeManager.requestJumptoDef(session, session.editor.document, offset);
|
||||
|
||||
return response;
|
||||
|
||||
@@ -77,10 +77,9 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
*
|
||||
* @param {Object} env - an Object with the environment, as read in from
|
||||
* the json files in thirdparty/tern/defs
|
||||
* @param {string} dir - the current directory
|
||||
* @param {Array.<string>} files - a list of filenames tern should be aware of
|
||||
*/
|
||||
function initTernServer(env, dir, files) {
|
||||
function initTernServer(env, files) {
|
||||
var ternOptions = {
|
||||
defs: env,
|
||||
async: true,
|
||||
@@ -94,33 +93,70 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build an object that can be used as a request to tern
|
||||
* @param {string} dir - the current directory
|
||||
* @param {string} file - the filename the request is in
|
||||
* @param {string} query - the type of request being made
|
||||
* @param {number} offset - the offset in the file the request is at
|
||||
* @param {string} text - the text of the file
|
||||
* Create a "full" update object.
|
||||
*
|
||||
* @param {string} path - full path of the file.
|
||||
* @param {string} text - full text of the file.
|
||||
* @return {{type: string, name: string, offsetLines: number, text: string}} -
|
||||
* "full" update.
|
||||
|
||||
*/
|
||||
function buildRequest(dir, file, query, offset, text) {
|
||||
function createFullUpdate(path, text) {
|
||||
return {type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
|
||||
name: path,
|
||||
offsetLines: 0,
|
||||
text: text};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a "empty" update object.
|
||||
*
|
||||
* @param {string} path - full path of the file.
|
||||
* @return {{type: string, name: string, offsetLines: number, text: string}} -
|
||||
* "empty" update.
|
||||
|
||||
*/
|
||||
function createEmptyUpdate(path) {
|
||||
return {type: MessageIds.TERN_FILE_INFO_TYPE_EMPTY,
|
||||
name: path,
|
||||
offsetLines: 0,
|
||||
text: ""};
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an object that can be used as a request to tern.
|
||||
*
|
||||
* @param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
|
||||
* - type of update, name of file, and the text of the update.
|
||||
* For "full" updates, the whole text of the file is present. For "part" updates,
|
||||
* the changed portion of the text. For "empty" updates, the file has not been modified
|
||||
* and the text is empty.
|
||||
* @param {string} query - the type of request being made
|
||||
* @param {{line: number, ch: number}} offset -
|
||||
*/
|
||||
function buildRequest(fileInfo, query, offset) {
|
||||
query = {type: query};
|
||||
query.start = offset;
|
||||
query.end = offset;
|
||||
query.file = file;
|
||||
query.file = (fileInfo.type === MessageIds.TERN_FILE_INFO_TYPE_PART) ? "#0" : fileInfo.name;
|
||||
query.filter = false;
|
||||
query.sort = false;
|
||||
query.depths = true;
|
||||
query.guess = true;
|
||||
query.origins = true;
|
||||
query.expandWordForward = false;
|
||||
|
||||
query.lineCharPositions = true;
|
||||
|
||||
var request = {query: query, files: [], offset: offset};
|
||||
request.files.push({type: "full", name: file, text: text});
|
||||
|
||||
if (fileInfo.type !== MessageIds.TERN_FILE_INFO_TYPE_EMPTY) {
|
||||
request.files.push(fileInfo);
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send a log message back from the worker to the main thread
|
||||
*
|
||||
@@ -132,26 +168,27 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
|
||||
/**
|
||||
* Get definition location
|
||||
* @param {string} dir - the directory
|
||||
* @param {string} file - the file name
|
||||
* @param {number} offset - the offset into the file for cursor
|
||||
* @param {string} text - the text of the file
|
||||
* @param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
|
||||
* - type of update, name of file, and the text of the update.
|
||||
* For "full" updates, the whole text of the file is present. For "part" updates,
|
||||
* the changed portion of the text. For "empty" updates, the file has not been modified
|
||||
* and the text is empty.
|
||||
* @param {{line: number, ch: number}} offset - the offset into the
|
||||
* file for cursor
|
||||
*/
|
||||
function getJumptoDef(dir, file, offset, text) {
|
||||
|
||||
var request = buildRequest(dir, file, "definition", offset, text);
|
||||
request.query.lineCharPositions = true;
|
||||
function getJumptoDef(fileInfo, offset) {
|
||||
var request = buildRequest(fileInfo, "definition", offset);
|
||||
// request.query.typeOnly = true; // FIXME: tern doesn't work exactly right yet.
|
||||
ternServer.request(request, function (error, data) {
|
||||
if (error) {
|
||||
_log("Error returned from Tern 'definition' request: " + error);
|
||||
self.postMessage({type: MessageIds.TERN_JUMPTODEF_MSG});
|
||||
self.postMessage({type: MessageIds.TERN_JUMPTODEF_MSG, file: fileInfo.name, offset: offset});
|
||||
return;
|
||||
}
|
||||
|
||||
// Post a message back to the main thread with the definition
|
||||
self.postMessage({type: MessageIds.TERN_JUMPTODEF_MSG,
|
||||
file: file,
|
||||
file: fileInfo.name,
|
||||
resultFile: data.file,
|
||||
offset: offset,
|
||||
start: data.start,
|
||||
@@ -163,15 +200,18 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
/**
|
||||
* Get all the known properties for guessing.
|
||||
*
|
||||
* @param {string} dir - the directory
|
||||
* @param {string} file - the file name
|
||||
* @param {number} offset - the offset into the file where we want completions for
|
||||
* @param {string} text - the text of the file
|
||||
* @param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
|
||||
* - type of update, name of file, and the text of the update.
|
||||
* For "full" updates, the whole text of the file is present. For "part" updates,
|
||||
* the changed portion of the text. For "empty" updates, the file has not been modified
|
||||
* and the text is empty.
|
||||
* @param {{line: number, ch: number}} offset -
|
||||
* the offset into the file where we want completions for
|
||||
* @param {string} type - the type of the message to reply with.
|
||||
*/
|
||||
function getTernProperties(dir, file, offset, text, type) {
|
||||
function getTernProperties(fileInfo, offset, type) {
|
||||
|
||||
var request = buildRequest(dir, file, "properties", undefined, text),
|
||||
var request = buildRequest(fileInfo, "properties", offset),
|
||||
i;
|
||||
//_log("tern properties: request " + request.type + dir + " " + file);
|
||||
ternServer.request(request, function (error, data) {
|
||||
@@ -188,8 +228,7 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
|
||||
// Post a message back to the main thread with the completions
|
||||
self.postMessage({type: type,
|
||||
dir: dir,
|
||||
file: file,
|
||||
file: fileInfo.name,
|
||||
offset: offset,
|
||||
properties: properties
|
||||
});
|
||||
@@ -198,16 +237,20 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
|
||||
/**
|
||||
* Get the completions for the given offset
|
||||
* @param {string} dir - the directory
|
||||
* @param {string} file - the file name
|
||||
* @param {number} offset - the offset into the file where we want completions for
|
||||
* @param {string} text - the text of the file
|
||||
*
|
||||
* @param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
|
||||
* - type of update, name of file, and the text of the update.
|
||||
* For "full" updates, the whole text of the file is present. For "part" updates,
|
||||
* the changed portion of the text. For "empty" updates, the file has not been modified
|
||||
* and the text is empty.
|
||||
* @param {{line: number, ch: number}} offset -
|
||||
* the offset into the file where we want completions for
|
||||
* @param {boolean} isProperty - true if getting a property hint,
|
||||
* otherwise getting an identifier hint.
|
||||
*/
|
||||
function getTernHints(dir, file, offset, text, isProperty) {
|
||||
function getTernHints(fileInfo, offset, isProperty) {
|
||||
|
||||
var request = buildRequest(dir, file, "completions", offset, text),
|
||||
var request = buildRequest(fileInfo, "completions", offset),
|
||||
i;
|
||||
|
||||
//_log("request " + dir + " " + file + " " + offset /*+ " " + text */);
|
||||
@@ -227,28 +270,31 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
if (completions.length > 0 || !isProperty) {
|
||||
// Post a message back to the main thread with the completions
|
||||
self.postMessage({type: MessageIds.TERN_COMPLETIONS_MSG,
|
||||
dir: dir,
|
||||
file: file,
|
||||
file: fileInfo.name,
|
||||
offset: offset,
|
||||
completions: completions
|
||||
});
|
||||
} else {
|
||||
// if there are no completions, then get all the properties
|
||||
getTernProperties(dir, file, offset, text, MessageIds.TERN_COMPLETIONS_MSG);
|
||||
getTernProperties(fileInfo, offset, MessageIds.TERN_COMPLETIONS_MSG);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the function type for the given offset
|
||||
* @param {string} dir - the directory
|
||||
* @param {string} file - the file name
|
||||
* @param {number} offset - the offset into the file where we want completions for
|
||||
* @param {string} text - the text of the file
|
||||
*
|
||||
* @param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
|
||||
* - type of update, name of file, and the text of the update.
|
||||
* For "full" updates, the whole text of the file is present. For "part" updates,
|
||||
* the changed portion of the text. For "empty" updates, the file has not been modified
|
||||
* and the text is empty.
|
||||
* @param {{line: number, ch: number}} offset -
|
||||
* the offset into the file where we want completions for
|
||||
*/
|
||||
function handleFunctionType(dir, file, pos, offset, text) {
|
||||
function handleFunctionType(fileInfo, offset) {
|
||||
|
||||
var request = buildRequest(dir, file, "type", pos, text);
|
||||
var request = buildRequest(fileInfo, "type", offset);
|
||||
|
||||
request.preferFunction = true;
|
||||
|
||||
@@ -263,8 +309,7 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
|
||||
// Post a message back to the main thread with the completions
|
||||
self.postMessage({type: MessageIds.TERN_CALLED_FUNC_TYPE_MSG,
|
||||
dir: dir,
|
||||
file: file,
|
||||
file: fileInfo.name,
|
||||
offset: offset,
|
||||
fnType: fnType
|
||||
});
|
||||
@@ -305,10 +350,10 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
* Make a completions request to tern to force tern to resolve files
|
||||
* and create a fast first lookup for the user.
|
||||
* @param {string} path - the path of the file
|
||||
* @param {string} text - the text of the file
|
||||
*/
|
||||
function handlePrimePump(path, text) {
|
||||
var request = buildRequest("", path, "completions", 0, text);
|
||||
function handlePrimePump(path) {
|
||||
var fileInfo = createEmptyUpdate(path);
|
||||
var request = buildRequest(fileInfo, "completions", {line: 0, ch: 0});
|
||||
|
||||
ternServer.request(request, function (error, data) {
|
||||
// Post a message back to the main thread
|
||||
@@ -319,49 +364,35 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
}
|
||||
|
||||
self.addEventListener("message", function (e) {
|
||||
var dir, file, text, offset,
|
||||
var file, text, offset,
|
||||
request = e.data,
|
||||
type = request.type;
|
||||
|
||||
if (type === MessageIds.TERN_INIT_MSG) {
|
||||
|
||||
dir = request.dir;
|
||||
var env = request.env,
|
||||
files = request.files;
|
||||
initTernServer(env, dir, files);
|
||||
initTernServer(env, files);
|
||||
} else if (type === MessageIds.TERN_COMPLETIONS_MSG) {
|
||||
dir = request.dir;
|
||||
file = request.file;
|
||||
text = request.text;
|
||||
offset = request.offset;
|
||||
getTernHints(dir, file, offset, text, request.isProperty);
|
||||
getTernHints(request.fileInfo, offset, request.isProperty);
|
||||
} else if (type === MessageIds.TERN_GET_FILE_MSG) {
|
||||
file = request.file;
|
||||
text = request.text;
|
||||
handleGetFile(file, text);
|
||||
} else if (type === MessageIds.TERN_CALLED_FUNC_TYPE_MSG) {
|
||||
dir = request.dir;
|
||||
file = request.file;
|
||||
text = request.text;
|
||||
offset = request.offset;
|
||||
var pos = request.pos;
|
||||
handleFunctionType(dir, file, pos, offset, text);
|
||||
handleFunctionType(request.fileInfo, offset);
|
||||
} else if (type === MessageIds.TERN_JUMPTODEF_MSG) {
|
||||
file = request.file;
|
||||
dir = request.dir;
|
||||
text = request.text;
|
||||
offset = request.offset;
|
||||
getJumptoDef(dir, file, offset, text);
|
||||
getJumptoDef(request.fileInfo, offset);
|
||||
} else if (type === MessageIds.TERN_ADD_FILES_MSG) {
|
||||
handleAddFiles(request.files);
|
||||
} else if (type === MessageIds.TERN_PRIME_PUMP_MSG) {
|
||||
handlePrimePump(request.path, request.text);
|
||||
handlePrimePump(request.path);
|
||||
} else if (type === MessageIds.TERN_GET_GUESSES_MSG) {
|
||||
dir = request.dir;
|
||||
file = request.file;
|
||||
text = request.text;
|
||||
offset = request.offset;
|
||||
getTernProperties(dir, file, offset, text, MessageIds.TERN_GET_GUESSES_MSG);
|
||||
getTernProperties(request.fileInfo, offset, MessageIds.TERN_GET_GUESSES_MSG);
|
||||
} else if (type === MessageIds.TERN_UPDATE_FILE_MSG) {
|
||||
handleUpdateFile(request.path, request.text);
|
||||
} else {
|
||||
|
||||
@@ -154,3 +154,99 @@ function testNonAscii() {
|
||||
hope["frenchçProp"] = "";
|
||||
|
||||
}
|
||||
|
||||
/* Add large comment to make this test over 250 lines which will trigger
|
||||
* partial updates to be used.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* end of large comment
|
||||
*/
|
||||
@@ -808,7 +808,7 @@ define(function (require, exports, module) {
|
||||
hintsPresentExact(hintObj, ["getAmountDue", "getName", "name", "setAmountDue"]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it("should show argument from from .prototype.Method", function () {
|
||||
var start = { line: 80, ch: 0 },
|
||||
testPos = { line: 80, ch: 24 };
|
||||
@@ -821,18 +821,6 @@ define(function (require, exports, module) {
|
||||
});
|
||||
});
|
||||
|
||||
it("should show guessed argument type from current passing parameter", function () {
|
||||
var start = { line: 80, ch: 0 },
|
||||
testPos = { line: 80, ch: 24 };
|
||||
|
||||
testDoc.replaceRange("myCustomer.setAmountDue(10)", start);
|
||||
testEditor.setCursorPos(testPos);
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
runs(function () {
|
||||
hintsPresentOrdered(hintObj, ["setAmountDue(amountDue: number)"]);
|
||||
});
|
||||
});
|
||||
|
||||
it("should show inner function type", function () {
|
||||
var testPos = { line: 96, ch: 23 };
|
||||
|
||||
@@ -1083,6 +1071,19 @@ define(function (require, exports, module) {
|
||||
// check we have a properties that start with "shift"
|
||||
hintsPresentOrdered(hintObj, ["frenchçProp"]);
|
||||
});
|
||||
|
||||
it("should show guessed argument type from current passing parameter", function () {
|
||||
var start = { line: 80, ch: 0 },
|
||||
testPos = { line: 80, ch: 24 };
|
||||
console.log("should show guessed...");
|
||||
testDoc.replaceRange("myCustomer.setAmountDue(10)", start);
|
||||
testEditor.setCursorPos(testPos);
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
runs(function () {
|
||||
hintsPresentOrdered(hintObj, ["setAmountDue(amountDue: number)"]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("JavaScript Code Hinting in a HTML file", function () {
|
||||
|
||||
Reference in new issue
Block a user