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

fails to format when config file in sub folder and has a relative includes glob

Open scottbessler opened this issue 2 years ago • 6 comments

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

image

scottbessler avatar Feb 01 '23 18:02 scottbessler

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.

dsherret avatar Feb 01 '23 19:02 dsherret

hmm i wonder if is potentially related to multi-root workspaces?

scottbessler avatar Feb 01 '23 19:02 scottbessler

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.

dsherret avatar Feb 01 '23 19:02 dsherret

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.

scottbessler avatar Feb 01 '23 19:02 scottbessler

Oh, that seems like a bug. Thanks for reporting back! I will investigate it soon.

dsherret avatar Feb 01 '23 21:02 dsherret

I'm also running into this, and discovered an interesting thing:

  1. we have a vscodium workspace with dprint config in the root (with no includes)
  2. 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)
  3. if i open from the file explorer then i get a relative workspace path and dprint works just fine

gotjoshua avatar Jan 17 '24 17:01 gotjoshua