Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 1a58d5c

Browse files
authored
Merge pull request #1152 from anton-dessiatov/temp-pattern-synonyms
Support for Pattern Synonyms
2 parents b875e8d + 42dd578 commit 1a58d5c

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

src/Haskell/Ide/Engine/Plugin/GhcMod.hs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,21 +681,30 @@ symbolProvider uri = pluginGetFile "ghc-mod symbolProvider: " uri $
681681
goValD (L l (PatBind { pat_lhs = p })) =
682682
map (\n -> Decl LSP.SkVariable n [] l) $ hsNamessRdr p
683683

684+
#if __GLASGOW_HASKELL__ >= 806
685+
goValD (L l (PatSynBind _ idR)) = case idR of
686+
XPatSynBind _ -> error "xPatSynBind"
687+
PSB { psb_id = ln } ->
688+
#else
689+
goValD (L l (PatSynBind (PSB { psb_id = ln }))) =
690+
#endif
691+
-- We are reporting pattern synonyms as functions. There is no such
692+
-- thing as pattern synonym in current LSP specification so we pick up
693+
-- an (arguably) closest match.
694+
pure (Decl LSP.SkFunction ln [] l)
695+
684696
#if __GLASGOW_HASKELL__ >= 806
685697
goValD (L _ (FunBind _ _ (XMatchGroup _) _ _)) = error "goValD"
686698
goValD (L _ (VarBind _ _ _ _)) = error "goValD"
687699
goValD (L _ (AbsBinds _ _ _ _ _ _ _)) = error "goValD"
688-
goValD (L _ (PatSynBind _ _)) = error "goValD"
689700
goValD (L _ (XHsBindsLR _)) = error "goValD"
690701
#elif __GLASGOW_HASKELL__ >= 804
691702
goValD (L _ (VarBind _ _ _)) = error "goValD"
692703
goValD (L _ (AbsBinds _ _ _ _ _ _)) = error "goValD"
693-
goValD (L _ (PatSynBind _)) = error "goValD"
694704
#else
695705
goValD (L _ (VarBind _ _ _)) = error "goValD"
696706
goValD (L _ (AbsBinds _ _ _ _ _)) = error "goValD"
697707
goValD (L _ (AbsBindsSig _ _ _ _ _ _)) = error "goValD"
698-
goValD (L _ (PatSynBind _)) = error "goValD"
699708
#endif
700709

701710
-- -----------------------------

test/functional/SymbolsSpec.hs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ spec :: Spec
1212
spec = describe "document symbols" $ do
1313

1414
-- Some common ranges and selection ranges in Symbols.hs
15-
let fooSR = Range (Position 4 0) (Position 4 3)
16-
fooR = Range (Position 4 0) (Position 6 43)
17-
barSR = Range (Position 5 8) (Position 5 11)
18-
barR = Range (Position 5 8) (Position 6 43)
19-
dogSR = Range (Position 6 17) (Position 6 20)
20-
dogR = Range (Position 6 16) (Position 6 43)
21-
catSR = Range (Position 6 22) (Position 6 25)
22-
catR = Range (Position 6 16) (Position 6 43)
23-
myDataSR = Range (Position 8 5) (Position 8 11)
24-
myDataR = Range (Position 8 0) (Position 9 22)
25-
aSR = Range (Position 8 14) (Position 8 15)
26-
aR = Range (Position 8 14) (Position 8 19)
27-
bSR = Range (Position 9 14) (Position 9 15)
28-
bR = Range (Position 9 14) (Position 9 22)
15+
let fooSR = Range (Position 5 0) (Position 5 3)
16+
fooR = Range (Position 5 0) (Position 7 43)
17+
barSR = Range (Position 6 8) (Position 6 11)
18+
barR = Range (Position 6 8) (Position 7 43)
19+
dogSR = Range (Position 7 17) (Position 7 20)
20+
dogR = Range (Position 7 16) (Position 7 43)
21+
catSR = Range (Position 7 22) (Position 7 25)
22+
catR = Range (Position 7 16) (Position 7 43)
23+
myDataSR = Range (Position 9 5) (Position 9 11)
24+
myDataR = Range (Position 9 0) (Position 10 22)
25+
aSR = Range (Position 9 14) (Position 9 15)
26+
aR = Range (Position 9 14) (Position 9 19)
27+
bSR = Range (Position 10 14) (Position 10 15)
28+
bR = Range (Position 10 14) (Position 10 22)
29+
testPatternSR = Range (Position 13 8) (Position 13 19)
30+
testPatternR = Range (Position 13 0) (Position 13 27)
2931

3032
describe "3.10 hierarchical document symbols" $ do
3133
it "provides nested data types and constructors" $ runSession hieCommand fullCaps "test/testdata" $ do
@@ -48,6 +50,14 @@ spec = describe "document symbols" $ do
4850
cat = DocumentSymbol "cat" (Just "") SkVariable Nothing catR catSR (Just mempty)
4951

5052
liftIO $ symbs `shouldContain` [foo]
53+
it "provides pattern synonyms" $ runSession hieCommand fullCaps "test/testdata" $ do
54+
doc <- openDoc "Symbols.hs" "haskell"
55+
Left symbs <- getDocumentSymbols doc
56+
57+
let testPattern = DocumentSymbol "TestPattern"
58+
(Just "") SkFunction Nothing testPatternR testPatternSR (Just mempty)
59+
60+
liftIO $ symbs `shouldContain` [testPattern]
5161

5262
-- TODO: Test module, imports
5363

test/testdata/Symbols.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE PatternSynonyms #-}
12
module Symbols where
23

34
import Data.Maybe
@@ -8,3 +9,6 @@ foo = bar
89

910
data MyData = A Int
1011
| B String
12+
13+
pattern TestPattern :: Int -> MyData
14+
pattern TestPattern x = A x

0 commit comments

Comments
 (0)