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

Add --stdout option OR option to remove delimiters from --preview-only #97

Closed
omarjatoi opened this issue Oct 26, 2024 · 1 comment
Closed

Comments

@omarjatoi
Copy link

Hi, I wrote an extension supporting SML for the Zed text editor (https://github.com/omarjatoi/zed-sml) and want to use smlfmt to format the buffer on save. The editor expects the formatter to output the formatted buffer to stdout. I'm able to configure it to use --preview-only, but this has delimiters at the top and bottom.

For example, if I open a buffer with the contents:

signature MAIN_STRUCTS =
   sig
   end

signature MAIN =
   sig
      include MAIN_STRUCTS

      val main: string * string list -> OS.Process.status
      val mainWrapped: unit -> 'a
   end

and save the file, my buffer now has:

---- mlton/mlton/main/main.sig ----
signature MAIN_STRUCTS = sig end

signature MAIN =
sig
  include MAIN_STRUCTS

  val main: string * string list -> OS.Process.status
  val mainWrapped: unit -> 'a
end
--------

I also tried passing --force to format the file in-place, but since the editor is replacing the buffer with the contents of stdout the contents of the buffer get formatted and then immediately emptied out by smlfmts stdout (which is nothing).

If the existing behavior is desirable, we could add a new option --stdout or --preview-only-no-delimiters that sends the formatted contents to stdout without the bottom and filename at top delimiters. Alternatively, we could add a supplementary option for --preview-only like --no-delimiters.

If either of these options sound good I'd be happy to open a PR with the suggested changes. Thanks!

@omarjatoi
Copy link
Author

Closing this issue, I just realized I was passing the path to the file, and after seeing #84 I realized I could send the contents of the buffer instead of the path to the file instead, yielding the results I expected.

Sorry for missing the obvious!

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

1 participant