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

Added a check of Untitled doc in _getNormalizedFilename and _getDenormalizedFilename #13201

Merged
merged 1 commit into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 8 additions & 7 deletions src/extensions/default/JavaScriptCodeHints/ScopeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,11 @@ define(function (require, exports, module) {
* @param {string} path - full path of file
* @return {jQuery.Promise} - the promise for the request
*/
function primePump(path) {
function primePump(path, isUntitledDoc) {
_postMessageByPass({
type : MessageIds.TERN_PRIME_PUMP_MSG,
path : path
type : MessageIds.TERN_PRIME_PUMP_MSG,
path : path,
isUntitledDoc : isUntitledDoc
});

return addPendingRequest(path, OFFSET_ZERO, MessageIds.TERN_PRIME_PUMP_MSG);
Expand Down Expand Up @@ -1152,7 +1153,7 @@ define(function (require, exports, module) {
if (isDocumentDirty && previousDocument) {
var updateFilePromise = updateTernFile(previousDocument);
updateFilePromise.done(function () {
primePump(path);
primePump(path, document.isUntitled());
addFilesDeferred.resolveWith(null, [_ternWorker]);
});
} else {
Expand All @@ -1171,7 +1172,7 @@ define(function (require, exports, module) {
deferredPreferences.done(function () {
if (file instanceof InMemoryFile) {
initTernServer(pr, []);
var hintsPromise = primePump(path);
var hintsPromise = primePump(path, true);
hintsPromise.done(function () {
addFilesDeferred.resolveWith(null, [_ternWorker]);
});
Expand Down Expand Up @@ -1202,7 +1203,7 @@ define(function (require, exports, module) {

initTernServer(dir, files);

var hintsPromise = primePump(path);
var hintsPromise = primePump(path, false);
hintsPromise.done(function () {
if (!usingModules()) {
// Read the subdirectories of the new file's directory.
Expand All @@ -1217,7 +1218,7 @@ define(function (require, exports, module) {
addAllFilesAndSubdirectories(projectRoot, function () {
// prime the pump again but this time don't wait
// for completion.
primePump(path);
primePump(path, false);

addFilesDeferred.resolveWith(null, [_ternWorker]);
});
Expand Down
8 changes: 5 additions & 3 deletions src/extensions/default/JavaScriptCodeHints/tern-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ var config = {};
Infer = infer;

var ternServer = null,
inferenceTimeout;
inferenceTimeout,
isUntitledDoc = false;

// Save the tern callbacks for when we get the contents of the file
var fileCallBacks = {};
Expand Down Expand Up @@ -107,14 +108,14 @@ var config = {};
}

function _getNormalizedFilename(fileName) {
if (ternServer.projectDir && fileName.indexOf(ternServer.projectDir) === -1) {
if (!isUntitledDoc && ternServer.projectDir && fileName.indexOf(ternServer.projectDir) === -1) {
fileName = ternServer.projectDir + fileName;
}
return fileName;
}

function _getDenormalizedFilename(fileName) {
if (ternServer.projectDir && fileName.indexOf(ternServer.projectDir) === 0) {
if (!isUntitledDoc && ternServer.projectDir && fileName.indexOf(ternServer.projectDir) === 0) {
fileName = fileName.slice(ternServer.projectDir.length);
}
return fileName;
Expand Down Expand Up @@ -659,6 +660,7 @@ var config = {};
} else if (type === MessageIds.TERN_ADD_FILES_MSG) {
handleAddFiles(request.files);
} else if (type === MessageIds.TERN_PRIME_PUMP_MSG) {
isUntitledDoc = request.isUntitledDoc;
handlePrimePump(request.path);
} else if (type === MessageIds.TERN_GET_GUESSES_MSG) {
offset = request.offset;
Expand Down