Skip to content

Commit 6848fb3

Browse files
committed
fix: add defaultStringType option to yaml.stringify calls
- Added defaultStringType: 'PLAIN' to minimize formatting changes - This helps preserve plain scalars when possible - Works alongside lineWidth: 0 to prevent automatic line wrapping
1 parent 4831ed0 commit 6848fb3

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/core/config/CustomModesManager.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ export class CustomModesManager {
213213
const fileExists = await fileExistsAtPath(filePath)
214214

215215
if (!fileExists) {
216-
await this.queueWrite(() => fs.writeFile(filePath, yaml.stringify({ customModes: [] }, { lineWidth: 0 })))
216+
await this.queueWrite(() =>
217+
fs.writeFile(
218+
filePath,
219+
yaml.stringify({ customModes: [] }, { lineWidth: 0, defaultStringType: "PLAIN" }),
220+
),
221+
)
217222
}
218223

219224
return filePath
@@ -418,7 +423,7 @@ export class CustomModesManager {
418423
content = await fs.readFile(filePath, "utf-8")
419424
} catch (error) {
420425
// File might not exist yet.
421-
content = yaml.stringify({ customModes: [] }, { lineWidth: 0 })
426+
content = yaml.stringify({ customModes: [] }, { lineWidth: 0, defaultStringType: "PLAIN" })
422427
}
423428

424429
let settings
@@ -431,7 +436,7 @@ export class CustomModesManager {
431436
}
432437

433438
settings.customModes = operation(settings.customModes || [])
434-
await fs.writeFile(filePath, yaml.stringify(settings, { lineWidth: 0 }), "utf-8")
439+
await fs.writeFile(filePath, yaml.stringify(settings, { lineWidth: 0, defaultStringType: "PLAIN" }), "utf-8")
435440
}
436441

437442
private async refreshMergedState(): Promise<void> {
@@ -490,7 +495,10 @@ export class CustomModesManager {
490495
public async resetCustomModes(): Promise<void> {
491496
try {
492497
const filePath = await this.getCustomModesFilePath()
493-
await fs.writeFile(filePath, yaml.stringify({ customModes: [] }, { lineWidth: 0 }))
498+
await fs.writeFile(
499+
filePath,
500+
yaml.stringify({ customModes: [] }, { lineWidth: 0, defaultStringType: "PLAIN" }),
501+
)
494502
await this.context.globalState.update("customModes", [])
495503
this.clearCache()
496504
await this.onUpdate()

src/services/marketplace/SimpleInstaller.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class SimpleInstaller {
8484

8585
// Write back to file
8686
await fs.mkdir(path.dirname(filePath), { recursive: true })
87-
const yamlContent = yaml.stringify(existingData, { lineWidth: 0 })
87+
const yamlContent = yaml.stringify(existingData, { lineWidth: 0, defaultStringType: "PLAIN" })
8888
await fs.writeFile(filePath, yamlContent, "utf-8")
8989

9090
// Calculate approximate line number where the new mode was added
@@ -282,7 +282,11 @@ export class SimpleInstaller {
282282
existingData.customModes = existingData.customModes.filter((mode: any) => mode.slug !== modeData.slug)
283283

284284
// Always write back the file, even if empty
285-
await fs.writeFile(filePath, yaml.stringify(existingData, { lineWidth: 0 }), "utf-8")
285+
await fs.writeFile(
286+
filePath,
287+
yaml.stringify(existingData, { lineWidth: 0, defaultStringType: "PLAIN" }),
288+
"utf-8",
289+
)
286290
}
287291
} catch (error: any) {
288292
if (error.code === "ENOENT") {

src/utils/migrateSettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async function migrateCustomModesToYaml(settingsDir: string, outputChannel: vsco
9393
const customModesData = yaml.parse(jsonContent)
9494

9595
// Convert to YAML with no line width limit to prevent line breaks
96-
const yamlContent = yaml.stringify(customModesData, { lineWidth: 0 })
96+
const yamlContent = yaml.stringify(customModesData, { lineWidth: 0, defaultStringType: "PLAIN" })
9797

9898
// Write YAML file
9999
await fs.writeFile(newYamlPath, yamlContent, "utf-8")

0 commit comments

Comments
 (0)