zardoy / vscode-fix-all-json

Utils & commands for fixing problems in JSON
https://marketplace.visualstudio.com/items?itemName=zardoy.fix-all-json
MIT License
5 stars 2 forks source link

Automatically insert a comma on `Enter` #5

Closed AgentRBY closed 1 year ago

AgentRBY commented 1 year ago

In WebStorm, if you press Enter after curly brackets in JSON, a comma will automatically appear. It would be cool to implement this in VS Code Example: webstorm64_MWRD9ppn9c

P.S.: Not sure if JSON is specific to this plugin, but either way it would be useful

zardoy commented 1 year ago

For now, I personally use shift+enter keybind, which powered by Commands and Comma Enter extensions as its useful for absolutely all languages (e.g. objects in TypeScript). In JSON we can easily implement the same behavior as in WS by overriding Enter and Ctrl+Enter.

P.S.: Not sure if JSON is specific to this plugin

This extension was originally created to fix errors (diagnostics) in JSON files, but I'm going to add a lot of commands / on-type JSON-specific fixes (such as autoEscapeQuoteJson) so I think its perfect place for this request.

AgentRBY commented 1 year ago

Not a bad solution, but there are problems. Comma Enter generally works everywhere, but in WebStorm the comma only works if the character next to ' or " or } or ] webstorm64_gN2eZ2DsZL

In VS Code I now have this: Code_-_Insiders_31C5qMj90f

AgentRBY commented 1 year ago

I just tested this on a release extension and it doesn't work for me on two devices. Everything is ok in development mode @zardoy does this feature work for you?

zardoy commented 1 year ago

Yes,

zardoy commented 1 year ago

The problem is obvious: it just doesn't work with CRLF, however tests a bit harder to fix than I expected, will do within a few hours.

AgentRBY commented 1 year ago

The problem is obvious: it just doesn't work with CRLF

Oh, okay, I'll fix it after work.

zardoy commented 1 year ago

Oh, okay, I'll fix it after work.

Sorry, didn't see that, the fix was extremely simple, it was initially my failure as I didn't setup tests correctly (file in integration tests was always using LF, dispite of files.eol is set to auto)