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

Commit 189f6d3

Browse files
authored
Merge pull request #13202 from adobe/saurabh95/TernWorkerRelease
Added a check of Untitled doc in _getNormalizedFilename and _getDenormalizedFilename
2 parents 4f0bab5 + 47a2a67 commit 189f6d3

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/extensions/default/JavaScriptCodeHints/ScopeManager.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,11 @@ define(function (require, exports, module) {
927927
* @param {string} path - full path of file
928928
* @return {jQuery.Promise} - the promise for the request
929929
*/
930-
function primePump(path) {
930+
function primePump(path, isUntitledDoc) {
931931
_postMessageByPass({
932-
type : MessageIds.TERN_PRIME_PUMP_MSG,
933-
path : path
932+
type : MessageIds.TERN_PRIME_PUMP_MSG,
933+
path : path,
934+
isUntitledDoc : isUntitledDoc
934935
});
935936

936937
return addPendingRequest(path, OFFSET_ZERO, MessageIds.TERN_PRIME_PUMP_MSG);
@@ -1152,7 +1153,7 @@ define(function (require, exports, module) {
11521153
if (isDocumentDirty && previousDocument) {
11531154
var updateFilePromise = updateTernFile(previousDocument);
11541155
updateFilePromise.done(function () {
1155-
primePump(path);
1156+
primePump(path, document.isUntitled());
11561157
addFilesDeferred.resolveWith(null, [_ternWorker]);
11571158
});
11581159
} else {
@@ -1171,7 +1172,7 @@ define(function (require, exports, module) {
11711172
deferredPreferences.done(function () {
11721173
if (file instanceof InMemoryFile) {
11731174
initTernServer(pr, []);
1174-
var hintsPromise = primePump(path);
1175+
var hintsPromise = primePump(path, true);
11751176
hintsPromise.done(function () {
11761177
addFilesDeferred.resolveWith(null, [_ternWorker]);
11771178
});
@@ -1202,7 +1203,7 @@ define(function (require, exports, module) {
12021203

12031204
initTernServer(dir, files);
12041205

1205-
var hintsPromise = primePump(path);
1206+
var hintsPromise = primePump(path, false);
12061207
hintsPromise.done(function () {
12071208
if (!usingModules()) {
12081209
// Read the subdirectories of the new file's directory.
@@ -1217,7 +1218,7 @@ define(function (require, exports, module) {
12171218
addAllFilesAndSubdirectories(projectRoot, function () {
12181219
// prime the pump again but this time don't wait
12191220
// for completion.
1220-
primePump(path);
1221+
primePump(path, false);
12211222

12221223
addFilesDeferred.resolveWith(null, [_ternWorker]);
12231224
});

src/extensions/default/JavaScriptCodeHints/tern-worker.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ var config = {};
4141
Infer = infer;
4242

4343
var ternServer = null,
44-
inferenceTimeout;
44+
inferenceTimeout,
45+
isUntitledDoc = false;
4546

4647
// Save the tern callbacks for when we get the contents of the file
4748
var fileCallBacks = {};
@@ -107,14 +108,14 @@ var config = {};
107108
}
108109

109110
function _getNormalizedFilename(fileName) {
110-
if (ternServer.projectDir && fileName.indexOf(ternServer.projectDir) === -1) {
111+
if (!isUntitledDoc && ternServer.projectDir && fileName.indexOf(ternServer.projectDir) === -1) {
111112
fileName = ternServer.projectDir + fileName;
112113
}
113114
return fileName;
114115
}
115116

116117
function _getDenormalizedFilename(fileName) {
117-
if (ternServer.projectDir && fileName.indexOf(ternServer.projectDir) === 0) {
118+
if (!isUntitledDoc && ternServer.projectDir && fileName.indexOf(ternServer.projectDir) === 0) {
118119
fileName = fileName.slice(ternServer.projectDir.length);
119120
}
120121
return fileName;
@@ -659,6 +660,7 @@ var config = {};
659660
} else if (type === MessageIds.TERN_ADD_FILES_MSG) {
660661
handleAddFiles(request.files);
661662
} else if (type === MessageIds.TERN_PRIME_PUMP_MSG) {
663+
isUntitledDoc = request.isUntitledDoc;
662664
handlePrimePump(request.path);
663665
} else if (type === MessageIds.TERN_GET_GUESSES_MSG) {
664666
offset = request.offset;

0 commit comments

Comments
 (0)