dprint / dprint-vscode

Visual Studio Code extension for formatting code with dprint.
MIT License
59 stars 12 forks source link

Feature request: Add an option to configure a custom location for .dprint.json #56

Open cameronhunter opened 1 year ago

cameronhunter commented 1 year ago

dprint supports a --config CLI parameter allowing for a custom configuration path to be specified. However, the VSCode plugin expects .dprint.json to be in the root of the workspace. It would be great if a configuration property could be added to the plugin, for example, "dprint.configurationFile": "path/to/my/dprint.json".

dsherret commented 1 year ago

Is your configuration in a sub directory and called either “dprint.json” or “.dprint.json”? If so, it should just work for that sub directory.

cameronhunter commented 1 year ago

Thanks for the quick response. Our dprint.json config file is in a directory such as tools/config/formatting/

dsherret commented 1 year ago

I think it should just automatically pick that up in that case and use that config. You can see in "View > Output" then select "dprint" in the drop down of the output window. It should show all the folders it got initialized in.

dsherret commented 1 year ago

Oh wait, I think I misunderstood. You want it to use the configuration in /your-project/tools/config/formatting/ for the /your-project/ directory? The above will only use it in /your-project/tools/config/formatting/.

I'm not sure I want to support having configurations in non-standard sub directories because it adds more complexity and maintenance overhead (ex. need to define "use this config for this folder and this config for that folder") and I'm not sure about the benefit. Plus it makes it so you can't just run dprint fmt in the project's directory and things "just work", so I think I'd rather discourage it. Most tools require their configs in the root folder.

spiffre commented 1 year ago

I have a similar and yet somewhat different need: I use a .jsonc file for my config (so I can put comments).

The CLI is happy with it as long as I point to it via the --config option.

The VSCode extension however does not automatically look for that file extension, and that's why I was also looking for an option to set the path (but really the name) of the configuration file.

Is that something that might happen in the future -- that or adding dprint.jsonc to the list of possible config files?

dsherret commented 1 year ago

@spiffre I opened https://github.com/dprint/dprint-vscode/pull/59 to auto-discover .jsonc config files.

spiffre commented 1 year ago

Many thanks @dsherret!