@@ -13,17 +13,22 @@ async function setIdeSettings (ideInstance: DetectedIDE, remote?: boolean) {
1313 const configFilePath = resolve ( ideInstance . settingsDir , ideInstance . settingsFile )
1414 const settingsPath = getSettingsPath ( ideInstance . ide )
1515 const serverConfig = getServerConfig ( undefined , remote )
16+
17+ let config = { }
1618 if ( existsSync ( configFilePath ) ) {
17- const fileContent = await readFile ( configFilePath , { encoding : 'utf8' } )
18- const existingConfig = parse ( fileContent )
19- deepset ( existingConfig , settingsPath , serverConfig )
20- await writeFile ( configFilePath , prettyPrint ( existingConfig ) )
21- return
22- } else {
23- const config = { }
24- deepset ( config , settingsPath , serverConfig )
25- await writeFile ( configFilePath , prettyPrint ( config ) )
19+ try {
20+ const fileContent = await readFile ( configFilePath , { encoding : 'utf8' } )
21+ const parsed = parse ( fileContent )
22+ if ( parsed && typeof parsed === 'object' ) {
23+ config = parsed
24+ }
25+ } catch {
26+ console . error ( 'Failed to parse existing config, creating new one' )
27+ }
2628 }
29+
30+ deepset ( config , settingsPath , serverConfig )
31+ await writeFile ( configFilePath , prettyPrint ( config ) )
2732}
2833
2934export async function installGlobally ( ides : DetectedIDE [ ] , remote ?: boolean ) {
0 commit comments