dprint-vscode
dprint-vscode copied to clipboard
fails to format when config file in sub folder and has a relative includes glob
Using dprint extension v0.13.5 With vs code insiders:
Version: 1.75.0-insider (Universal)
Commit: e2816fe719a4026ffa1ee0189dc89bdfdbafb164
Date: 2023-02-01T15:16:42.458Z (3 hrs ago)
Electron: 19.1.9
Chromium: 102.0.5005.194
Node.js: 16.14.2
V8: 10.2.154.23-electron.0
OS: Darwin arm64 21.6.0
Sandboxed: Yes
For some reason, the dprint extension fails with this error:
Extension 'Dprint Code Formatter' is
configured as formatter but it cannot
format 'TypeScript'-files

It works for me in 1.75.0 insiders. Do you have a dprint configuration file in the folder? It's necessary at the moment in order to define the plugins.
hmm i wonder if is potentially related to multi-root workspaces?
Maybe. I have tested for that scenario in the past. Does it work when not in a multi-root workspace?
You might want to set the following option in your settings:
{
"dprint.verbose": true
}
Then in the "Output" pane select "dprint". It should log everything it's doing.
Ok I think I figured it out, and it was related to my includes expecting to resolve relative to the location of the dprint.json file.
Our code-workspace file exists in a subfolder we'll call foo:
"folders": [
{
"path": ".",
"name": "foo"
},
{
"path": "..",
"name": "root"
}
],
I had the dprint.json in the "foo" folder
The ts/js code is in foo/packages/**
So I had:
"includes": ["packages/**/*.{ts,tsx,js,jsx,mjs}"],
And the verbose logs show:
[VERBOSE] Reading file: /redacted/repo/foo/dprint.json
[VERBOSE] Checking path exists: /redacted/dprint/cache/plugins/dprint-plugin-prettier/0.19.0/aarch64/dprint-plugin-prettier
[VERBOSE] Reading file: /redacted/dprint/cache/plugins/dprint-plugin-typescript/0.81.1-aarch64.cached
[VERBOSE] Checking can format: /redacted/repo/foo/packages/bar/src/index.ts
[VERBOSE] Response - File not matched: /redacted/repo/foo/packages/bar/src/index.ts
which led me to try changing my includes to:
"includes": ["**/packages/**/*.{ts,tsx,js,jsx,mjs}"],
which seems to have resolved my issue.
Oh, that seems like a bug. Thanks for reporting back! I will investigate it soon.
I'm also running into this, and discovered an interesting thing:
- we have a vscodium workspace with dprint config in the root (with no includes)
- if i open a file from cli or via click through from another package in the monorepo i get an absolute path - and dprint will not work (with the same cannot format 'TypeScript'-files error)
- if i open from the file explorer then i get a relative workspace path and dprint works just fine