Skip to content

Commit 28e8a2b

Browse files
Merge branch 'master' into harder_hlint_fixes
2 parents 07a0123 + 50854ca commit 28e8a2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+98
-41
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ packages:
44
./shake-bench
55
./ghcide
66
./hls-plugin-api
7-
./plugins/tactics
7+
./plugins/hls-tactics-plugin
88
./plugins/hls-class-plugin
99
./plugins/hls-eval-plugin
1010
./plugins/hls-explicit-imports-plugin

haskell-language-server.cabal

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ description:
88

99
homepage: https://github.com/haskell/haskell-language-server#readme
1010
bug-reports: https://github.com/haskell/haskell-language-server/issues
11-
author: Alan Zimmerman
11+
author: The Haskell IDE Team
1212
maintainer: [email protected]
13-
copyright: Alan Zimmerman
13+
copyright: The Haskell IDE Team
1414
license: Apache-2.0
1515
license-file: LICENSE
16+
category: Development
1617
build-type: Simple
1718
tested-with: GHC == 8.6.4 || == 8.6.5 || == 8.8.2 || == 8.8.3 || == 8.8.4 || == 8.10.1 || == 8.10.2 || == 8.10.3
1819
extra-source-files:
@@ -413,7 +414,7 @@ test-suite func-test
413414
, tasty-rerun
414415
, ghcide
415416

416-
hs-source-dirs: test/functional plugins/tactics/src plugins/hls-eval-plugin/test plugins/hls-splice-plugin/src
417+
hs-source-dirs: test/functional plugins/hls-tactics-plugin/src plugins/hls-eval-plugin/test plugins/hls-splice-plugin/src
417418

418419
main-is: Main.hs
419420
other-modules:

hls-plugin-api/hls-plugin-api.cabal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ homepage: https://github.com/haskell/haskell-language-server/hls-plugin-api
88
bug-reports: https://github.com/haskell/haskell-language-server/issues
99
license: Apache-2.0
1010
license-file: LICENSE
11-
author: Many,TBD when we release
12-
maintainer: [email protected] (for now)
13-
copyright: Alan Zimmerman
14-
category: Web
11+
author: The Haskell IDE Team
12+
maintainer: [email protected]
13+
copyright: The Haskell IDE Team
14+
category: Development
1515
build-type: Simple
1616

1717
flag pedantic

nix/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let
2727
hls-hlint-plugin = gitignoreSource ../plugins/hls-hlint-plugin;
2828
hls-retrie-plugin = gitignoreSource ../plugins/hls-retrie-plugin;
2929
hls-splice-plugin = gitignoreSource ../plugins/hls-splice-plugin;
30-
hls-tactics-plugin = gitignoreSource ../plugins/tactics;
30+
hls-tactics-plugin = gitignoreSource ../plugins/hls-tactics-plugin;
3131
});
3232
in
3333
{

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,26 @@ findPragma str = concatMap check possiblePragmas
100100
where
101101
check p = [p | T.isInfixOf p str]
102102

103+
-- We exclude the Strict extension as it causes many false positives, see
104+
-- the discussion at https://github.com/haskell/ghcide/pull/638
105+
--
106+
-- We don't include the No- variants, as GHC never suggests disabling an
107+
-- extension in an error message.
108+
possiblePragmas :: [T.Text]
109+
possiblePragmas =
110+
[ name
111+
| FlagSpec{flagSpecName = T.pack -> name} <- xFlags
112+
, "Strict" /= name
113+
]
114+
103115
-- ---------------------------------------------------------------------
104116

105-
-- | Possible Pragma names.
106-
-- See discussion at https://github.com/haskell/ghcide/pull/638
107-
possiblePragmas :: [T.Text]
108-
possiblePragmas = [name | FlagSpec{flagSpecName = T.pack -> name} <- xFlags, "Strict" /= name]
117+
-- | All language pragmas, including the No- variants
118+
allPragmas :: [T.Text]
119+
allPragmas = concat
120+
[ [name, "No" <> name]
121+
| FlagSpec{flagSpecName = T.pack -> name} <- xFlags
122+
]
109123

110124
-- ---------------------------------------------------------------------
111125

@@ -121,7 +135,7 @@ completion lspFuncs _ide complParams = do
121135
where
122136
result (Just pfix)
123137
| "{-# LANGUAGE" `T.isPrefixOf` VFS.fullLine pfix
124-
= Completions $ List $ map buildCompletion possiblePragmas
138+
= Completions $ List $ map buildCompletion allPragmas
125139
| otherwise
126140
= Completions $ List []
127141
result Nothing = Completions $ List []

plugins/hls-haddock-comments-plugin/src/Ide/Plugin/HaddockComments.hs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
{-# LANGUAGE ExistentialQuantification #-}
2+
{-# LANGUAGE FlexibleContexts #-}
23
{-# LANGUAGE NamedFieldPuns #-}
34
{-# LANGUAGE OverloadedStrings #-}
45
{-# LANGUAGE RecordWildCards #-}
56
{-# LANGUAGE ViewPatterns #-}
67

7-
module Ide.Plugin.HaddockComments where
8+
module Ide.Plugin.HaddockComments (descriptor) where
89

910
import Control.Monad (join)
1011
import qualified Data.HashMap.Strict as HashMap
1112
import qualified Data.Map as Map
1213
import qualified Data.Text as T
1314
import Development.IDE
1415
import Development.IDE.GHC.Compat
16+
import Development.IDE.GHC.ExactPrint (GetAnnotatedParsedSource (..), annsA, astA)
1517
import Ide.Types
1618
import Language.Haskell.GHC.ExactPrint
1719
import Language.Haskell.GHC.ExactPrint.Types hiding (GhcPs)
@@ -25,17 +27,14 @@ descriptor plId =
2527
{ pluginCodeActionProvider = Just codeActionProvider
2628
}
2729

28-
haddockCommentsId :: CommandId
29-
haddockCommentsId = "HaddockCommentsCommand"
30-
3130
codeActionProvider :: CodeActionProvider IdeState
3231
codeActionProvider _lspFuncs ideState _pId (TextDocumentIdentifier uri) range CodeActionContext {_diagnostics = List diags} =
3332
do
3433
let noErr = and $ (/= Just DsError) . _severity <$> diags
3534
nfp = uriToNormalizedFilePath $ toNormalizedUri uri
36-
(join -> pm) <- runAction "HaddockComments.GetParsedModule" ideState $ use GetParsedModule `traverse` nfp
37-
let locDecls = hsmodDecls . unLoc . pm_parsed_source <$> pm
38-
anns = relativiseApiAnns <$> (pm_parsed_source <$> pm) <*> (pm_annotations <$> pm)
35+
(join -> pm) <- runAction "HaddockComments.GetAnnotatedParsedSource" ideState $ use GetAnnotatedParsedSource `traverse` nfp
36+
let locDecls = hsmodDecls . unLoc . astA <$> pm
37+
anns = annsA <$> pm
3938
edits = [runGenComments gen locDecls anns range | noErr, gen <- genList]
4039
return $ Right $ List [CACodeAction $ toAction title uri edit | (Just (title, edit)) <- edits]
4140

@@ -46,13 +45,16 @@ genList =
4645
]
4746

4847
-----------------------------------------------------------------------------
48+
49+
-- | Defines how to generate haddock comments by tweaking annotations of AST
4950
data GenComments = forall a.
5051
GenComments
5152
{ title :: T.Text,
5253
fromDecl :: HsDecl GhcPs -> Maybe a,
5354
collectKeys :: a -> [AnnKey],
5455
isFresh :: Annotation -> Bool,
55-
updateAnn :: Annotation -> Annotation
56+
updateAnn :: Annotation -> Annotation,
57+
updateDeclAnn :: Annotation -> Annotation
5658
}
5759

5860
runGenComments :: GenComments -> Maybe [LHsDecl GhcPs] -> Maybe Anns -> Range -> Maybe (T.Text, TextEdit)
@@ -63,7 +65,8 @@ runGenComments GenComments {..} mLocDecls mAnns range
6365
annKeys <- collectKeys x,
6466
not $ null annKeys,
6567
and $ maybe False isFresh . flip Map.lookup anns <$> annKeys,
66-
anns' <- foldr (Map.adjust updateAnn) anns annKeys,
68+
declKey <- mkAnnKey locDecl,
69+
anns' <- Map.adjust updateDeclAnn declKey $ foldr (Map.adjust updateAnn) anns annKeys,
6770
Just range' <- toRange src,
6871
result <- T.strip . T.pack $ exactPrint locDecl anns' =
6972
Just (title, TextEdit range' result)
@@ -80,9 +83,9 @@ genForSig = GenComments {..}
8083
fromDecl _ = Nothing
8184

8285
updateAnn x = x {annEntryDelta = DP (0, 1), annsDP = dp}
86+
updateDeclAnn = cleanPriorComments
8387

8488
isFresh Ann {annsDP} = null [() | (AnnComment _, _) <- annsDP]
85-
8689
collectKeys = keyFromTyVar 0
8790

8891
comment = mkComment "-- ^ " noSrcSpan
@@ -98,6 +101,7 @@ genForRecord = GenComments {..}
98101
fromDecl _ = Nothing
99102

100103
updateAnn x = x {annEntryDelta = DP (1, 2), annPriorComments = [(comment, DP (1, 2))]}
104+
updateDeclAnn = cleanPriorComments
101105

102106
isFresh Ann {annPriorComments} = null annPriorComments
103107

@@ -120,14 +124,18 @@ toAction title uri edit = CodeAction {..}
120124

121125
toRange :: SrcSpan -> Maybe Range
122126
toRange src
123-
| (RealSrcSpan span) <- src,
124-
range' <- realSrcSpanToRange span =
127+
| (RealSrcSpan s) <- src,
128+
range' <- realSrcSpanToRange s =
125129
Just range'
126130
| otherwise = Nothing
127131

128132
isIntersectWith :: Range -> SrcSpan -> Bool
129133
isIntersectWith Range {_start, _end} x = isInsideSrcSpan _start x || isInsideSrcSpan _end x
130134

135+
-- clean prior comments, since src span we get from 'LHsDecl' does not include them
136+
cleanPriorComments :: Annotation -> Annotation
137+
cleanPriorComments x = x {annPriorComments = []}
138+
131139
-----------------------------------------------------------------------------
132140

133141
keyFromTyVar :: Int -> LHsType GhcPs -> [AnnKey]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ synopsis: Hlint integration plugin with Haskell Language Server
55
description: Please see Haskell Language Server Readme (https://github.com/haskell/haskell-language-server#readme)
66
license: Apache-2.0
77
license-file: LICENSE
8-
author: https://github.com/haskell/haskell-language-server/contributors
9-
maintainer: https://github.com/haskell/haskell-language-server/contributors
10-
copyright: Alan Zimmerman
11-
category: Web
8+
author: The Haskell IDE Team
9+
maintainer: alan.zimm@gmail.com
10+
copyright: The Haskell IDE Team
11+
category: Development
1212
build-type: Simple
1313

1414
flag pedantic

stack-8.10.1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ packages:
1313
- ./plugins/hls-hlint-plugin
1414
- ./plugins/hls-retrie-plugin
1515
- ./plugins/hls-splice-plugin
16-
- ./plugins/tactics
16+
- ./plugins/hls-tactics-plugin
1717

1818
ghc-options:
1919
"$everything": -haddock

stack-8.10.2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ packages:
1313
- ./plugins/hls-hlint-plugin
1414
- ./plugins/hls-retrie-plugin
1515
- ./plugins/hls-splice-plugin
16-
- ./plugins/tactics
16+
- ./plugins/hls-tactics-plugin
1717

1818
ghc-options:
1919
"$everything": -haddock

stack-8.10.3.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ packages:
1313
- ./plugins/hls-hlint-plugin
1414
- ./plugins/hls-retrie-plugin
1515
- ./plugins/hls-splice-plugin
16-
- ./plugins/tactics
16+
- ./plugins/hls-tactics-plugin
1717

1818
ghc-options:
1919
"$everything": -haddock

stack-8.6.4.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ packages:
1414
- ./plugins/hls-hlint-plugin
1515
- ./plugins/hls-retrie-plugin
1616
- ./plugins/hls-splice-plugin
17-
- ./plugins/tactics
17+
- ./plugins/hls-tactics-plugin
1818

1919
ghc-options:
2020
"$everything": -haddock

stack-8.6.5.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ packages:
1313
- ./plugins/hls-hlint-plugin
1414
- ./plugins/hls-retrie-plugin
1515
- ./plugins/hls-splice-plugin
16-
- ./plugins/tactics
16+
- ./plugins/hls-tactics-plugin
1717

1818
ghc-options:
1919
"$everything": -haddock

stack-8.8.2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ packages:
1313
- ./plugins/hls-hlint-plugin
1414
- ./plugins/hls-retrie-plugin
1515
- ./plugins/hls-splice-plugin
16-
- ./plugins/tactics
16+
- ./plugins/hls-tactics-plugin
1717

1818
ghc-options:
1919
"$everything": -haddock

stack-8.8.3.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ packages:
1313
- ./plugins/hls-hlint-plugin
1414
- ./plugins/hls-retrie-plugin
1515
- ./plugins/hls-splice-plugin
16-
- ./plugins/tactics
16+
- ./plugins/hls-tactics-plugin
1717

1818
ghc-options:
1919
"$everything": -haddock

stack-8.8.4.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ packages:
1313
- ./plugins/hls-hlint-plugin
1414
- ./plugins/hls-retrie-plugin
1515
- ./plugins/hls-splice-plugin
16-
- ./plugins/tactics
16+
- ./plugins/hls-tactics-plugin
1717

1818
ghc-options:
1919
"$everything": -haddock

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ packages:
1313
- ./plugins/hls-hlint-plugin
1414
- ./plugins/hls-retrie-plugin
1515
- ./plugins/hls-splice-plugin
16-
- ./plugins/tactics
16+
- ./plugins/hls-tactics-plugin
1717

1818
ghc-options:
1919
"$everything": -haddock

test/functional/Completion.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ tests = testGroup "completions" [
9494
item ^. label @?= "OverloadedStrings"
9595
item ^. kind @?= Just CiKeyword
9696

97+
, testCase "completes the Strict language extension" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
98+
doc <- openDoc "Completion.hs" "haskell"
99+
100+
_ <- waitForDiagnostics
101+
102+
let te = TextEdit (Range (Position 0 13) (Position 0 31)) "Str"
103+
_ <- applyEdit doc te
104+
105+
compls <- getCompletions doc (Position 0 24)
106+
let item = head $ filter ((== "Strict") . (^. label)) compls
107+
liftIO $ do
108+
item ^. label @?= "Strict"
109+
item ^. kind @?= Just CiKeyword
110+
111+
, testCase "completes No- language extensions" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
112+
doc <- openDoc "Completion.hs" "haskell"
113+
114+
_ <- waitForDiagnostics
115+
116+
let te = TextEdit (Range (Position 0 13) (Position 0 31)) "NoOverload"
117+
_ <- applyEdit doc te
118+
119+
compls <- getCompletions doc (Position 0 24)
120+
let item = head $ filter ((== "NoOverloadedStrings") . (^. label)) compls
121+
liftIO $ do
122+
item ^. label @?= "NoOverloadedStrings"
123+
item ^. kind @?= Just CiKeyword
124+
97125
, testCase "completes pragmas" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
98126
doc <- openDoc "Completion.hs" "haskell"
99127

test/functional/HaddockComments.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tests =
2828
"haddock comments"
2929
[ goldenTest "HigherRankFunction" Signature 4 6,
3030
goldenTest "KindSigFunction" Signature 9 10,
31-
goldenTest "MultivariateFunction" Signature 2 8,
31+
goldenTest "MultivariateFunction" Signature 4 8,
3232
goldenTest "QualFunction" Signature 2 10,
3333
goldenTest "Record" Record 7 2,
3434
expectedNothing "ConstFunction" Signature 2 2,
@@ -37,7 +37,7 @@ tests =
3737
]
3838

3939
goldenTest :: FilePath -> GenCommentsType -> Int -> Int -> TestTree
40-
goldenTest fp (toTitle -> expectedTitle) l c = goldenVsStringDiff fp goldenGitDiff goldenFilePath $
40+
goldenTest fp (toTitle -> expectedTitle) l c = goldenVsStringDiff (fp <> " (golden)") goldenGitDiff goldenFilePath $
4141
runSession hlsCommand fullCaps haddockCommentsPath $ do
4242
doc <- openDoc hsFilePath "haskell"
4343
_ <- waitForDiagnostics

test/testdata/haddockComments/MultivariateFunction.expected.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module MultivariateFunction where
22

3+
-- | some
4+
-- docs
35
f :: a -- ^
46
-> b -- ^
57
-> c -- ^
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module MultivariateFunction where
22

3+
-- | some
4+
-- docs
35
f :: a -> b -> c -> d -> e -> f -> g -> g
46
f _ _ _ _ _ _ x = x

test/testdata/haddockComments/Record.expected.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Record where
22

3+
-- | A record
34
data Record a b c d e f
45
= RecordA
56
{

test/testdata/haddockComments/Record.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Record where
22

3+
-- | A record
34
data Record a b c d e f
45
= RecordA
56
{ a :: a,

0 commit comments

Comments
 (0)