@@ -192,28 +192,73 @@ public IIDETypeScriptProjectSettings getProjectSettings() {
192
192
@ Override
193
193
public boolean canValidate (IResource resource ) {
194
194
try {
195
+ // Use project preferences, which defines exclude path
195
196
if (!getProjectSettings ().canValidate (resource )) {
196
197
return false ;
197
198
}
198
- IDETsconfigJson tsconfig = JsonConfigResourcesManager .getInstance ().findTsconfig (resource );
199
- if (tsconfig != null ) {
200
- // check if the given file is declared in the "files"
201
- if (tsconfig .hasFiles ()) {
202
- return tsconfig .isInFiles (resource );
203
- } else if (tsconfig .hasExclude ()) {
204
- return !tsconfig .isExcluded (resource );
205
- }
206
- } else {
207
- // tsconfig.json was not found (ex : MyProject/node_modules),
208
- // validation must not be done.
209
- return false ;
199
+ boolean isJSFile = IDEResourcesManager .getInstance ().isJsFile (resource )
200
+ || IDEResourcesManager .getInstance ().isJsxFile (resource );
201
+ if (isJSFile ) {
202
+ // Can validate js file?
203
+ return canValidateJsFile (resource );
210
204
}
205
+ // Can validate ts file?
206
+ return canValidateTsFile (resource );
211
207
} catch (CoreException e ) {
212
208
Trace .trace (Trace .SEVERE , "Error while getting tsconfig.json for canValidate" , e );
213
209
}
214
210
return true ;
215
211
}
216
212
213
+ /**
214
+ * Returns true if the given js, jsx file can be validated and false
215
+ * otherwise.
216
+ *
217
+ * @param resource
218
+ * @return true if the given js, jsx file can be validated and false
219
+ * otherwise.
220
+ * @throws CoreException
221
+ */
222
+ private boolean canValidateJsFile (IResource resource ) throws CoreException {
223
+ // Search if a jsconfig.json exists?
224
+ IFile jsconfigFile = JsonConfigResourcesManager .getInstance ().findJsconfigFile (resource );
225
+ if (jsconfigFile != null ) {
226
+ return true ;
227
+ }
228
+ // Search if tsconfig.json exists and defines alloyJs
229
+ IDETsconfigJson tsconfig = JsonConfigResourcesManager .getInstance ().findTsconfig (resource );
230
+ if (tsconfig != null && tsconfig .getCompilerOptions () != null && tsconfig .getCompilerOptions ().isAlloyJs ()) {
231
+ return true ;
232
+ }
233
+ // jsconfig.json was not found (ex : MyProject/node_modules),
234
+ // validation must not be done.
235
+ return false ;
236
+ }
237
+
238
+ /**
239
+ * Returns true if the given ts, tsx file can be validated and false
240
+ * otherwise.
241
+ *
242
+ * @param resource
243
+ * @return true if the given ts, tsx file can be validated and false
244
+ * otherwise.
245
+ * @throws CoreException
246
+ */
247
+ private boolean canValidateTsFile (IResource resource ) throws CoreException {
248
+ IDETsconfigJson tsconfig = JsonConfigResourcesManager .getInstance ().findTsconfig (resource );
249
+ if (tsconfig != null ) {
250
+ // check if the given file is declared in the "files"
251
+ if (tsconfig .hasFiles ()) {
252
+ return tsconfig .isInFiles (resource );
253
+ } else if (tsconfig .hasExclude ()) {
254
+ return !tsconfig .isExcluded (resource );
255
+ }
256
+ }
257
+ // tsconfig.json was not found (ex : MyProject/node_modules),
258
+ // validation must not be done.
259
+ return false ;
260
+ }
261
+
217
262
@ Override
218
263
public boolean canCompileOnSave (IResource resource ) {
219
264
try {
0 commit comments