Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

JavaScript Refactoring - Rename Identifier, Wrap selection, Convert to arrow function, Create Getters & Setters #13965

Merged
merged 16 commits into from
Dec 20, 2017
Merged
2 changes: 2 additions & 0 deletions src/JSUtils/MessageIds.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ define(function (require, exports, module) {
TERN_INFERENCE_TIMEDOUT = "InferenceTimedOut",
SET_CONFIG = "SetConfig",
TERN_UPDATE_DIRTY_FILE = "UpdateDirtyFileEntry",
TERN_REFS = "getRefs",
TERN_CLEAR_DIRTY_FILES_LIST = "ClearDirtyFilesList";

// Message parameter constants
Expand All @@ -62,6 +63,7 @@ define(function (require, exports, module) {
exports.SET_CONFIG = SET_CONFIG;
exports.TERN_UPDATE_DIRTY_FILE = TERN_UPDATE_DIRTY_FILE;
exports.TERN_CLEAR_DIRTY_FILES_LIST = TERN_CLEAR_DIRTY_FILES_LIST;
exports.TERN_REFS = TERN_REFS;
});


32 changes: 30 additions & 2 deletions src/JSUtils/ScopeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,28 @@ define(function (require, exports, module) {
return text;
}

/**
* Handle the response from the tern node domain when
* it responds with the references
*
* @param response - the response from the node domain
*/
function handleRename(response) {

if (response.error) {
EditorManager.getActiveEditor().displayErrorMessageAtCursor(response.error);
return;
}

var file = response.file,
offset = response.offset;

var $deferredFindRefs = getPendingRequest(file, offset, MessageIds.TERN_REFS);

if ($deferredFindRefs) {
$deferredFindRefs.resolveWith(null, [response]);
}
}

/**
* Request Jump-To-Definition from Tern.
Expand All @@ -390,10 +411,12 @@ define(function (require, exports, module) {
*/
function requestJumptoDef(session, document, offset) {
var path = document.file.fullPath,
fileInfo = {type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
fileInfo = {
type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
name: path,
offsetLines: 0,
text: filterText(session.getJavascriptText())};
text: filterText(session.getJavascriptText())
};

var ternPromise = getJumptoDef(fileInfo, offset);

Expand Down Expand Up @@ -1091,6 +1114,8 @@ define(function (require, exports, module) {
handleTernGetFile(response);
} else if (type === MessageIds.TERN_JUMPTODEF_MSG) {
handleJumptoDef(response);
} else if (type === MessageIds.TERN_REFS) {
handleRename(response);
} else if (type === MessageIds.TERN_PRIME_PUMP_MSG) {
handlePrimePumpCompletion(response);
} else if (type === MessageIds.TERN_GET_GUESSES_MSG) {
Expand Down Expand Up @@ -1557,5 +1582,8 @@ define(function (require, exports, module) {
exports.handleProjectClose = handleProjectClose;
exports.handleProjectOpen = handleProjectOpen;
exports._readyPromise = _readyPromise;
exports.filterText = filterText;
exports.postMessage = postMessage;
exports.addPendingRequest = addPendingRequest;

});
43 changes: 42 additions & 1 deletion src/JSUtils/node/TernNodeDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function initTernServer(env, files) {
defs: env,
async: true,
getFile: getFile,
plugins: {requirejs: {}, doc_comment: true, angular: true}
plugins: {requirejs: {}, commonjs: true, doc_comment: true, angular: true}
};

// If a server is already created just reset the analysis data before marking it for GC
Expand Down Expand Up @@ -236,6 +236,44 @@ function buildRequest(fileInfo, query, offset) {
return request;
}


/**
* Get all References location
* @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 getRefs(fileInfo, offset) {
var request = buildRequest(fileInfo, "refs", offset);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can fileInfo be null or undefined ever?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should not be the case. Anyways I handled this when we are creating fileInfo.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

try {
ternServer.request(request, function (error, data) {
if (error) {
_log("Error returned from Tern 'refs' request: " + error);
var response = {
type: MessageIds.TERN_REFS,
error: error.message
};
self.postMessage(response);
return;
}
var response = {
type: MessageIds.TERN_REFS,
file: fileInfo.name,
offset: offset,
references: data
};
// Post a message back to the main thread with the results
self.postMessage(response);
});
} catch (e) {
_reportError(e, fileInfo.name);
}
}

/**
* Get definition location
* @param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
Expand Down Expand Up @@ -745,6 +783,9 @@ function _requestTernServer(commandConfig) {
} else if (type === MessageIds.TERN_JUMPTODEF_MSG) {
offset = request.offset;
getJumptoDef(request.fileInfo, offset);
} else if (type === MessageIds.TERN_REFS) {
offset = request.offset;
getRefs(request.fileInfo, offset);
} else if (type === MessageIds.TERN_ADD_FILES_MSG) {
handleAddFiles(request.files);
} else if (type === MessageIds.TERN_PRIME_PUMP_MSG) {
Expand Down
Loading