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

HLS deletes shebang line #4143

Open
Vic-M opened this issue Mar 19, 2024 · 4 comments
Open

HLS deletes shebang line #4143

Vic-M opened this issue Mar 19, 2024 · 4 comments
Labels
status: blocked Not actionable, because blocked by upstream/GHC etc. type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@Vic-M
Copy link

Vic-M commented Mar 19, 2024

HLS deletes the shebang line in single file scripts when accepting a suggestion.

Your environment

Which OS do you use?
Windows WSL2 running CentOS Stream 9

Which version of GHC do you use and how did you install it?
GHC 9.4.8 from ghcup

Which LSP client (editor/plugin) do you use?
vscode haskell

Which version of HLS do you use and how did you install it?
HLS 2.7.0.0 from ghcup

Steps to reproduce

Use the following the code:

#!/usr/bin/env cabal

{- cabal:
default-language: GHC2021

build-depends:
    base ^>=4.17.0.0,
-}

main :: IO ()
main = print $ fmap (\x -> x + 1) [1,2,3]

image

Accept the suggestion.

Expected behaviour

#!/usr/bin/env cabal

default-language: GHC2021

{- cabal:
default-language: GHC2021

build-depends:
    base ^>=4.17.0.0,
-}

main :: IO ()
main = print $ fmap (+ 1) [1,2,3]

Actual behaviour



{- cabal:
default-language: GHC2021

build-depends:
    base ^>=4.17.0.0,
-}

main :: IO ()
main = print $ fmap (+ 1) [1,2,3]
@Vic-M Vic-M added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Mar 19, 2024
@fendor
Copy link
Collaborator

fendor commented Mar 19, 2024

Hi, thank you for your bug report! This bug was previously reported and fixed in #2724, but it clearly came back :(

This bug is likely in apply-refact and consequentially in ghc-exactprint. Can we verify this happens in hlint on the cli, without HLS?

@jhrcek
Copy link
Collaborator

jhrcek commented Mar 19, 2024

I confirm I can reproduce the issue with the latest versions of apply-refact + latest hlint.
I saw ghc-exactprint 1.6.1.3 being used when installing apply-refact (as I installed hlint + apply-refact with ghc 9.4.8).

Indeed the shebang is removed as you can see in the steps below.

$ refactor --version
v0.14.0.0
$ hlint --version
HLint v3.8, (C) Neil Mitchell 2006-2024
$ cat Script.hs 
#!/usr/bin/env cabal

{- cabal:
default-language: GHC2021

build-depends:
    base ^>=4.17.0.0,
-}

main :: IO ()
main = print $ fmap (\x -> x + 1) [1,2,3]

$ hlint Script.hs 
Script.hs:11:21-33: Suggestion: Avoid lambda using `infix`
Found:
  (\ x -> x + 1)
Perhaps:
  (+ 1)

1 hint
$ hlint Script.hs --refactor --refactor-options="--inplace"
$ cat Script.hs 


{- cabal:
default-language: GHC2021

build-depends:
    base ^>=4.17.0.0,
-}

main :: IO ()
main = print $ fmap (+ 1) [1,2,3]

@michaelpj
Copy link
Collaborator

This is an upstream bug, it sounds like?

@michaelpj michaelpj added status: blocked Not actionable, because blocked by upstream/GHC etc. and removed status: needs triage labels Mar 19, 2024
@jhrcek
Copy link
Collaborator

jhrcek commented Mar 19, 2024

Found this mpickering/apply-refact#140
so even though the issue might have been fixed in ghc-exactprint, it seems to be still present in apply-refact..?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: blocked Not actionable, because blocked by upstream/GHC etc. type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

4 participants