belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.41k stars 99 forks source link

VS Code extension doesn't find installed version of CSharpier, fails silently #1348

Open tysonstewart opened 2 months ago

tysonstewart commented 2 months ago

Environments

Log Output

["ERROR" - 8:38:23 PM] CSharpier was not found so files may not be formatted.

It then tries to install from NuGet and seems to ignore the NuGet.Config in the project directory, so I got an error here too until I added the NuGet repo to $HOME/.nuget/NuGet/NuGet.Config.

So then when you try to format files, you get something like:

Formatting started for $PATH using NULL

Steps to reproduce

  1. Set up a devcontainer using the image above.
  2. Install the tool with dotnet tool install csharpier (using -g also does not work)
  3. Remove the nuget.org repo from your packageSources in $HOME/.nuget/NuGet/NuGet.Config
  4. Reload VS Code window
  5. Try to format a .cs file

This is reproducible for me and my colleagues across our platforms, but may have something to do with our repo and/or devcontainer configuration.

Expected behavior

The extension should find the locally-installed tool and use it without needing to resort to fetching it from nuget.org. It would also be nice if it gave a little help in the UI when it's in this state. For me, when I removed the nuget.org repo from my $HOME config (but it was still in the repo config) and rebuilt the devcontainer, formatting suddenly stopped working. That was really unexpected and I wasn't sure where to go from there.

Actual behavior

The extension fails to find CSharpier, tries to install from NuGet, and if that fails, silently fails to format.


Workaround: ensure that the nuget.org repo is a package source in $HOME/.nuget/NuGet/NuGet.Config in the container and it should work OK, but will probably ignore the version you have configured in your repo .config/dotnet-tools.json if any.

Just want to add, though: we really like this extension. Microsoft's C# Dev Kit extension just doesn't cut it when it comes to code formatting. Thank you for this!