1919 *
2020 */
2121
22- /* global path*/
22+ /* global path, fs */
2323
2424/**
2525 * Provides JSLint results via the core linting extension point
@@ -40,6 +40,11 @@ define(function (require, exports, module) {
4040 FileSystem = brackets . getModule ( "filesystem/FileSystem" ) ,
4141 IndexingWorker = brackets . getModule ( "worker/IndexingWorker" ) ;
4242
43+ if ( Phoenix . isTestWindow ) {
44+ IndexingWorker . on ( "html_lint_extension_Loaded" , ( ) => {
45+ window . _htmlLintExtensionReadyToIntegTest = true ;
46+ } ) ;
47+ }
4348 IndexingWorker . loadScriptInWorker ( `${ module . uri } /../worker/html-worker.js` ) ;
4449
4550 const prefs = PreferencesManager . getExtensionPrefs ( "HTMLLint" ) ;
@@ -117,26 +122,26 @@ define(function (require, exports, module) {
117122 return new Promise ( ( resolve , reject ) => {
118123 const configFilePath = path . join ( dir , CONFIG_FILE_NAME ) ;
119124 let displayPath = ProjectManager . getProjectRelativeOrDisplayPath ( configFilePath ) ;
120- DocumentManager . getDocumentForPath ( configFilePath ) . done ( function ( configDoc ) {
121- let config ;
122- const content = configDoc . getText ( ) ;
123- try {
124- config = JSON . parse ( content ) ;
125- console . log ( "html-lint: loaded config file for project " + configFilePath ) ;
126- } catch ( e ) {
127- console . log ( "html-lint: error parsing " + configFilePath , content , e ) ;
128- // just log and return as this is an expected failure for us while the user edits code
129- reject ( StringUtils . format ( Strings . HTML_LINT_CONFIG_JSON_ERROR , displayPath ) ) ;
130- return ;
131- }
132- resolve ( config ) ;
133- } ) . fail ( ( err ) => {
134- if ( err === FileSystemError . NOT_FOUND ) {
125+ // directly reading from fs as we are still getting deleted file from document manager read.
126+ fs . readFile ( configFilePath , 'utf8' , function ( err , content ) {
127+ if ( err && fs . ERR_CODES . ENOENT === err . code ) {
135128 resolve ( null ) ; // no config file is a valid case. we just resolve with null
136- return ;
129+ } else if ( err ) {
130+ console . error ( "Error reading JSHint Config File" , configFilePath , err ) ;
131+ reject ( "Error reading JSHint Config File" , displayPath ) ;
132+ } else {
133+ let config ;
134+ try {
135+ config = JSON . parse ( content ) ;
136+ console . log ( "html-lint: loaded config file for project " + configFilePath ) ;
137+ } catch ( e ) {
138+ console . log ( "html-lint: error parsing " + configFilePath , content , e ) ;
139+ // just log and return as this is an expected failure for us while the user edits code
140+ reject ( StringUtils . format ( Strings . HTML_LINT_CONFIG_JSON_ERROR , displayPath ) ) ;
141+ return ;
142+ }
143+ resolve ( config ) ;
137144 }
138- console . error ( "Error reading JSHint Config File" , configFilePath , err ) ;
139- reject ( "Error reading JSHint Config File" , displayPath ) ;
140145 } ) ;
141146 } ) ;
142147 }
@@ -191,29 +196,34 @@ define(function (require, exports, module) {
191196 } ) ;
192197 }
193198
194- function _isFileInArray ( pathToMatch , filePathArray ) {
195- if ( ! filePathArray ) {
196- return false ;
197- }
198- for ( let filePath of filePathArray ) {
199- if ( filePath === pathToMatch ) {
200- return true ;
201- }
199+ let projectConfigPaths ;
200+ function _getConfigPaths ( ) {
201+ if ( ! projectConfigPaths ) {
202+ projectConfigPaths = [
203+ path . join ( ProjectManager . getProjectRoot ( ) . fullPath , CONFIG_FILE_NAME ) ,
204+ ... UNSUPPORTED_CONFIG_FILES . map ( fileName =>
205+ path . join ( ProjectManager . getProjectRoot ( ) . fullPath , fileName ) )
206+ ] ;
202207 }
203- return false ;
208+ return projectConfigPaths ;
204209 }
205210
206- function _projectFileChanged ( _evt , changedPath , added , removed ) {
207- let configFilePath = path . join ( ProjectManager . getProjectRoot ( ) . fullPath , CONFIG_FILE_NAME ) ;
208- if ( changedPath === configFilePath
209- || _isFileInArray ( configFilePath , added ) || _isFileInArray ( configFilePath , removed ) ) {
210- _reloadOptions ( ) ;
211+ function _projectFileChanged ( _evt , changedPath , addedSet , removedSet ) {
212+ const configPaths = _getConfigPaths ( ) ;
213+ for ( let configPath of configPaths ) {
214+ if ( changedPath === configPath || addedSet . has ( configPath ) || removedSet . has ( configPath ) ) {
215+ _reloadOptions ( ) ;
216+ return ;
217+ }
211218 }
212219 }
213220
214221 AppInit . appReady ( function ( ) {
215- ProjectManager . on ( ProjectManager . EVENT_PROJECT_PATH_CHANGED_OR_RENAMED , _projectFileChanged ) ;
216- ProjectManager . on ( ProjectManager . EVENT_PROJECT_OPEN , _reloadOptions ) ;
222+ ProjectManager . on ( ProjectManager . EVENT_PROJECT_CHANGED_OR_RENAMED_PATH , _projectFileChanged ) ;
223+ ProjectManager . on ( ProjectManager . EVENT_PROJECT_OPEN , ( ) => {
224+ projectConfigPaths = null ;
225+ _reloadOptions ( ) ;
226+ } ) ;
217227 _reloadOptions ( ) ;
218228 } ) ;
219229
0 commit comments