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

Replaces the whole file with time status. #972

Closed
FormalSnake opened this issue Oct 6, 2023 · 9 comments
Closed

Replaces the whole file with time status. #972

FormalSnake opened this issue Oct 6, 2023 · 9 comments

Comments

@FormalSnake
Copy link

I am using nvim format-on-save, and using this line I got it to execute the dotnet csharpier command:

cs = formatters.shell({ cmd = { "dotnet-csharpier", "." } }),

and it replaces the whole file with:
Formatted 5 files in 98ms.

@FormalSnake
Copy link
Author

I am not sure if this is a plugin issue or a csharpier problem

@belav
Copy link
Owner

belav commented Oct 6, 2023

I'm not familiar with nvim format-on-save, but the command dotnet-csharpier . will format files in place in the location it is run from.

If you run dotnet-csharpier [pathToFile] --write-stdout it would read the saved file and write the formatted results back to std out, which may work.

It is also possible to pipe input to dotnet-csharpier --write-stdout, which will also write the formatted results of the piped file back to std out.

You may also want to look into https://github.com/sbdchd/neoformat which has support for csharpier. The fact that it supports csharpier is the extent of my knowledge though, I don't know how it compares to nvim format-on-save.

@FormalSnake
Copy link
Author

So, after testing the command it does not seem to output the file, even in the normal console.
Screenshot 2023-10-06 at 22 21 42

@FormalSnake
Copy link
Author

it only outputs when I make a change to the file

@FormalSnake
Copy link
Author

but then the file just becomes empty when I save with no change

@belav
Copy link
Owner

belav commented Oct 6, 2023

Ah, it seems that there is a bug related to the caching that is done to speed up formatting when combined with --write-stdout. I created #973 to address that.

For now if you run with --write-stdout --no-cache then the file will be returned. However if there is a compilation error, then an error is written on stderror and nothing is written on stdout. I believe it also returns an exitcode of 1.

image

@FormalSnake
Copy link
Author

Yep, that did work. But can there be an argument to not output errors and just the file without formatting?
cs = formatters.shell({ cmd = { "dotnet-csharpier", "%", "--write-stdout", "--no-cache" } }),

@belav
Copy link
Owner

belav commented Oct 7, 2023

There isn't a way to get back the file, but --loglevel none would prevent the error from returning. Which probably gets you back to ending up with an empty file.

Maybe your best bet for now is to wire up some basic logic that checks the exit code of csharpier, either returning the output of csharpier, or the contents of the file. Put that into a powershell or bash script, and then call that script from your formatter.

@FormalSnake
Copy link
Author

I will try that out, I should probably open an issue in the neovim plugin aswel.

@belav belav closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants