Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannon format JSON with comments on save (mode = modifications) #2330

Closed
memeplex opened this issue Dec 18, 2021 · 3 comments · Fixed by #2447
Closed

Cannon format JSON with comments on save (mode = modifications) #2330

memeplex opened this issue Dec 18, 2021 · 3 comments · Fixed by #2447
Labels
locked Please open a new issue and fill out the template instead of commenting.

Comments

@memeplex
Copy link

memeplex commented Dec 18, 2021

Summary

I can prettify a json with comments file (say .vscode/tasks.json) both from the CLI and using Format Document inside vscode. But when I save the document, the auto-formatter fails with:

Extension 'Prettier - Code formatter' is configured as formatter but it cannot format 'JSON with Comments'-files

Perhaps this has to do with my "editor.formatOnSaveMode": "modifications" setting, but I don't see a clear relationships between this mode and comment support, so I'm reporting it just in case.

Steps To Reproduce:

  1. Execute the following commands in your terminal in order to create and open a test project:
mkdir /tmp/proj
cd /tmp/proj
git init
mkdir .vscode
touch .vscode/settings.json
code .
  1. Copy the following in .vscode/settings.json and save it.
{
  "editor.formatOnSave": true,
  "editor.formatOnSaveMode": "modifications",
  "editor.defaultFormatter": "esbenp.prettier-vscode"
}
  1. Do some modification to settings.json and save it.

Expected result

Changes are formatted.

Actual result

Changes aren't formatted. This message is shown in the statusbar:

Extension 'Prettier - Code formatter' is configured as formatter but it cannot format 'JSON with Comments'-files

Additional information

VS Code Version: 1.61.2

Prettier Extension Version: 9.0.0

OS and version: macOS Big Sur

Prettier Log Output

["INFO" - 4:35:41 PM] Extension Name: esbenp.prettier-vscode.
["INFO" - 4:35:41 PM] Extension Version: 9.0.0.
["INFO" - 4:35:47 PM] Formatting file:///private/tmp/proj/.vscode/settings.json
["INFO" - 4:35:47 PM] Using ignore file (if present) at /private/tmp/proj/.prettierignore
["INFO" - 4:35:47 PM] File Info:
{
  "ignored": false,
  "inferredParser": "json"
}
["INFO" - 4:35:47 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 4:35:47 PM] Prettier Options:
{
  "arrowParens": "always",
  "bracketSpacing": true,
  "endOfLine": "lf",
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": false,
  "printWidth": 80,
  "proseWrap": "preserve",
  "quoteProps": "as-needed",
  "requirePragma": false,
  "semi": true,
  "singleQuote": false,
  "tabWidth": 2,
  "trailingComma": "es5",
  "useTabs": false,
  "vueIndentScriptAndStyle": false,
  "filepath": "/private/tmp/proj/.vscode/settings.json",
  "parser": "json"
}
["INFO" - 4:35:47 PM] Formatting completed in 0.04ms.
@chipbuster
Copy link

I have a similar issue. I suspect that this is tied to saving modifications: if I use the command palette (Ctrl+Shift+P) and select "Format Document", everything seems to work properly. However, if I select "Format Modified Lines" or "Format Selection" instead, I get a popup message with the same text (except that it says it can't format 'Markdown' files).

image

I also wonder if this is related to #2331: it's a similar looking issue, but there's not enough information in that post to be able to confirm.

Additional Logs + Details

Output from Prettier Logs

["INFO" - 1:34:52 PM] Formatting file:///home/chipbuster/codes/shellprompt/criterion-compare/README.md
["INFO" - 1:34:52 PM] Using config file at '/home/chipbuster/codes/shellprompt/criterion-compare/.prettierrc.json'
["INFO" - 1:34:52 PM] Using ignore file (if present) at /home/chipbuster/codes/shellprompt/criterion-compare/.prettierignore
["INFO" - 1:34:52 PM] File Info:
{
  "ignored": false,
  "inferredParser": "markdown"
}
["INFO" - 1:34:52 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 1:34:52 PM] Prettier Options:
{
  "filepath": "/home/chipbuster/codes/shellprompt/criterion-compare/README.md",
  "parser": "markdown",
  "printWidth": 80,
  "tabWidth": 2,
  "useTabs": false,
  "semi": false,
  "singleQuote": true,
  "trailingComma": "none",
  "bracketSpacing": true,
  "arrowParens": "avoid"
}
["INFO" - 1:34:52 PM] Formatting completed in 0.03ms.

VSCode + Platform Infomation

Version: 1.63.2
Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3
Date: 2021-12-15T09:39:46.686Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.15.8-zen1-1-zen

VSCode Settings File (JSON)

VSCode Config JSON

{
  "editor.bracketPairColorization.enabled": true,
  "editor.cursorStyle": "line",
  "editor.cursorSurroundingLines": 5,
  "editor.fontFamily": "'Fira Code Retina','Fira Code','Source Code Pro', 'monospace', monospace",
  "editor.fontLigatures": true,
  "editor.fontSize": 12,
  "editor.formatOnSave": true,
  "editor.formatOnSaveMode": "modificationsIfAvailable",
  "editor.minimap.enabled": true,
  "editor.minimap.maxColumn": 60,
  "editor.multiCursorModifier": "alt",
  "editor.renderWhitespace": "boundary",
  "editor.rulers": [
    80,
    92,
    120
  ],
  "editor.suggestSelection": "first",
  "security.workspace.trust.untrustedFiles": "open",
  "terminal.external.osxExec": "iTerm2.app",
  "terminal.integrated.allowChords": false,
  "terminal.integrated.commandsToSkipShell": [
    "language-julia.interrupt"
  ],
  "terminal.integrated.cursorBlinking": true,
  "terminal.integrated.fontFamily": "'Source Code Pro', 'Source Code Variable', monospace",
  "terminal.integrated.fontSize": 12,
  "terminal.integrated.scrollback": 100000,
  "window.titleBarStyle": "custom",
  "workbench.colorTheme": "Dracula",
  "workbench.editor.decorations.colors": true,
  "workbench.editorAssociations": {
    "*.ipynb": "jupyter-notebook"
  },
  "workbench.iconTheme": "material-icon-theme",
  "workbench.startupEditor": "welcomePage",
  ////////////////////////////////////////////////
  "vim.handleKeys": {
    "<C-d>": true,
    "<C-k>": false
  },
  "vim.normalModeKeyBindingsNonRecursive": [
    {
      "before": [
        "<space>"
      ],
      "commands": [
        "workbench.action.files.save"
      ]
    }
  ],
  /////////////////////////////////////////////////
  "C_Cpp.clang_format_path": "/usr/bin/clang-format",
  "[c]": {
    "editor.defaultFormatter": "xaver.clang-format"
  },
  "[cpp]": {
    "editor.defaultFormatter": "ms-vscode.cpptools"
  },
  "[fsharp]": {
    "editor.defaultFormatter": "Ionide.Ionide-fsharp"
  },
  "[julia]": {
    "editor.defaultFormatter": "singularitti.vscode-julia-formatter"
  },
  "[markdown]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[python]": {
    "editor.formatOnPaste": false,
    "editor.formatOnSaveMode": "file"
  },
  "cSpell.enabled": false,
  "cSpell.language": "en",
  "cSpell.userWords": [
    "malloc"
  ],
  "cmake.configureOnOpen": true,
  "cmake.sourceDirectory": "${workspaceFolder}/src",
  "debug.console.fontSize": 12,
  "explorer.confirmDelete": false,
  "git.autofetch": true,
  "githubPullRequests.remotes": [
    "upstream"
  ],
  "gitlens.currentLine.enabled": false,
  "gitlens.hovers.currentLine.over": "line",
  "gitlens.statusBar.enabled": false,
  "julia.NumThreads": 32,
  "julia.enableCrashReporter": true,
  "julia.enableTelemetry": true,
  "julia.symbolCacheDownload": true,
  "jupyter.askForKernelRestart": false,
  "jupyter.sendSelectionToInteractiveWindow": true,
  "latex-workshop.view.pdf.viewer": "tab",
  "markdown-preview-enhanced.breakOnSingleNewLine": false,
  "markdown-preview-enhanced.chromePath": "/usr/bin/chromium",
  "markdown-preview-enhanced.codeBlockTheme": "vs.css",
  "markdown-preview-enhanced.previewTheme": "vue.css",
  "markdown.preview.fontSize": 12,
  "notebook.cellToolbarLocation": {
    "default": "right",
    "jupyter-notebook": "left"
  },
  "notebook.lineNumbers": "on",
  "python.defaultInterpreterPath": "/bin/python",
  "python.formatting.provider": "black",
  "todo-tree.general.tags": [
    "BUG",
    "HACK",
    "FIXME",
    "TODO",
    "XXX",
    "[ ]",
    "[x]"
  ],
  "todo-tree.regex.regex": "(//|#|<!--|;|/\\*|^|^\\s*(-|\\d+.))\\s*($TAGS)",
  "peacock.favoriteColors": [
    {
      "name": "Angular Red",
      "value": "#b52e31"
    },
    {
      "name": "Auth0 Orange",
      "value": "#eb5424"
    },
    {
      "name": "Azure Blue",
      "value": "#007fff"
    },
    {
      "name": "C# Purple",
      "value": "#68217A"
    },
    {
      "name": "Gatsby Purple",
      "value": "#639"
    },
    {
      "name": "Go Cyan",
      "value": "#5dc9e2"
    },
    {
      "name": "Java Blue-Gray",
      "value": "#557c9b"
    },
    {
      "name": "JavaScript Yellow",
      "value": "#f9e64f"
    },
    {
      "name": "Mandalorian Blue",
      "value": "#1857a4"
    },
    {
      "name": "Node Green",
      "value": "#215732"
    },
    {
      "name": "React Blue",
      "value": "#00b3e6"
    },
    {
      "name": "Something Different",
      "value": "#832561"
    },
    {
      "name": "Vue Green",
      "value": "#42b883"
    },
    {
      "name": "Burnt Orange",
      "value": "cc5500"
    },
    {
      "name": "Starship Magenta",
      "value": "f01e86"
    }
  ],
  "[jsonc]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "julia.usePlotPane": false,
  "window.zoomLevel": 1
}

@ntotten
Copy link
Member

ntotten commented Jan 1, 2022

Prettier VSCode doesn't support the setting "editor.formatOnSaveMode": "modifications". Prettier doesnt do well with formatting partial documents.

@github-actions
Copy link

github-actions bot commented Apr 2, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot added the locked Please open a new issue and fill out the template instead of commenting. label Apr 2, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants