17
17
import org .eclipse .core .resources .IProject ;
18
18
import org .eclipse .core .runtime .CoreException ;
19
19
20
- import ts .eclipse .ide .core .resources . TypeScriptSettingsHelper ;
20
+ import ts .eclipse .ide .core .preferences . TypeScriptCorePreferenceConstants ;
21
21
import ts .eclipse .ide .core .resources .UseSalsa ;
22
+ import ts .eclipse .ide .core .resources .WorkspaceTypeScriptSettingsHelper ;
22
23
import ts .eclipse .ide .internal .core .Trace ;
23
- import ts .resources .ITypeScriptProject ;
24
24
import ts .resources .ITypeScriptResourcesManagerDelegate ;
25
25
import ts .utils .FileUtils ;
26
26
@@ -33,7 +33,7 @@ public static IDEResourcesManager getInstance() {
33
33
}
34
34
35
35
@ Override
36
- public ITypeScriptProject getTypeScriptProject (Object obj , boolean force ) throws IOException {
36
+ public IDETypeScriptProject getTypeScriptProject (Object obj , boolean force ) throws IOException {
37
37
if (obj instanceof IProject ) {
38
38
IProject project = (IProject ) obj ;
39
39
try {
@@ -72,21 +72,34 @@ private synchronized IDETypeScriptProject create(IProject project) throws CoreEx
72
72
return tsProject ;
73
73
}
74
74
75
- public boolean hasTypeScriptNature (IProject project ) {
76
- // see https://github.com/angelozerr/typescript.java/issues/12
77
- // FIXME: All projects can be a TypeScript project. It means that
78
- // project
79
- // properties display every time "TypeScript" menu item. But is it a
80
- // problem?
81
- // To hide the TypeScript menu item we could check that project contains
82
- // tsconfig.json or src/tsconfig.json
83
- // User could add a new path for tsconfig.json in the preferences but
84
- // I'm afrais that it's a little complex.
85
- return true ;
75
+ /**
76
+ * Returns true if the given project contains one or several "tsconfig.json"
77
+ * file(s) false otherwise.
78
+ *
79
+ * To have a very good performance, "tsconfig.json" is not searched by
80
+ * scanning the whole files of the project but it checks if "tsconfig.json"
81
+ * exists in several folders ('/tsconfig.json' or '/src/tsconfig.json).
82
+ * Those folders can be customized with preferences buildpath
83
+ * {@link TypeScriptCorePreferenceConstants#TYPESCRIPT_BUILD_PATH}.
84
+ *
85
+ * @param project
86
+ * Eclipse project.
87
+ * @return true if the given project contains one or several "tsconfig.json"
88
+ * file(s) false otherwise.
89
+ */
90
+ public boolean isTypeScriptProject (IProject project ) {
91
+ // check that TypeScript project have build path.
92
+ try {
93
+ IDETypeScriptProject tsProject = getTypeScriptProject (project , false );
94
+ return tsProject != null && tsProject .getTypeScriptBuildPath ().getContainers ().size () > 0 ;
95
+ } catch (Exception e ) {
96
+ Trace .trace (Trace .SEVERE , "Error while getting TypeScript project" , e );
97
+ }
98
+ return false ;
86
99
}
87
100
88
101
public boolean hasSalsaNature (IProject project ) {
89
- UseSalsa useSalsa = TypeScriptSettingsHelper .getUseSalsa ();
102
+ UseSalsa useSalsa = WorkspaceTypeScriptSettingsHelper .getUseSalsa ();
90
103
switch (useSalsa ) {
91
104
case Never :
92
105
return false ;
0 commit comments