dprint-vscode icon indicating copy to clipboard operation
dprint-vscode copied to clipboard

VS Code ignores `dprint.json` and stops formatting with `dprint` version `0.16.1` on Mac

Open schreter opened this issue 9 months ago • 4 comments

Version 0.16.0 works just fine with VS Code on Mac and formats documents.

Version 0.16.1 stopped working. Initialization of the plugin fails with "No configuration file found" printed to the output. The configuration dprint.json in the workspace exists, of course.

Seems like the fix #80 broke it, that's the only one referenced in release notes between 0.16.0 and 0.16.1.

I only tested on newest VS Code 1.89.0 on MacOS.

Downgrading to 0.16.0 restores format-on-save via dprint.

schreter avatar May 07 '24 15:05 schreter

@schreter do you have a repo I could try it out on? If not, what does the setup look like? It's been working for me.

dsherret avatar May 07 '24 15:05 dsherret

do you have a repo I could try it out on?

Sorry, it's a private repo (and quite large). dprint on the command line works just fine (well, it's also independent :-)).

It's been working for me.

Are you also on MacOS w/ newest VS Code? It could be an OS-related problem.

schreter avatar May 08 '24 08:05 schreter

If not, what does the setup look like?

Ah, sorry, missed this one. Here some more details:

  • we use dprint 0.45.1
  • the config is under workspace root in dprint.json

dprint.json:

{
  "incremental": true,
  "markdown": {
    "lineWidth": 100,
    "textWrap": "always",
    "unorderedListKind": "asterisks"
  },
  "toml": {
  },
  "includes": ["**/*.{md,toml}"],
  "excludes": ["external/**"],
  "plugins": [
    "https://plugins.dprint.dev/markdown-0.17.0.wasm",
    "https://plugins.dprint.dev/toml-0.6.1.wasm"
  ]
}

VS Code will not even load dprint extension (with version 0.16.1) due to supposedly missing config file. Trying to format md file will tell me there is no formatter available.

The VS Code is configured w.r.t. dprint like this:

    "[markdown]": {
        "editor.defaultFormatter": "dprint.dprint",
        "editor.formatOnSave": true
    },
    "[toml]": {
        "editor.defaultFormatter": "dprint.dprint",
        "editor.formatOnSave": true
    }

BTW, I also tried to minimize dprint.json to check whether some contents there is causing an issue, but to no avail.

schreter avatar May 08 '24 09:05 schreter

I did some digging into dprint-vscode changes. I now see the issue.

The config file is there in the workspace, but it is hidden from the Explorer view by

    "files.exclude": {
        ...
        "dprint.json": true,
        ...
    }

It seems like in VS Code the function fs.existsSync doesn't "see" the file if it's hidden. The question is what to do about it (except removing the exclude).

We did hide quite a few files in workspace directory, since it's polluted by a lot of stuff which various tools require to have in the root of the workspace.

schreter avatar May 08 '24 18:05 schreter