@@ -40,6 +40,48 @@ describe('writeEditorConfigs', () => {
4040 expect ( settings [ 'editor.formatOnSave' ] ) . toBe ( true ) ;
4141 } ) ;
4242
43+ it ( 'merges existing vscode JSONC settings (comments, trailing commas)' , async ( ) => {
44+ const projectRoot = createTempDir ( ) ;
45+
46+ const vscodeDir = path . join ( projectRoot , '.vscode' ) ;
47+ fs . mkdirSync ( vscodeDir , { recursive : true } ) ;
48+ fs . writeFileSync (
49+ path . join ( vscodeDir , 'settings.json' ) ,
50+ `{
51+ // JSONC comment
52+ "editor.formatOnSave": false,
53+ "editor.codeActionsOnSave": {
54+ // preserve existing key
55+ "source.organizeImports": "explicit",
56+ },
57+ }
58+ ` ,
59+ 'utf8' ,
60+ ) ;
61+
62+ await writeEditorConfigs ( {
63+ projectRoot,
64+ editorId : 'vscode' ,
65+ interactive : false ,
66+ silent : true ,
67+ } ) ;
68+
69+ const settings = JSON . parse (
70+ fs . readFileSync ( path . join ( projectRoot , '.vscode' , 'settings.json' ) , 'utf8' ) ,
71+ ) as Record < string , unknown > ;
72+
73+ // Existing key is preserved (merge never overwrites)
74+ expect ( settings [ 'editor.formatOnSave' ] ) . toBe ( false ) ;
75+
76+ // New keys are added
77+ expect ( settings [ 'editor.defaultFormatter' ] ) . toBe ( 'oxc.oxc-vscode' ) ;
78+ expect ( settings [ 'oxc.fmt.configPath' ] ) . toBe ( './vite.config.ts' ) ;
79+
80+ const codeActions = settings [ 'editor.codeActionsOnSave' ] as Record < string , unknown > ;
81+ expect ( codeActions [ 'source.organizeImports' ] ) . toBe ( 'explicit' ) ;
82+ expect ( codeActions [ 'source.fixAll.oxc' ] ) . toBe ( 'explicit' ) ;
83+ } ) ;
84+
4385 it ( 'writes zed settings that align formatter config with vite.config.ts' , async ( ) => {
4486 const projectRoot = createTempDir ( ) ;
4587
0 commit comments