Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
scottbessler opened this issue Feb 1, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@scottbessler
Copy link

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

@dsherret
Copy link
Member

dsherret commented Feb 1, 2023

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.

@scottbessler
Copy link
Author

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

@dsherret
Copy link
Member

dsherret commented Feb 1, 2023

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.

@scottbessler
Copy link
Author

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.

@dsherret
Copy link
Member

dsherret commented Feb 1, 2023

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

@dsherret dsherret changed the title fails to format in vscode-insiders fails to format when config file in sub folder and has a relative includes glob Feb 1, 2023
@dsherret dsherret added the bug Something isn't working label Feb 1, 2023
@gotjoshua
Copy link

gotjoshua commented Jan 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants