csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Problem with CSharpier - Code Format (VSCode Extension)

Open evertonandrade opened this issue 2 years ago • 5 comments

Environments

  • IDE Version: VSCode 1.85.1
  • Extension Version: v1.5.2
  • CSharpier Version: 0.26.7
  • Operating System: Arch Linux

Log Output ["ERROR" - 7:41:38 PM] CSharpier was not found so files may not be formatted. ["INFO" - 7:41:38 PM] 1 ["INFO" - 7:41:40 PM] Formatting started for /home/everton/Dev/playgrounds/CSharpPlayground/Program.cs. ["DEBUG" - 7:41:40 PM] /home/everton/.vscode/extensions/csharpier.csharpier-vscode-1.5.2/build ["DEBUG" - 7:41:40 PM] /home/everton/.vscode/extensions/csharpier.csharpier-vscode-1.5.2/build ["DEBUG" - 7:41:40 PM] Ensure there is a csharpier process for /home/everton/Dev/playgrounds/CSharpPlayground ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/playgrounds/CSharpPlayground/.csproj ["DEBUG" - 7:41:40 PM] Looking at /home/everton/Dev/playgrounds/CSharpPlayground/CSharpPlayground.csproj ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/playgrounds/CSharpPlayground/.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/playgrounds/.csproj ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/playgrounds/.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/.csproj ["DEBUG" - 7:41:40 PM] Looking for /home/everton/Dev/.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Looking for /home/everton/.csproj ["DEBUG" - 7:41:40 PM] Looking for /home/everton/.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Looking for /home/.csproj ["DEBUG" - 7:41:40 PM] Looking for /home/.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Looking for //.csproj ["DEBUG" - 7:41:40 PM] Looking for /.config/dotnet-tools.json ["DEBUG" - 7:41:40 PM] Unable to find dotnet-tools.json, falling back to running dotnet csharpier --version ["DEBUG" - 7:41:41 PM] dotnet csharpier --version failed with Could not execute because the specified command or file was not found. Possible reasons for this include:

  • You misspelled a built-in dotnet command.
  • You intended to execute a .NET program, but dotnet-csharpier does not exist.
  • You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

["ERROR" - 7:41:41 PM] CSharpier was not found so files may not be formatted. ["INFO" - 7:41:41 PM] 1 ["DEBUG" - 7:41:41 PM] returning NullCSharpierProcess because there was no csharpierProcessesByVersion for ["DEBUG" - 7:41:41 PM] Skipping formatting because this is a NullCSharpierProcess. This generally indicates there was a problem starting the CSharpier process ["INFO" - 7:41:41 PM] Formatted in 860.4347350001335ms ["DEBUG" - 7:41:41 PM] result is empty

Steps to reproduce

  • Install extension
  • Install Csharpier tool globally
  • Try formart with Csharpier - code format VSCode extension

Expected behavior It was expected that with the tool installed globally, formatting would work, but this does not happen. The extension only works with local installation

Actual behavior With global installation it is not possible to use the extension, even passing the correct path to dotnet-csharpier image

evertonandrade avatar Jan 06 '24 22:01 evertonandrade

I believe the problem has to do with PATH, and the extension not being able to run the dotnet csharpier --version command to determine which version of CSharpier is being used. I have an open issue to try to add better support for this #893

I'm not familiar with Linux, so I don't know if the workaround for macOS from that issue also applies.

You also may be able to use this setting I added for testing the extensions as a workaround. It will keep the application running from that location but I believe that is only a problem with windows.

"csharpier.dev.customPath": "[PathToFolderContainingDotnetCSharpier]"

belav avatar Jan 08 '24 16:01 belav

Hi @belav

image this solution didn't work for me =/

however, via cli it worked image

It's a problem with the extension to find the global csharpier because with a local installation it also works

evertonandrade avatar Jan 23 '24 02:01 evertonandrade

Hey @evertonandrade I have ubuntu set up now and am digging into this.

If you run which dotnet in vscode, what is the result?

And by chance do you have any of the following set?

"dotnet.dotnetPath": "",
"dotnetAcquisitionExtension.existingDotnetPath": [ "" ],
"omnisharp.sdkPath": "",

belav avatar Feb 02 '24 19:02 belav

@belav running which dotnet in vscode I have the output /usr/bin/dotnet: image

in my settings.json (ctrl + shift + p > Preferences: Open User Settings (JSON), i don't have:

"dotnet.dotnetPath": "",
"dotnetAcquisitionExtension.existingDotnetPath": [ "" ],
"omnisharp.sdkPath": ""

evertonandrade avatar Feb 03 '24 14:02 evertonandrade

@evertonandrade I have these changes mostly done, I just want to do some more testing. I was going to install arch linux because I believe it may handle PATH a bit differently than ubuntu, but it didn't seem like a straightforward install.

I'm hoping the new beta will find dotnet automatically for you but if not the extension now supports setting dotnet.dotnetPath or omnisharp.dotNetCliPaths.

If you have a chance to try it out let me know if it is working.

belav avatar Feb 12 '24 03:02 belav

@belav , I've been investigating and found the problem.

For some reason, process.env.PATH when called from running a vscode extension does not show me the full PATH of my system. I created a small test playground extension to verify this. The result was: 2024-02-17_17-17

However, in another testing playground for nodejs I have the complete result: image

Another test I did was run vscode as root user sudo code Dev/playgrounds/vscode-extension-playground --no-sandbox --user-data-dir="~/.vscode-root"

image This way I was able to access the complete PATH of the system

I still have no idea why this behavior happens. until recently the extension works well on my Arch Linux.

evertonandrade avatar Feb 17 '24 20:02 evertonandrade

@evertonandrade Did the c# extension continue to work? I pulled in some code from that, and they don't appear to be doing anything out of the ordinary when trying to locate dotnet on the PATH.

Someone had mentioned that running sh -c "dotnet" may work better with PATH, so I included that logic in the latest version of the extension. It also shows an error message letting the user know why it can't format anything and contains logs that should help track down any PATH issues.

belav avatar Feb 19 '24 17:02 belav

@belav

The problem is not dotnet. The C# (Microsoft) extension is working fine. The problem is the installed tools that can only be called when they are in the PATH. In my .zshrc file I add export PATH="$PATH:$HOME/.dotnet/tools/" to the end, and the tool works perfectly via the cli, however, in the vscode context it was not possible to access it because in the PATH is not available (unless I run as root user).

evertonandrade avatar Feb 22 '24 02:02 evertonandrade