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

Problem with CSharpier - Code Format (VSCode Extension) #1114

Closed
evertonandrade opened this issue Jan 6, 2024 · 8 comments · Fixed by #1183
Closed

Problem with CSharpier - Code Format (VSCode Extension) #1114

evertonandrade opened this issue Jan 6, 2024 · 8 comments · Fixed by #1183

Comments

@evertonandrade
Copy link

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

@belav
Copy link
Owner

belav commented Jan 8, 2024

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]"

@evertonandrade
Copy link
Author

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

@belav belav added this to the Planned - Extensions milestone Jan 31, 2024
@belav
Copy link
Owner

belav commented Feb 2, 2024

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": "",

@evertonandrade
Copy link
Author

evertonandrade commented Feb 3, 2024

@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": ""

@belav
Copy link
Owner

belav commented Feb 12, 2024

@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.

@evertonandrade
Copy link
Author

@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.

@belav
Copy link
Owner

belav commented Feb 19, 2024

@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.

@evertonandrade
Copy link
Author

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants