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

Ormolu moves shebang from first line to the end of the file #377

Closed
mavnn opened this issue Sep 13, 2019 · 7 comments · Fixed by #379 or #465
Closed

Ormolu moves shebang from first line to the end of the file #377

mavnn opened this issue Sep 13, 2019 · 7 comments · Fixed by #379 or #465
Labels
bug Something isn't working
Projects

Comments

@mavnn
Copy link

mavnn commented Sep 13, 2019

Write a simple Haskell script:

#! /usr/bin/env runhaskell
import Prelude

main :: IO ()
main = putStrLn "hello world"

Run ormolu:

import Prelude

main :: IO ()
main = putStrLn "hello world"
#! /usr/bin/env runhaskell

Is it possible to make Ormolu aware of shebang lines at the beginning of files?

@mrkkrp mrkkrp added bug Something isn't working comments Issues related to comment placement labels Sep 13, 2019
@mrkkrp
Copy link
Member

mrkkrp commented Sep 13, 2019

Hmm, I cannot reproduce this. I get exactly the same source code unchanged if I run Ormolu. Are you using the latest version from current master?

@mrkkrp mrkkrp removed bug Something isn't working comments Issues related to comment placement labels Sep 13, 2019
@mrkkrp
Copy link
Member

mrkkrp commented Sep 14, 2019

Interesting, I was re-checking this today and it indeed seems to be the case, not sure what happened yesterday. I'll look into this.

@mrkkrp mrkkrp added the bug Something isn't working label Sep 14, 2019
@mrkkrp mrkkrp self-assigned this Sep 14, 2019
@mrkkrp
Copy link
Member

mrkkrp commented Sep 14, 2019

The bug was related to how we extract shebangs from sources and convert them to comments. We generate spans for those comments manually and then the normal machinery for comments renders the shebangs. Interestingly we used a fixed file name SHEBANG for shebangs (the code is partly taken from ghc-exactprint and I don't know why they do it like this there), so the way it was popped from the stream actually depended on name of input file! For example with Shebang.hs (I started with this one) the "shebang-comment" always was deemed less than any other span "SHEBANG" < "Shebang.hs" and so it was promptly popped and inserted, thus I concluded that there is no bug. When I later tried with Foo.hs I got a different result, matching yours.

@mrkkrp
Copy link
Member

mrkkrp commented Sep 14, 2019

@mavnn This is now fixed, nice catch!

@mavnn
Copy link
Author

mavnn commented Sep 15, 2019 via email

@cblp
Copy link
Contributor

cblp commented Sep 20, 2019

Not fixed:

#!/usr/bin/env stack

{-# LANGUAGE OverloadedStrings #-}

main = pure ()

is reformatted as

{-# LANGUAGE OverloadedStrings #-}

#!/usr/bin/env stack
main = pure ()

@mrkkrp
Copy link
Member

mrkkrp commented Sep 20, 2019

Let's re-open this one then. Still this (and #393) is not going to make it in the first release.

@mrkkrp mrkkrp reopened this Sep 20, 2019
@mrkkrp mrkkrp added this to TODO in 0.0.2.0 Oct 3, 2019
@mrkkrp mrkkrp removed their assignment Oct 5, 2019
@mrkkrp mrkkrp moved this from TODO to Done in 0.0.2.0 Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants