Giter Club home page Giter Club logo

Comments (31)

deviousasti avatar deviousasti commented on May 29, 2024 1

from fantomas-for-vs.

abelbraaksma avatar abelbraaksma commented on May 29, 2024 1

That's an interesting error, as I installed the tool globally with the -g flag. Also, the Fantomas plugin worked in other projects.

The improved error reporting is very useful, thanks!

However, good news is that after doing a dotnet tool restore on the root of the project that didn't work, it now picks it up correctly. Is it possible that if fantomas is configured for a project that it does not attempt to find the tool on the global path?

I don't know if this would also solve it for @Nekroido, my project was not one with WSL2-hosted files.

from fantomas-for-vs.

deviousasti avatar deviousasti commented on May 29, 2024

Hey @Nekroido,
Sorry for the delayed reply. I suspect it could be a permissions issue.
Here's the issue I'm seeing:

Fantomas.Client tried to run dotnet tool list but exited with code 1. File dotnet-tools.json came from another computer and might be blocked to help protect this computer. For more information, including how to unblock, see https://aka.ms/motw

If there's a dotnet tool version defined in dotnet-tools.json, Fantomas tries to use that specific version.

from fantomas-for-vs.

deviousasti avatar deviousasti commented on May 29, 2024

It will work if there's no tool manifest defined - with the globally installed formatter.

from fantomas-for-vs.

Nekroido avatar Nekroido commented on May 29, 2024

Hi! Sorry, looks like I never pressed the "Comment" button.
I do have the manifest file, but only with the paket entry. The error I see in my "Output: F# Formatting" is this:

The operation is not supported:
 The FantomasResponseCode value '11' is unexpected.

from fantomas-for-vs.

nojaf avatar nojaf commented on May 29, 2024

Hello, Code '11' means that Fantomas daemon (your global or local tool) could not be started.
Can you execute:

open System
open System.IO

let userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
Path.Combine(userProfile, ".dotnet", "tools", "fantomas.exe")

in a F# interactive session (dotnet fsi) and verify that the path that comes out of there exists.

from fantomas-for-vs.

Nekroido avatar Nekroido commented on May 29, 2024

The path exists in the Windows host. It also exists in my Debian host but without the .exe extension.

from fantomas-for-vs.

nojaf avatar nojaf commented on May 29, 2024

Alright, can you execute the exe in the command line?
You shouldn't see anything, but if that crashes, that already tells us something.

from fantomas-for-vs.

Nekroido avatar Nekroido commented on May 29, 2024

Both executables exit with Input path is missing...

from fantomas-for-vs.

nojaf avatar nojaf commented on May 29, 2024

Ah apologies, you need to add the --daemon flag.
So C:\fullPath\fantomas.exe --daemon

from fantomas-for-vs.

Nekroido avatar Nekroido commented on May 29, 2024

Both executables wait for the input and crash with the following trace when I press Enter:

Unhandled exception. StreamJsonRpc.BadRpcHeaderException: No Content-Length header detected.
   at StreamJsonRpc.HeaderDelimitedMessageHandler.ReadCoreAsync(CancellationToken cancellationToken)
   at StreamJsonRpc.MessageHandlerBase.ReadAsync(CancellationToken cancellationToken)
   at StreamJsonRpc.JsonRpc.ReadAndHandleRequestsAsync()
   at Program.main(String[] argv) in C:\Users\nojaf\Projects\fantomas\src\Fantomas.CoreGlobalTool\Program.fs:line 441

from fantomas-for-vs.

nojaf avatar nojaf commented on May 29, 2024

Yeah, that sounds about right.
The error you get when pressing enter makes sense.
So, I can conclude here that the daemon can be started but not programmatically on your end.
There could be a bug in Fantomas.Client.

Could you create a script file with:

#r "nuget: Fantomas.Client"

open System.IO
open Fantomas.Client.Contracts
open Fantomas.Client.LSPFantomasService

let service = new LSPFantomasService() :> FantomasService

// TODO: change file path to existing file on your machine
let file = @"C:\Users\nojaf\Projects\HelloWorld\Math.fs"
let content = File.ReadAllText file

let response =
    service.FormatDocumentAsync { SourceCode = content; FilePath = file; Config = None }
    |> Async.AwaitTask
    |> Async.RunSynchronously

printfn "%A" response

What does that output?

from fantomas-for-vs.

Nekroido avatar Nekroido commented on May 29, 2024

It outputs a formatted document in Windows environment when I provide a valid absolute \\wsl$\Debian\... path. Same for Debian for a /home/... path.

I see the error you mentioned initially if I use \\wsl.localhost\... path.

from fantomas-for-vs.

nojaf avatar nojaf commented on May 29, 2024

Yeah, the behaviour we see is starting to make some sense.
Something is going wrong when requests are made with UNIX paths inside the Windows host.

from fantomas-for-vs.

abelbraaksma avatar abelbraaksma commented on May 29, 2024

Just chiming in as I'm running into the exact same issue. Nothing happens when I try to execute Format Document (or a variant, like saving with format-on-save set to 'on'). I'm on Windows 10, VS 2022, all recent updates, F# 6.0 etc. Just installed F# Formatting extension. Same output in the Output window:

The operation is not supported:
 The FantomasResponseCode value '11' is unexpected.

Running the commands above work just like @Nekroido mentions.

from fantomas-for-vs.

abelbraaksma avatar abelbraaksma commented on May 29, 2024

@nojaf Is there a way to get more detailed output, or to set it up for debugging?

I should probably add that we use the .editorconfig file approach, as there's nothing that we can set inside the F# > Formatting options window. I know this is an open bug. I dunno if this may have anything to do with the extension not working.

from fantomas-for-vs.

nojaf avatar nojaf commented on May 29, 2024

Hi, I don't think .editorconfig is relevant here.
To debug you could create a sort of integration unit test where you reference Fantomas.Client and try to mimic what the editor is doing in

service.FormatDocumentAsync(new Contracts.FormatDocumentRequest(originText, path, null), token),

If you can step into the Fantomas.Client source, I expect
https://github.com/fsprojects/fantomas/blob/0e036ac3c54301fb8208205c1af0613e7bb06636/src/Fantomas.Client/LSPFantomasService.fs#L74
would be a good place to look what exactually happened.

from fantomas-for-vs.

abelbraaksma avatar abelbraaksma commented on May 29, 2024

Btw, this is not WSL2. However, I just found out that the formatting does work correctly on an older .NET Framework project, using VS 2022.

@nojaf, thanks, I'll give it a go.

from fantomas-for-vs.

deviousasti avatar deviousasti commented on May 29, 2024

I've published a new version for VS22 that has much better error logging for this case.
Could you please update and post your logs here. 😊

from fantomas-for-vs.

abelbraaksma avatar abelbraaksma commented on May 29, 2024

I'll try, let me update.

from fantomas-for-vs.

abelbraaksma avatar abelbraaksma commented on May 29, 2024

@deviousasti, silly question, but I only installed this so far through Marketplace. Do you know what to update? I assume I run the build.ps1 script, but then what, just replace some dll somewhere, I guess?

from fantomas-for-vs.

deviousasti avatar deviousasti commented on May 29, 2024

from fantomas-for-vs.

abelbraaksma avatar abelbraaksma commented on May 29, 2024

I just did a local compile of the sln file, found the vsix, uninstalled old, re-installed with vsix from the release dir.

from fantomas-for-vs.

abelbraaksma avatar abelbraaksma commented on May 29, 2024

Oh, yes, that'd work too! 😄

from fantomas-for-vs.

abelbraaksma avatar abelbraaksma commented on May 29, 2024

@deviousasti, this is the new output from the tool:

Creating the Fantomas Daemon failed:
Fantomas.Client tried to run `dotnet fantomas --daemon` but failed with "Daemon std error: Run "dotnet tool restore" to make the "fantomas" command available.
.
JsonRpc exception:One or more errors occurred."
Attempting to find Fantomas Tool...
Found at: FantomasToolFound
  (FantomasVersion "4.6.0",
   LocalTool
     (Folder
        "D:\Projects\MyProject.Tests\Hosting\Subscriptions"))

from fantomas-for-vs.

deviousasti avatar deviousasti commented on May 29, 2024

Is it possible that if fantomas is configured for a project that it does not attempt to find the tool on the global path?

Yes, this is the current behavior.

from fantomas-for-vs.

Nekroido avatar Nekroido commented on May 29, 2024

Yup, it's much clearer where the issue lies now. I can confirm the "file came from another computer" error. I guess I'm out of luck and I need to consider setting up my dev env in Windows host. Unless it's possible to skip loading dotnet-tools.json and use the globally installed tool instead.

from fantomas-for-vs.

nojaf avatar nojaf commented on May 29, 2024

The flow is the following:
It will check if you have a local tool (using dotnet tool list),
next, it will check if it has a global tool (using dotnet tool list -g).

So, if you have a global tool in both places that might work but I suspect you will bump into problems when detecting the .editorconfig.

from fantomas-for-vs.

deviousasti avatar deviousasti commented on May 29, 2024

On WSL2, if there's no local config, I can confirm that the file formats with the global tool.

from fantomas-for-vs.

snuup avatar snuup commented on May 29, 2024

I have a fresh machine and installed the extension into Visual Studio, getting the same error @abelbraaksma 👍

Tried many things, those are the steps that need to be done in addition to installing this VS extension:

dotnet tool install fantomas-tool -g 

Reopening of Visual Studio is sometimes needed. Also

dotnet restore

The options pane is not shown, but that is already mentioned in well handled in #28

from fantomas-for-vs.

sonicbhoc avatar sonicbhoc commented on May 29, 2024

I too am running into this. Is there a way to configure Fantomas to look for a global tool if the local tool fails with this specific error?

from fantomas-for-vs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.