Skip to content

Commit e24ba3d

Browse files
committed
fix: race conditions in JSHint config file reading
1 parent 5b3c92b commit e24ba3d

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/document/DocumentManager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,4 +744,8 @@ define(function (require, exports, module) {
744744
// Handle Language change events
745745
LanguageManager.on("languageAdded", _handleLanguageAdded);
746746
LanguageManager.on("languageModified", _handleLanguageModified);
747+
748+
if(location.origin === "http://localhost:8000"){
749+
window.DocumentManager = exports; // this is for quick editor queries during development in browser console
750+
}
747751
});

src/extensions/default/JSLint/JSHint.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,19 @@ define(function (require, exports, module) {
163163
let displayPath = ProjectManager.makeProjectRelativeIfPossible(configFilePath);
164164
displayPath = Phoenix.app.getDisplayPath(displayPath);
165165
DocumentManager.getDocumentForPath(configFilePath).done(function (configDoc) {
166+
if (!ProjectManager.isWithinProject(configFilePath)) {
167+
// this is a rare race condition where the user switches project between the get document call.
168+
// Eg. in integ tests.
169+
reject(`JSHint Project changed while scanning ${configFilePath}`);
170+
return;
171+
}
166172
let config;
167173
const content = configDoc.getText();
168174
try {
169175
config = JSON.parse(removeComments(content));
170176
console.log("JSHint: loaded config file for project " + configFilePath);
171177
} catch (e) {
172-
console.log("JSHint: error parsing " + configFilePath);
178+
console.log("JSHint: error parsing " + configFilePath, content, e);
173179
// just log and return as this is an expected failure for us while the user edits code
174180
reject("Error parsing JSHint config file: " + displayPath);
175181
return;
@@ -209,11 +215,20 @@ define(function (require, exports, module) {
209215

210216
function _reloadOptions() {
211217
projectSpecificOptions = null;
212-
_readConfig(ProjectManager.getProjectRoot().fullPath, CONFIG_FILE_NAME).then((config)=>{
218+
const scanningProjectPath = ProjectManager.getProjectRoot().fullPath;
219+
_readConfig(scanningProjectPath, CONFIG_FILE_NAME).then((config)=>{
220+
if(scanningProjectPath !== ProjectManager.getProjectRoot().fullPath){
221+
// this is a rare race condition where the user switches project between the get document call.
222+
// Eg. in integ tests. do nothing as another scan for the new project will be in progress.
223+
return;
224+
}
213225
projectSpecificOptions = config;
214226
CodeInspection.requestRun(Strings.JSHINT_NAME);
215227
jsHintConfigFileErrorMessage = null;
216228
}).catch((err)=>{
229+
if(scanningProjectPath !== ProjectManager.getProjectRoot().fullPath){
230+
return;
231+
}
217232
jsHintConfigFileErrorMessage = err;
218233
CodeInspection.requestRun(Strings.JSHINT_NAME);
219234
});

0 commit comments

Comments
 (0)