Paul Waldo
Paul Waldo

Reputation: 1233

VS Code format splitting comma-separated items in JSON file

VS Code wants to split comma separated arguments into separate lines. I would prefer it not do this. It only happens on one machine and I can't discover the setting that makes this happen.

As an example, consider this text in settings.json

"args": [
    "-q", "query",
    "-a", "answer"
]

I have format-on-save turned on, and every time I save the file, I get this

"args": [
    "-q",
    "query",
    "-a",
    "answer"
]

I would prefer that it leave these alone, like on all of my other machines. Please note that I do not want to turn off auto-format, I just want this wrapping behavior to stop.

[New Info] I copied the User settings ~/Library/Application Support/Code/User/settings.json from the machine that did not have the wrapping issues to the machine that did have the issues. I'm not sure which setting it was, but that fixed the problem. I'd still love to know which setting caused this behavior. Both files are below.

Wrapping Issues Settings

{
    "telemetry.enableTelemetry": false,
    "editor.minimap.enabled": false,
    "files.autoSave": "afterDelay",
    "workbench.sideBar.location": "left",
    //"editor.wordWrap": "bounded",
    "editor.wordWrapColumn": 132,
    "editor.wrappingIndent": "deepIndent",
    "go.formatTool": "goimports",
    "go.liveErrors": {
        "enabled": true,
        "delay": 500
    },
    "go.vetOnSave": "workspace",
    "go.gocodeAutoBuild": true,
    "git.enableCommitSigning": true,
    "go.autocompleteUnimportedPackages": true,
    "git.autofetch": true,
    "git.confirmSync": false,
    "editor.formatOnPaste": true,
    "editor.formatOnType": true,
    "editor.formatOnSave": true,
    "python.testing.unittestEnabled": true,
    "python.venvPath": "~/develop/virtualenv",
    "python.linting.pep8Enabled": true,
    "editor.detectIndentation": false,
    "search.quickOpen.includeSymbols": true,
    "workbench.colorTheme": "Default Light+",
}

No Wrapping Issues Settings

{
    "telemetry.enableTelemetry": false,
    "window.zoomLevel": 0,
    "files.autoSave": "afterDelay",
    "editor.fontSize": 14,
    "editor.minimap.enabled": false,
    "files.exclude": {
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    },
    "editor.wordWrap": "on",
    "editor.wrappingIndent": "deepIndent",
    "editor.wordWrapColumn": 132,
    "go.autocompleteUnimportedPackages": true,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "go.gocodeAutoBuild": true,
    "debug.enableAllHovers": true,
    "debug.inlineValues": true,
    "git.enableCommitSigning": true,
    "python.jediEnabled": false,
    "[python]": {

    },
    "python.testing.unittestEnabled": true,
    "git.autofetch": true,
    "python.venvPath": "~/develop/virtualenv",
    "python.linting.pep8Enabled": true,
    "editor.detectIndentation": false,
    "editor.formatOnPaste": true,
    "window.openFilesInNewWindow": "on",
}

Combined settings with duplicates removed

paul-> cat settings.json.old.json settings.json |sort|uniq

        "**/.classpath": true,
        "**/.factorypath": true
        "**/.project": true,
        "**/.settings": true,
        "delay": 500
        "enabled": true,
    "[python]": {
    "debug.enableAllHovers": true,
    "debug.inlineValues": true,
    "editor.detectIndentation": false,
    "editor.fontSize": 14,
    "editor.formatOnPaste": true,
    "editor.formatOnSave": true,
    "editor.formatOnType": true,
    "editor.minimap.enabled": false,
    "editor.suggestSelection": "first",
    "editor.wordWrap": "on",
    "editor.wordWrapColumn": 132,
    "editor.wrappingIndent": "deepIndent",
    "files.autoSave": "afterDelay",
    "files.exclude": {
    "git.autofetch": true,
    "git.confirmSync": false,
    "git.enableCommitSigning": true,
    "go.autocompleteUnimportedPackages": true,
    "go.formatTool": "goimports",
    "go.gocodeAutoBuild": true,
    "go.liveErrors": {
    "go.vetOnSave": "workspace",
    "python.jediEnabled": false,
    "python.linting.pep8Enabled": true,
    "python.testing.unittestEnabled": true,
    "python.venvPath": "~/develop/virtualenv",
    "search.quickOpen.includeSymbols": true,
    "telemetry.enableTelemetry": false,
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "window.openFilesInNewWindow": "on",
    "window.zoomLevel": 0,
    "workbench.colorTheme": "Default Light+",
    "workbench.sideBar.location": "left",
    //"editor.wordWrap": "bounded",
    },
{
}
}{

Upvotes: 0

Views: 2870

Answers (1)

Mark
Mark

Reputation: 181060

See https://stackoverflow.com/a/73180702/836330 for a similar case.

Enable this setting: JSON > Format: Keep Lines

With that setting enabled - it is coming in v1.70

"args": [
    "-q", "query",
    "-a", "answer"
]

will stay exactly that way. Lines with multiple values or multiple key/value pairs will be "kept" as is.

Upvotes: 1

Related Questions