Skip to content

Fix extension pragma inserted below ghc options pragma #2364 #2392

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

Merged
merged 25 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
23f49cf
new parser for stuff before first declaration
eddiemundo Nov 23, 2021
43cae29
Merge branch 'fix-pragma-inserts' of https://github.com/eddiemundo/ha…
eddiemundo Nov 23, 2021
beb43c8
remove unused pragmas, modify haddock comment on parser
eddiemundo Nov 23, 2021
64c3824
Merge branch 'master' into fix-pragma-inserts
eddiemundo Nov 23, 2021
7ba4e1e
Merge branch 'master' into fix-pragma-inserts
eddiemundo Nov 24, 2021
2a0c61f
working but need to clean lots of little things and add more tests
eddiemundo Nov 26, 2021
c4f5d05
Merge branch 'haskell:master' into fix-pragma-inserts
eddiemundo Nov 26, 2021
a4fcfff
Merge branch 'fix-pragma-inserts' of https://github.com/eddiemundo/ha…
eddiemundo Nov 26, 2021
f77c544
uncomment completions functions and tests (was trying to see why the …
eddiemundo Nov 27, 2021
40f049a
add line splitting tests, fix line splitting errors and among other t…
eddiemundo Nov 27, 2021
554071c
change comments, add cpp for setting use_pos_prags bit in PState
eddiemundo Nov 28, 2021
20ef6cd
add safeImportsOn to compat, fix ghc versions
eddiemundo Nov 29, 2021
bd2f998
fix compat
eddiemundo Nov 29, 2021
9e4ca0e
fix compat
eddiemundo Nov 29, 2021
1d2400a
fix compat 3
eddiemundo Nov 29, 2021
3946d09
fix compat 4
eddiemundo Nov 29, 2021
d1f75fa
fix compat 5
eddiemundo Nov 29, 2021
66eadad
fix test
eddiemundo Nov 29, 2021
2a78641
fix compat 6
eddiemundo Nov 29, 2021
4475e77
Merge branch 'fix-pragma-inserts' of https://github.com/eddiemundo/ha…
eddiemundo Nov 29, 2021
21c55c9
add back some tests and investigate #2375 later
eddiemundo Nov 29, 2021
1c3a53c
Merge branch 'master' into fix-pragma-inserts
jneira Nov 29, 2021
43e0e67
Merge branch 'master' into fix-pragma-inserts
eddiemundo Nov 29, 2021
c93f3ee
Merge branch 'master' into fix-pragma-inserts
eddiemundo Nov 29, 2021
85eff89
Merge branch 'master' into fix-pragma-inserts
jneira Nov 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ghcide/src/Development/IDE/GHC/Compat/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Development.IDE.GHC.Compat.Env (
-- * DynFlags Helper
setBytecodeLinkerOptions,
setInterpreterLinkerOptions,
Development.IDE.GHC.Compat.Env.safeImportsOn,
-- * Ways
Ways,
Way,
Expand Down Expand Up @@ -178,6 +179,13 @@ homeUnitId_ =
thisPackage
#endif

safeImportsOn :: DynFlags -> Bool
safeImportsOn =
#if MIN_VERSION_ghc(9,2,0)
Session.safeImportsOn
#else
DynFlags.safeImportsOn
#endif

#if MIN_VERSION_ghc(9,0,0) && !MIN_VERSION_ghc(9,2,0)
type HomeUnit = Unit
Expand Down
4 changes: 4 additions & 0 deletions ghcide/src/Development/IDE/GHC/Compat/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module Development.IDE.GHC.Compat.Parser (
Anno.ApiAnns(..),
#else
ApiAnns,
#endif
#if MIN_VERSION_ghc(9,0,0)
PsSpan(..),
#endif
mkHsParsedModule,
mkParsedModule,
Expand All @@ -24,6 +27,7 @@ module Development.IDE.GHC.Compat.Parser (

#if MIN_VERSION_ghc(9,0,0)
import qualified GHC.Parser.Lexer as Lexer
import GHC.Types.SrcLoc (PsSpan (..))
#if MIN_VERSION_ghc(9,2,0)
import qualified GHC.Driver.Config as Config
import GHC.Parser.Lexer hiding (initParserState)
Expand Down
2 changes: 2 additions & 0 deletions ghcide/src/Development/IDE/GHC/Compat/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ module Development.IDE.GHC.Compat.Util (
StringBuffer(..),
hGetStringBuffer,
stringToStringBuffer,
nextChar,
atEnd
) where

#if MIN_VERSION_ghc(9,0,0)
Expand Down
2 changes: 2 additions & 0 deletions plugins/hls-pragmas-plugin/hls-pragmas-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ library
, base >=4.12 && <5
, extra
, fuzzy
, ghc
, ghcide >=1.2 && <1.6
, hls-plugin-api >=1.1 && <1.3
, lens
, lsp
, text
, transformers
, unordered-containers
, containers

default-language: Haskell2010

Expand Down
540 changes: 479 additions & 61 deletions plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions plugins/hls-pragmas-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,24 @@ tests =
codeActionTests :: TestTree
codeActionTests =
testGroup "code actions"
[ codeActionTest "adds LANGUAGE with no other pragmas at start ignoring later INLINE pragma" "AddPragmaIgnoreInline" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "adds LANGUAGE after shebang preceded by other LANGUAGE and GHC_OPTIONS" "AddPragmaAfterShebangPrecededByLangAndOptsGhc" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "adds LANGUAGE after shebang with other Language preceding shebang" "AddPragmaAfterShebangPrecededByLangAndOptsGhc" [("Add \"TupleSections\"", "Contains TupleSections code action")]
[
codeActionTest "Block comment then line comment doesn't split line" "BlockCommentThenLineComment" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Block comment then single-line block comment doesn't split line" "BlockCommentThenSingleLineBlockComment" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Block comment then multi-line block comment doesn't split line" "BlockCommentThenMultiLineBlockComment" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Block comment then line haddock splits line" "BlockCommentThenLineHaddock" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Block comment then single-line block haddock splits line" "BlockCommentThenSingleLineBlockHaddock" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Block comment then multi-line block haddock splits line" "BlockCommentThenMultiLineBlockHaddock" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Pragma then line comment doesn't split line" "PragmaThenLineComment" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Pragma then single-line block comment doesn't split line" "PragmaThenSingleLineBlockComment" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Pragma then multi-line block comment splits line" "PragmaThenMultiLineBlockComment" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Pragma then line haddock splits line" "PragmaThenLineHaddock" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Pragma then single-line block haddock splits line" "PragmaThenSingleLineBlockHaddock" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Pragma then multi-line block haddock splits line" "PragmaThenMultiLineBlockHaddock" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Pragma then single-line block haddock single-line block comment splits line" "PragmaThenSingleLineBlockHaddockSingleLineBlockComment" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Block comment then single-line block haddock single-line block comment splits line" "BlockCommentThenSingleLineBlockHaddockSingleLineBlockComment" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Pragma then line haddock then newline line comment splits line" "PragmaThenLineHaddockNewlineLineComment" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "does not add pragma after OPTIONS_GHC pragma located after a declaration" "OptionsGhcAfterDecl" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "adds LANGUAGE with no other pragmas at start ignoring later INLINE pragma" "AddPragmaIgnoreInline" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "adds LANGUAGE before Doc comments after interchanging pragmas" "BeforeDocInterchanging" [("Add \"NamedFieldPuns\"", "Contains NamedFieldPuns code action")]
, codeActionTest "Add language after altering OPTIONS_GHC and Language" "AddLanguagePragmaAfterInterchaningOptsGhcAndLangs" [("Add \"TupleSections\"", "Contains TupleSections code action")]
, codeActionTest "Add language after pragmas with non standard space between prefix and name" "AddPragmaWithNonStandardSpacingInPrecedingPragmas" [("Add \"TupleSections\"", "Contains TupleSections code action")]
Expand Down Expand Up @@ -67,7 +82,8 @@ codeActionTest testComment fp actions =
codeActionTests' :: TestTree
codeActionTests' =
testGroup "additional code actions"
[ goldenWithPragmas "no duplication" "NamedFieldPuns" $ \doc -> do
[
goldenWithPragmas "no duplication" "NamedFieldPuns" $ \doc -> do
_ <- waitForDiagnosticsFrom doc
cas <- map fromAction <$> getCodeActions doc (Range (Position 8 9) (Position 8 9))
liftIO $ length cas == 1 @? "Expected one code action, but got: " <> show cas
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{- block comment -} -- line comment
{-# LANGUAGE TupleSections #-}

module BlockCommentThenLineComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{- block comment -} -- line comment

module BlockCommentThenLineComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{- block comment -}
{-# LANGUAGE TupleSections #-}
-- | line haddock

module BlockCommentThenLineHaddock where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{- block comment -} -- | line haddock

module BlockCommentThenLineHaddock where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{- block comment -} {- multi
line
block
comment
-}
{-# LANGUAGE TupleSections #-}

module BlockCommentThenMultiLineBlockComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{- block comment -} {- multi
line
block
comment
-}

module BlockCommentThenMultiLineBlockComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{- block comment -}
{-# LANGUAGE TupleSections #-}
{-| multi
line
block
haddock
-}

module BlockCommentThenMultiLineBlockHaddock where
import GHC.SourceGen (multiIf)
import Diagrams (block)

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{- block comment -} {-| multi
line
block
haddock
-}

module BlockCommentThenMultiLineBlockHaddock where
import GHC.SourceGen (multiIf)
import Diagrams (block)

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{- block comment -} {- single line block comment -}
{-# LANGUAGE TupleSections #-}

module BlockCommentThenSingleLineBlockComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{- block comment -} {- single line block comment -}

module BlockCommentThenSingleLineBlockComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{- block comment -}
{-# LANGUAGE TupleSections #-}
{-| single line block haddock -}

module BlockCommentThenSingleLineBlockHaddock where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{- block comment -} {-| single line block haddock -}

module BlockCommentThenSingleLineBlockHaddock where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{- block comment -}
{-# LANGUAGE TupleSections #-}
{-| single line block haddock -} {- single line block comment -}

module BlockCommentThenSingleLineBlockHaddockSingleLineBlockComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{- block comment -} {-| single line block haddock -} {- single line block comment -}

module BlockCommentThenSingleLineBlockHaddockSingleLineBlockComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{-# LANGUAGE TupleSections #-}
data Something = Something {
foo :: !String,
bar :: !Int
}

tupleSection = (1, ) <$> Just 2

{-# OPTIONS_GHC addOne #-}
addOne :: Int -> Int
addOne x = x + 1
10 changes: 10 additions & 0 deletions plugins/hls-pragmas-plugin/test/testdata/OptionsGhcAfterDecl.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data Something = Something {
foo :: !String,
bar :: !Int
}

tupleSection = (1, ) <$> Just 2

{-# OPTIONS_GHC addOne #-}
addOne :: Int -> Int
addOne x = x + 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE TypeApplications #-} {-| haddock -}

module PragmaFollowedByBlockHaddock where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{-# LANGUAGE TypeApplications #-} -- line comment
{-# LANGUAGE TupleSections #-}

module PragmaThenLineComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE TypeApplications #-} -- line comment

module PragmaThenLineComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TupleSections #-}
-- | line haddock

module PragmaThenLineHaddock where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE TypeApplications #-} -- | line haddock

module PragmaThenLineHaddock where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TupleSections #-}
-- | line haddock
-- line comment

module PragmaThenLineHaddockNewlineLineComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{-# LANGUAGE TypeApplications #-} -- | line haddock
-- line comment

module PragmaThenLineHaddockNewlineLineComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TupleSections #-}
{- multi
line
block
comment
-}

module PragmaThenSingleLineBlockComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{-# LANGUAGE TypeApplications #-} {- multi
line
block
comment
-}

module PragmaThenSingleLineBlockComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TupleSections #-}
{-| multi
line
block
haddock
-}

module PragmaThenMultiLineBlockHaddock where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{-# LANGUAGE TypeApplications #-} {-| multi
line
block
haddock
-}

module PragmaThenMultiLineBlockHaddock where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{-# LANGUAGE TypeApplications #-} {- single line block comment -}
{-# LANGUAGE TupleSections #-}

module PragmaThenSingleLineBlockComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE TypeApplications #-} {- single line block comment -}

module PragmaThenSingleLineBlockComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TupleSections #-}
{-| single line block haddock -}

module PragmaThenSingleLineBlockHaddock where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE TypeApplications #-} {-| single line block haddock -}

module PragmaThenSingleLineBlockHaddock where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TupleSections #-}
{-| single line block haddock -} {- single line block comment -}

module PragmaThenSingleLineBlockHaddockSingleLineBlockComment where

a = (1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE TypeApplications #-} {-| single line block haddock -} {- single line block comment -}

module PragmaThenSingleLineBlockHaddockSingleLineBlockComment where

a = (1,)