Skip to content

Commit 81b26eb

Browse files
authored
Merge branch 'master' into fix-win-cache
2 parents c2851ca + 2e78baa commit 81b26eb

File tree

18 files changed

+110
-47
lines changed

18 files changed

+110
-47
lines changed

haskell-language-server.cabal

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,91 +78,97 @@ library
7878

7979
default-language: Haskell2010
8080

81+
-- Plugin flags are designed for 'cabal install haskell-language-server':
82+
-- - Packaged plugins should be manual:False
83+
-- - Non packaged plugins and bulk flags should be manual:True
84+
-- - Bulk flags should be default:False
85+
-- - Individual flags should be default:True
86+
8187
flag all-plugins
8288
description: Enable all non formatter plugins
83-
default: True
89+
default: False
8490
manual: True
8591

8692
flag all-formatters
8793
description: Enable all fomatters
88-
default: True
94+
default: False
8995
manual: True
9096

9197
flag class
9298
description: Enable class plugin
93-
default: False
94-
manual: True
99+
default: True
100+
manual: False
95101

96102
flag haddockComments
97103
description: Enable haddockComments plugin
98-
default: False
99-
manual: True
104+
default: True
105+
manual: False
100106

101107
flag eval
102108
description: Enable eval plugin
103-
default: False
104-
manual: True
109+
default: True
110+
manual: False
105111

106112
flag importLens
107113
description: Enable importLens plugin
108-
default: False
109-
manual: True
114+
default: True
115+
manual: False
110116

111117
flag retrie
112118
description: Enable retrie plugin
113-
default: False
114-
manual: True
119+
default: True
120+
manual: False
115121

116122
flag tactic
117123
description: Enable tactic plugin
118-
default: False
119-
manual: True
124+
default: True
125+
manual: False
120126

121127
flag hlint
122128
description: Enable hlint plugin
123-
default: False
124-
manual: True
129+
default: True
130+
manual: False
125131

126132
flag moduleName
127133
description: Enable moduleName plugin
128-
default: False
134+
default: True
129135
manual: True
130136

131137
flag pragmas
132138
description: Enable pragmas plugin
133-
default: False
139+
default: True
134140
manual: True
135141

136142
flag splice
137143
description: Enable splice plugin
138-
default: False
139-
manual: True
144+
default: True
145+
manual: False
140146

141147
-- formatters
142148

143149
flag floskell
144150
description: Enable floskell plugin
145-
default: False
151+
default: True
146152
manual: True
147153

148154
flag fourmolu
149155
description: Enable fourmolu plugin
150-
default: False
156+
default: True
151157
manual: True
152158

153159
flag ormolu
154160
description: Enable ormolu plugin
155-
default: False
161+
default: True
156162
manual: True
157163

158164
flag stylishHaskell
159165
description: Enable stylishHaskell plugin
160-
default: False
166+
default: True
161167
manual: True
162168

163169
flag brittany
164170
description: Enable brittany plugin
165-
default: False
171+
default: True
166172
manual: True
167173

168174
common example-plugins

plugins/default/src/Ide/Plugin/Pragmas.hs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ codeActionProvider _ state _plId docId _ (J.CodeActionContext (J.List diags) _mo
6767
let mFile = docId ^. J.uri & uriToFilePath <&> toNormalizedFilePath'
6868
pm <- fmap join $ runAction "addPragma" state $ getParsedModule `traverse` mFile
6969
let dflags = ms_hspp_opts . pm_mod_summary <$> pm
70-
-- Filter diagnostics that are from ghcmod
71-
ghcDiags = filter (\d -> d ^. J.source == Just "typecheck") diags
72-
-- Get all potential Pragmas for all diagnostics.
73-
pragmas = concatMap (\d -> genPragma dflags (d ^. J.message)) ghcDiags
70+
-- Get all potential Pragmas for all diagnostics.
71+
pragmas = concatMap (\d -> genPragma dflags (d ^. J.message)) diags
7472
cmds <- mapM mkCodeAction pragmas
7573
return $ Right $ List cmds
7674
where
@@ -81,13 +79,17 @@ codeActionProvider _ state _plId docId _ (J.CodeActionContext (J.List diags) _mo
8179
edit = mkPragmaEdit (docId ^. J.uri) pragmaName
8280
return codeAction
8381

84-
genPragma mDynflags target
85-
| Just dynFlags <- mDynflags,
86-
-- GHC does not export 'OnOff', so we have to view it as string
87-
disabled <- [ e | Just e <- T.stripPrefix "Off " . T.pack . prettyPrint <$> extensions dynFlags]
88-
= [ r | r <- findPragma target, r `notElem` disabled]
89-
| otherwise = []
90-
82+
genPragma mDynflags target =
83+
[ r | r <- findPragma target, r `notElem` disabled]
84+
where
85+
disabled
86+
| Just dynFlags <- mDynflags
87+
-- GHC does not export 'OnOff', so we have to view it as string
88+
= [ e | Just e <- T.stripPrefix "Off " . T.pack . prettyPrint <$> extensions dynFlags]
89+
| otherwise
90+
-- When the module failed to parse, we don't have access to its
91+
-- dynFlags. In that case, simply don't disable any pragmas.
92+
= []
9193

9294
-- ---------------------------------------------------------------------
9395

plugins/hls-class-plugin/hls-class-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ library
1313
exposed-modules: Ide.Plugin.Class
1414
hs-source-dirs: src
1515
build-depends: aeson
16-
, base
16+
, base >=4.12 && <5
1717
, containers
1818
, haskell-lsp
1919
, hls-plugin-api

plugins/hls-class-plugin/src/Ide/Plugin/Class.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ addMethodPlaceholders lf state AddMinimalMethodsParams{..} = fmap (fromMaybe err
119119

120120
toMethodName n
121121
| Just (h, _) <- T.uncons n
122-
, not (isAlpha h)
122+
, not (isAlpha h || h == '_')
123123
= "(" <> n <> ")"
124124
| otherwise
125125
= n

plugins/hls-eval-plugin/hls-eval-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ library
2525

2626
build-depends:
2727
, aeson
28-
, base
28+
, base >=4.12 && <5
2929
, containers
3030
, deepseq
3131
, Diff

plugins/hls-explicit-imports-plugin/hls-explicit-imports-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ library
1616
exposed-modules: Ide.Plugin.ExplicitImports
1717
hs-source-dirs: src
1818
build-depends: aeson
19-
, base
19+
, base >=4.12 && <5
2020
, containers
2121
, deepseq
2222
, haskell-lsp-types

plugins/hls-haddock-comments-plugin/hls-haddock-comments-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ library
1818
hs-source-dirs: src
1919
ghc-options: -Wall -Wno-name-shadowing -Wredundant-constraints
2020
build-depends:
21-
, base
21+
, base >=4.12 && <5
2222
, containers
2323
, ghc
2424
, ghc-exactprint

plugins/hls-hlint-plugin/hls-hlint-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ library
2828
build-depends:
2929
, aeson
3030
, apply-refact
31-
, base
31+
, base >=4.12 && <5
3232
, binary
3333
, bytestring
3434
, containers

plugins/hls-retrie-plugin/hls-retrie-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ library
1616
exposed-modules: Ide.Plugin.Retrie
1717
hs-source-dirs: src
1818
build-depends: aeson
19-
, base
19+
, base >=4.12 && <5
2020
, containers
2121
, deepseq
2222
, directory

plugins/hls-splice-plugin/hls-splice-plugin.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ library
1515
other-modules: Ide.Plugin.Splice.Types
1616
hs-source-dirs: src
1717
build-depends: aeson
18-
, base
18+
, base >=4.12 && <5
1919
, containers
2020
, foldl
2121
, haskell-lsp

test/functional/Class.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ tests = testGroup
4848
, glodenTest "Creates a placeholder for multiple methods 2" "T3" "2"
4949
$ \(_:mmAction:_) -> do
5050
executeCodeAction mmAction
51+
, glodenTest "Creates a placeholder for a method starting with '_'" "T4" ""
52+
$ \(_fAction:_) -> do
53+
executeCodeAction _fAction
5154
]
5255

5356
_CACodeAction :: Prism' CAResult CodeAction
@@ -60,14 +63,18 @@ classPath = "test" </> "testdata" </> "class"
6063

6164
glodenTest :: String -> FilePath -> FilePath -> ([CodeAction] -> Session ()) -> TestTree
6265
glodenTest name fp deco execute
63-
= goldenVsStringDiff name goldenGitDiff (classPath </> fp <.> deco <.> "expected" <.> "hs")
66+
= goldenVsStringDiff name goldenGitDiff (classPath </> fpWithDeco <.> "expected" <.> "hs")
6467
$ runSession hlsCommand fullCaps classPath
6568
$ do
6669
doc <- openDoc (fp <.> "hs") "haskell"
6770
_ <- waitForDiagnosticsFromSource doc "typecheck"
6871
actions <- concatMap (^.. _CACodeAction) <$> getAllCodeActions doc
6972
execute actions
7073
BS.fromStrict . T.encodeUtf8 <$> getDocumentEdit doc
74+
where
75+
fpWithDeco
76+
| deco == "" = fp
77+
| otherwise = fp <.> deco
7178

7279
goldenGitDiff :: FilePath -> FilePath -> [String]
7380
goldenGitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew]

test/functional/FunctionalCodeAction.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ missingPragmaTests = testGroup "missing pragma warning code actions" [
425425
contents <- documentContents doc
426426

427427
let expected = [ "{-# LANGUAGE TypeSynonymInstances #-}"
428+
, "module NeedsPragmas where"
428429
, ""
429430
, "import GHC.Generics"
430431
, ""
@@ -443,6 +444,30 @@ missingPragmaTests = testGroup "missing pragma warning code actions" [
443444
]
444445

445446
liftIO $ (T.lines contents) @?= expected
447+
448+
, testCase "Adds TypeApplications pragma" $ do
449+
runSession hlsCommand fullCaps "test/testdata/addPragmas" $ do
450+
doc <- openDoc "TypeApplications.hs" "haskell"
451+
452+
_ <- waitForDiagnosticsFrom doc
453+
cas <- map fromAction <$> getAllCodeActions doc
454+
455+
liftIO $ "Add \"TypeApplications\"" `elem` map (^. L.title) cas @? "Contains TypeApplications code action"
456+
457+
executeCodeAction $ head cas
458+
459+
contents <- documentContents doc
460+
461+
let expected =
462+
[ "{-# LANGUAGE TypeApplications #-}"
463+
, "{-# LANGUAGE ScopedTypeVariables #-}"
464+
, "module TypeApplications where"
465+
, ""
466+
, "foo :: forall a. a -> a"
467+
, "foo = id @a"
468+
]
469+
470+
liftIO $ (T.lines contents) @?= expected
446471
]
447472

448473
unusedTermTests :: TestTree

test/testdata/addPragmas/NeedsPragmas.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
module NeedsPragmas where
12

23
import GHC.Generics
34

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE ScopedTypeVariables #-}
2+
module TypeApplications where
3+
4+
foo :: forall a. a -> a
5+
foo = id @a

test/testdata/addPragmas/hie.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ cradle:
22
direct:
33
arguments:
44
- "NeedsPragmas"
5+
- "TypeApplications"

test/testdata/addPragmas/test.cabal

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ category: Web
1010
build-type: Simple
1111
cabal-version: >=1.10
1212

13-
executable p
14-
main-is: NeedsPragmas.hs
13+
library
14+
exposed-modules: NeedsPragmas
15+
TypeApplications
1516
hs-source-dirs: .
1617
build-depends: base >= 4.7 && < 5
1718
default-language: Haskell2010

test/testdata/class/T4.expected.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module T4 where
2+
3+
class Test a where
4+
_f :: a
5+
{-# MINIMAL _f #-}
6+
7+
instance Test Int where
8+
_f = _

test/testdata/class/T4.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module T4 where
2+
3+
class Test a where
4+
_f :: a
5+
{-# MINIMAL _f #-}
6+
7+
instance Test Int where

0 commit comments

Comments
 (0)