HLS deletes shebang line
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]
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]
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?
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]
This is an upstream bug, it sounds like?
Found this https://github.com/mpickering/apply-refact/issues/140 so even though the issue might have been fixed in ghc-exactprint, it seems to be still present in apply-refact..?