Skip to content

Extension does not register as formatter for jsonc (and json) language, or anything other extension for that matter #138

@AMDphreak

Description

@AMDphreak

Describe the bug
The dprint VS Code extension does not properly register as a formatter for the jsonc language ID. As a result, dprint does not appear in the "Default Formatter" dropdown for JSON with Comments (e.g. settings.json, launch.json, *.code-workspace) unless the user manually sets "[jsonc]": { "editor.defaultFormatter": "dprint.dprint" } in settings.

To reproduce

  1. Install the dprint extension and ensure a dprint config exists (e.g. with the json plugin).
  2. Open a .jsonc or settings.json (or any file with language mode "JSON with Comments").
  3. Open the Command Palette → "Format Document With..." or check Settings → Default Formatter for jsonc.
  4. dprint is not listed / not the default.

Expected
dprint should be offered as a formatter for jsonc (and json) when the workspace has dprint config that includes the json plugin.

Workaround
Add to workspace or user settings:

"[jsonc]": { "editor.defaultFormatter": "dprint.dprint" }

Cause
The extension registers DocumentFormattingEditProvider only with document selectors built from glob patterns ({ scheme: "file", pattern }). VS Code does not reliably associate such glob-only selectors with the jsonc language ID, so the extension does not appear in the formatter list for that language.

Fix
Explicitly register the same provider for language IDs jsonc and json (e.g. add { scheme: "file", language: "jsonc" } and { scheme: "file", language: "json" } to the document selectors). I can open a PR with this change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions