1
1
{-# LANGUAGE OverloadedStrings #-}
2
2
module Symbol (tests ) where
3
3
4
+ import Control.Lens (to , ix , (^?) , _Just )
4
5
import Control.Monad.IO.Class
5
6
import Data.List
6
7
import Language.Haskell.LSP.Test as Test
7
8
import Language.Haskell.LSP.Types
9
+ import qualified Language.Haskell.LSP.Types.Lens as L
8
10
import Language.Haskell.LSP.Types.Capabilities
9
11
import Test.Hls.Util
10
12
import Test.Tasty
@@ -19,69 +21,110 @@ tests = testGroup "document symbols" [
19
21
20
22
v310Tests :: TestTree
21
23
v310Tests = testGroup " 3.10 hierarchical document symbols" [
22
- ignoreTestBecause " Broken " $ testCase " provides nested data types and constructors" $ runSession hlsCommand fullCaps " test/testdata" $ do
24
+ testCase " provides nested data types and constructors" $ runSession hlsCommand fullCaps " test/testdata" $ do
23
25
doc <- openDoc " Symbols.hs" " haskell"
24
26
Left symbs <- getDocumentSymbols doc
25
27
26
- let myData = DocumentSymbol " MyData" (Just " " ) SkClass Nothing myDataR myDataSR (Just (List [a, b]))
27
- a = DocumentSymbol " A" (Just " " ) SkConstructor Nothing aR aSR (Just mempty )
28
- b = DocumentSymbol " B" (Just " " ) SkConstructor Nothing bR bSR (Just mempty )
28
+ let myData = DocumentSymbol " MyData" Nothing SkStruct Nothing myDataR myDataSR (Just (List [a, b]))
29
+ a = DocumentSymbol " A" Nothing SkConstructor Nothing aR aSR Nothing
30
+ b = DocumentSymbol " B" Nothing SkConstructor Nothing bR bSR Nothing
31
+ let myData' = symbs ^? ix 0 . L. children . _Just . to fromList . ix 2
29
32
30
- liftIO $ myData `elem` symbs @? " Contains symbol"
33
+ liftIO $ Just myData == myData' @? " Contains symbol"
31
34
32
- ,ignoreTestBecause " Broken " $ testCase " provides nested where functions" $ runSession hlsCommand fullCaps " test/testdata" $ do
35
+ , ignoreTestBecause " extracting symbols from nested wheres not supported " $ testCase " provides nested where functions" $ runSession hlsCommand fullCaps " test/testdata" $ do
33
36
doc <- openDoc " Symbols.hs" " haskell"
34
37
Left symbs <- getDocumentSymbols doc
35
38
36
- let foo = DocumentSymbol " foo" (Just " " ) SkFunction Nothing fooR fooSR (Just (List [bar]))
37
- bar = DocumentSymbol " bar" (Just " " ) SkFunction Nothing barR barSR (Just (List [dog, cat]))
38
- dog = DocumentSymbol " dog" (Just " " ) SkVariable Nothing dogR dogSR (Just mempty )
39
- cat = DocumentSymbol " cat" (Just " " ) SkVariable Nothing catR catSR (Just mempty )
39
+ let foo = DocumentSymbol " foo" Nothing SkFunction Nothing fooR fooSR (Just (List [bar]))
40
+ bar = DocumentSymbol " bar" Nothing SkFunction Nothing barR barSR (Just (List [dog, cat]))
41
+ dog = DocumentSymbol " dog" Nothing SkVariable Nothing dogR dogSR (Just mempty )
42
+ cat = DocumentSymbol " cat" Nothing SkVariable Nothing catR catSR (Just mempty )
43
+ let foo' = symbs ^? ix 0 . L. children . _Just . to fromList . ix 1
40
44
41
- liftIO $ foo `elem` symbs @? " Contains symbol"
45
+ liftIO $ Just foo == foo' @? " Contains symbol"
42
46
43
- , ignoreTestBecause " Broken " $ testCase " provides pattern synonyms" $ runSession hlsCommand fullCaps " test/testdata" $ do
47
+ , ignoreTestBecause " extracting pattern synonym symbols not supported " $ testCase " provides pattern synonyms" $ runSession hlsCommand fullCaps " test/testdata" $ do
44
48
doc <- openDoc " Symbols.hs" " haskell"
45
49
Left symbs <- getDocumentSymbols doc
46
50
47
51
let testPattern = DocumentSymbol " TestPattern"
48
- (Just " " ) SkFunction Nothing testPatternR testPatternSR (Just mempty )
52
+ Nothing SkFunction Nothing testPatternR testPatternSR (Just mempty )
53
+ let testPattern' = symbs ^? ix 0 . L. children . _Just . to fromList . ix 3
49
54
50
- liftIO $ testPattern `elem` symbs @? " Contains symbol"
51
- ]
55
+ liftIO $ Just testPattern == testPattern' @? " Contains symbol"
52
56
53
- -- TODO: Test module, imports
57
+ , testCase " provides imports" $ runSession hlsCommand fullCaps " test/testdata" $ do
58
+ doc <- openDoc " Symbols.hs" " haskell"
59
+ Left symbs <- getDocumentSymbols doc
60
+
61
+ let imports = DocumentSymbol " imports" Nothing SkModule Nothing importsR importsSR (Just (List [importDataMaybe]))
62
+ importDataMaybe = DocumentSymbol " import Data.Maybe" Nothing SkModule Nothing importDataMaybeR importDataMaybeSR Nothing
63
+ let imports' = symbs ^? ix 0 . L. children . _Just . to fromList . ix 0
64
+
65
+ liftIO $ Just imports == imports' @? " Contains symbol"
66
+ ]
54
67
55
68
pre310Tests :: TestTree
56
69
pre310Tests = testGroup " pre 3.10 symbol information" [
57
- ignoreTestBecause " Broken " $ testCase " provides nested data types and constructors" $ runSession hlsCommand oldCaps " test/testdata" $ do
70
+ testCase " provides nested data types and constructors" $ runSession hlsCommand oldCaps " test/testdata" $ do
58
71
doc@ (TextDocumentIdentifier testUri) <- openDoc " Symbols.hs" " haskell"
59
72
Right symbs <- getDocumentSymbols doc
60
73
61
- let myData = SymbolInformation " MyData" SkClass Nothing (Location testUri myDataR) Nothing
74
+ let myData = SymbolInformation " MyData" SkStruct Nothing (Location testUri myDataR) ( Just " Symbols " )
62
75
a = SymbolInformation " A" SkConstructor Nothing (Location testUri aR) (Just " MyData" )
63
76
b = SymbolInformation " B" SkConstructor Nothing (Location testUri bR) (Just " MyData" )
64
77
65
78
liftIO $ [myData, a, b] `isInfixOf` symbs @? " Contains symbols"
66
79
67
- ,ignoreTestBecause " Broken " $ testCase " provides nested where functions" $ runSession hlsCommand oldCaps " test/testdata" $ do
80
+ , ignoreTestBecause " extracting symbols from nested wheres not supported " $ testCase " provides nested where functions" $ runSession hlsCommand oldCaps " test/testdata" $ do
68
81
doc@ (TextDocumentIdentifier testUri) <- openDoc " Symbols.hs" " haskell"
69
82
Right symbs <- getDocumentSymbols doc
70
83
71
- let foo = SymbolInformation " foo" SkFunction Nothing (Location testUri fooR) Nothing
84
+ let foo = SymbolInformation " foo" SkFunction Nothing (Location testUri fooR) ( Just " Symbols " )
72
85
bar = SymbolInformation " bar" SkFunction Nothing (Location testUri barR) (Just " foo" )
73
86
dog = SymbolInformation " dog" SkVariable Nothing (Location testUri dogR) (Just " bar" )
74
87
cat = SymbolInformation " cat" SkVariable Nothing (Location testUri catR) (Just " bar" )
75
88
76
89
-- Order is important!
77
90
liftIO $ [foo, bar, dog, cat] `isInfixOf` symbs @? " Contains symbols"
91
+
92
+ , ignoreTestBecause " extracting pattern synonym symbols not supported" $ testCase " provides pattern synonyms" $ runSession hlsCommand oldCaps " test/testdata" $ do
93
+ doc@ (TextDocumentIdentifier testUri) <- openDoc " Symbols.hs" " haskell"
94
+ Right symbs <- getDocumentSymbols doc
95
+
96
+ let testPattern = SymbolInformation " TestPattern"
97
+ SkFunction Nothing (Location testUri testPatternR) (Just " Symbols" )
98
+
99
+ liftIO $ testPattern `elem` symbs @? " Contains symbols"
100
+
101
+ , testCase " provides imports" $ runSession hlsCommand oldCaps " test/testdata" $ do
102
+ doc@ (TextDocumentIdentifier testUri) <- openDoc " Symbols.hs" " haskell"
103
+ Right symbs <- getDocumentSymbols doc
104
+
105
+ let imports = SymbolInformation " imports" SkModule Nothing (Location testUri importsR) (Just " Symbols" )
106
+ importDataMaybe = SymbolInformation " import Data.Maybe" SkModule Nothing (Location testUri importDataMaybeR) (Just " imports" )
107
+
108
+ liftIO $ [imports, importDataMaybe] `isInfixOf` symbs @? " Contains symbol"
78
109
]
79
110
80
111
oldCaps :: ClientCapabilities
81
112
oldCaps = capsForVersion (LSPVersion 3 9 )
113
+
114
+ fromList :: List a -> [a ]
115
+ fromList (List a) = a
116
+
82
117
-- Some common ranges and selection ranges in Symbols.hs
118
+ importsR :: Range
119
+ importsR = Range (Position 3 0 ) (Position 3 17 )
120
+ importsSR :: Range
121
+ importsSR = Range (Position 3 0 ) (Position 3 17 )
122
+ importDataMaybeR :: Range
123
+ importDataMaybeR = Range (Position 3 0 ) (Position 3 17 )
124
+ importDataMaybeSR :: Range
125
+ importDataMaybeSR = Range (Position 3 0 ) (Position 3 17 )
83
126
fooSR :: Range
84
- fooSR = Range (Position 5 0 ) (Position 5 3 )
127
+ fooSR = Range (Position 5 0 ) (Position 7 43 )
85
128
fooR :: Range
86
129
fooR = Range (Position 5 0 ) (Position 7 43 )
87
130
barSR :: Range
@@ -97,7 +140,7 @@ catSR = Range (Position 7 22) (Position 7 25)
97
140
catR :: Range
98
141
catR = Range (Position 7 16 ) (Position 7 43 )
99
142
myDataSR :: Range
100
- myDataSR = Range (Position 9 5 ) (Position 9 11 )
143
+ myDataSR = Range (Position 9 0 ) (Position 10 22 )
101
144
myDataR :: Range
102
145
myDataR = Range (Position 9 0 ) (Position 10 22 )
103
146
aSR :: Range
0 commit comments