16
16
import org .eclipse .core .runtime .Platform ;
17
17
import org .eclipse .core .runtime .preferences .AbstractPreferenceInitializer ;
18
18
import org .eclipse .core .runtime .preferences .IEclipsePreferences ;
19
+ import org .osgi .service .prefs .BackingStoreException ;
19
20
20
21
import ts .cmd .tslint .TslintSettingsStrategy ;
21
22
import ts .eclipse .ide .core .TypeScriptCorePlugin ;
@@ -56,14 +57,18 @@ public void initializeDefaultPreferences() {
56
57
for (int i = 0 ; i < oldRepostoryBaseDirs .length ; i ++) {
57
58
oldRepostoryBaseDir = oldRepostoryBaseDirs [i ];
58
59
if (oldRepostoryBaseDir .isDirectory ()) {
59
- TypeScriptCorePlugin .getTypeScriptRepositoryManager ().createRepository (oldRepostoryBaseDir );
60
+ try {
61
+ TypeScriptCorePlugin .getTypeScriptRepositoryManager ().createRepository (oldRepostoryBaseDir );
62
+ } catch (Exception e ) {
63
+ Trace .trace (Trace .SEVERE , "Error while getting an archived TypeScript repository" , e );
64
+ }
60
65
}
61
66
}
62
67
63
68
}
64
69
65
70
// Initialize tsc preferences
66
- initializeTscPreferences (node , defaultRepository );
71
+ initializeTypeScriptRuntimePreferences (node , defaultRepository );
67
72
// Initialize tsserver preferences
68
73
initializeTsserverPreferences (node , defaultRepository );
69
74
// Initialize tslint preferences
@@ -82,6 +87,11 @@ public void initializeDefaultPreferences() {
82
87
83
88
// initialize editor+formation options
84
89
initializeEditorFormatOptions (node );
90
+
91
+ // Fix embedded TypeScript id preference
92
+ // See https://github.com/angelozerr/typescript.java/issues/121
93
+ fixEmbeddedTypeScriptIdPreference (
94
+ WorkspaceTypeScriptSettingsHelper .getWorkspacePreferences (TypeScriptCorePlugin .PLUGIN_ID ));
85
95
}
86
96
87
97
/**
@@ -112,7 +122,8 @@ private static boolean useBundledNodeJsEmbedded(IEclipsePreferences node) {
112
122
return false ;
113
123
}
114
124
115
- private void initializeTscPreferences (IEclipsePreferences node , ITypeScriptRepository defaultRepository ) {
125
+ private void initializeTypeScriptRuntimePreferences (IEclipsePreferences node ,
126
+ ITypeScriptRepository defaultRepository ) {
116
127
node .put (TypeScriptCorePreferenceConstants .EMBEDDED_TYPESCRIPT_ID , defaultRepository .getName ());
117
128
node .putBoolean (TypeScriptCorePreferenceConstants .USE_EMBEDDED_TYPESCRIPT , true );
118
129
node .put (TypeScriptCorePreferenceConstants .INSTALLED_TYPESCRIPT_PATH , "" );
@@ -171,4 +182,25 @@ private void initializeEditorFormatOptions(IEclipsePreferences node) {
171
182
TypeScriptCorePreferenceConstants .FORMAT_OPTIONS_PLACE_OPEN_BRACE_ON_NEW_LINE_FOR_CONTROL_BLOCKS_DEFAULT );
172
183
173
184
}
185
+
186
+ /**
187
+ * Fix the embeddedTypeScriptId preference if needed with default
188
+ * embeddedTypeScriptId.
189
+ *
190
+ * @param preferences
191
+ * @see https://github.com/angelozerr/typescript.java/issues/121
192
+ */
193
+ public static void fixEmbeddedTypeScriptIdPreference (IEclipsePreferences preferences ) {
194
+ String embeddedTypeScriptId = preferences .get (TypeScriptCorePreferenceConstants .EMBEDDED_TYPESCRIPT_ID , null );
195
+ if (embeddedTypeScriptId != null
196
+ && TypeScriptCorePlugin .getTypeScriptRepositoryManager ().getRepository (embeddedTypeScriptId ) == null ) {
197
+ preferences .put (TypeScriptCorePreferenceConstants .EMBEDDED_TYPESCRIPT_ID ,
198
+ TypeScriptCorePlugin .getTypeScriptRepositoryManager ().getDefaultRepository ().getName ());
199
+ try {
200
+ preferences .flush ();
201
+ } catch (BackingStoreException e ) {
202
+ Trace .trace (Trace .SEVERE , "Error while fixing embeddedTypeScriptId preference" , e );
203
+ }
204
+ }
205
+ }
174
206
}
0 commit comments