vscode_deno icon indicating copy to clipboard operation
vscode_deno copied to clipboard

Unable to format vscode user profile level `settings.json` file

Open qupig opened this issue 1 year ago • 6 comments

Describe the bug

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

The denoland.vscode-deno extension is ONLY cannot format the user profile level settings.json file.

But it can format the workspace level settings.json file or the *.jsonc file within the workspace.

This is very strange but I think it might be solved in vscode extensions since Prettier - Code formatter extension works in all files mentioned above.

This is actually consistent with #840, but I think it defines the scope of the issue more clearly here, and the possibility of a fix.

I've also tested adding "editor.formatOnSaveMode": "file" but it has no effect.

Like said in the comment, if you drag that settings.json as a file into vscode to open it works, but not when opening the file directly from entrances within vscode.

NOTE that the Prettier extension works in both cases, so there must be a way around it.

Not supporting formatting of user profile level settings.json file is very inconvenient, for example I cannot set "denoland.vscode-deno" to user level "editor.defaultFormatter" because it does not work in the file itself. Instead I have to configure "denoland.vscode-deno" individually in each workspace.

I hope someone can investigate and resolve this humble little issue. And I'm perfectly willing to set this to my user level "editor.defaultFormatter" once this issue is resolved.

Versions

vscode: 1.95.2 deno: 2.0.6 extension: 3.42.0

qupig avatar Nov 13 '24 19:11 qupig

Also reproducible with keybindings.json a.k.a. workbench.action.openGlobalKeybindingsFile a.k.a. Preferences: Open Keyboard Shortcuts (JSON).

dogfuntom avatar Nov 18 '24 20:11 dogfuntom

@dogfuntom Thank you for adding.

I'm assuming user level jsonc config files may all have the same issue.

qupig avatar Nov 18 '24 20:11 qupig

@qupig Do you use WSL on Windows by any chance? I encountered this issue but it turns out it's because the user settings file is in a Windows directory.

nayeemrmn avatar Feb 11 '25 21:02 nayeemrmn

@nayeemrmn No, I'm in macOS.

qupig avatar Feb 12 '25 04:02 qupig

@nayeemrmn, I think the problem is that the settings.json file does not have a "file" scheme but rather "vscode-userdata" for which the extension is not registered. Extension is currently registered for the "file" and "untitled" schemes (for the jsonc file type, of course). I was able to replace the schema in my LSP (as a proof of concept) and the file is formatted

redking00 avatar Feb 12 '25 19:02 redking00

According to @redking00's instructions, I found this in prettier extension:

https://github.com/prettier/prettier-vscode/blob/b8d9e42b8900c88e2210bc72615d9f925439b058/src/PrettierEditService.ts#L337-L340

It seems that the issue can finally be solved. 🎉

qupig avatar Feb 13 '25 08:02 qupig