@@ -15,12 +15,16 @@ import Control.Monad.IO.Class
15
15
import Data.Maybe
16
16
import Data.Text qualified as T
17
17
import Data.Text.Encoding (decodeASCII , decodeLatin1 )
18
- import Debug.Trace as Debug
19
18
import Development.IDE.Core.Rules
20
19
import Development.IDE.Core.Shake (IdeState (shakeExtras ), runIdeAction , useWithStaleFast )
21
20
import Development.IDE.Types.Location (toNormalizedFilePath' )
22
- import Distribution.Fields.Field (Field (Field ), Name (Name ), FieldName , FieldLine (FieldLine ))
23
- import Distribution.Parsec.Position (Position (Position ))
21
+ import Distribution.Fields.Field
22
+ ( Field (Field , Section ),
23
+ FieldLine (FieldLine ),
24
+ Name (Name ),
25
+ SectionArg (SecArgName , SecArgOther , SecArgStr ),
26
+ )
27
+ import Distribution.Parsec.Position (Position )
24
28
import Ide.Plugin.Cabal.Completion.Types (ParseCabalFields (.. ), cabalPositionToLSPPosition )
25
29
import Ide.Plugin.Cabal.Orphans ()
26
30
import Ide.Types
@@ -32,8 +36,6 @@ moduleOutline ideState _ LSP.DocumentSymbolParams {_textDocument = LSP.TextDocum
32
36
case LSP. uriToFilePath uri of
33
37
Just (toNormalizedFilePath' -> fp) -> do
34
38
mFields <- liftIO $ runIdeAction " cabal-plugin.fields" (shakeExtras ideState) (useWithStaleFast ParseCabalFields fp)
35
- let debug = fmap fst mFields
36
- -- Debug.traceShowM debug
37
39
case fmap fst mFields of
38
40
Just fieldPositions -> pure $ LSP. InR (LSP. InL allSymbols)
39
41
where
@@ -42,39 +44,88 @@ moduleOutline ideState _ LSP.DocumentSymbolParams {_textDocument = LSP.TextDocum
42
44
Nothing -> pure $ LSP. InL []
43
45
44
46
documentSymbolForField :: Field Position -> Maybe LSP. DocumentSymbol
45
- documentSymbolForField (Field (Name pos fieldName) fieldLines) = Just $ LSP. DocumentSymbol {.. }
47
+ documentSymbolForField (Field (Name pos fieldName) fieldLines) =
48
+ Just
49
+ (defDocumentSymbol range)
50
+ { LSP. _name = decodeASCII fieldName,
51
+ LSP. _kind = LSP. SymbolKind_Object ,
52
+ LSP. _children = Just $ mapMaybe documentSymbolForFieldLine fieldLines
53
+ }
46
54
where
47
- _detail = Nothing
48
- _deprecated = Nothing
49
- _name = decodeASCII fieldName
50
-
51
- _kind = LSP. SymbolKind_Field
52
- _range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII fieldName
53
- _selectionRange = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII fieldName
54
- _children = Just $ mapMaybe documentSymbolForFieldLine fieldLines
55
- _tags = Nothing
55
+ range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII fieldName
56
+ documentSymbolForField (Section (Name pos fieldName) sectionArgs fields) =
57
+ Just
58
+ (defDocumentSymbol range)
59
+ { LSP. _name = decodeASCII fieldName,
60
+ LSP. _kind = LSP. SymbolKind_Object ,
61
+ LSP. _children =
62
+ Just
63
+ ( mapMaybe documentSymbolForField fields
64
+ ++ mapMaybe documentSymbolForSectionArgs sectionArgs
65
+ )
66
+ }
67
+ where
68
+ range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII fieldName
56
69
57
- documentSymbolForField _ = Nothing
70
+ documentSymbolForSectionArgs :: SectionArg Position -> Maybe LSP. DocumentSymbol
71
+ documentSymbolForSectionArgs (SecArgName pos identifier) =
72
+ Just
73
+ (defDocumentSymbol range)
74
+ { LSP. _name = decodeLatin1 identifier,
75
+ LSP. _kind = LSP. SymbolKind_Variable ,
76
+ LSP. _children = Nothing
77
+ }
78
+ where
79
+ range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII identifier
80
+ documentSymbolForSectionArgs (SecArgStr pos quotedString) =
81
+ Just
82
+ (defDocumentSymbol range)
83
+ { LSP. _name = decodeLatin1 quotedString,
84
+ LSP. _kind = LSP. SymbolKind_Constant ,
85
+ LSP. _children = Nothing
86
+ }
87
+ where
88
+ range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII quotedString
89
+ documentSymbolForSectionArgs (SecArgOther pos string) =
90
+ Just
91
+ (defDocumentSymbol range)
92
+ { LSP. _name = decodeLatin1 string,
93
+ LSP. _kind = LSP. SymbolKind_String ,
94
+ LSP. _children = Nothing
95
+ }
96
+ where
97
+ range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII string
58
98
59
99
documentSymbolForFieldLine :: FieldLine Position -> Maybe LSP. DocumentSymbol
60
- documentSymbolForFieldLine (FieldLine pos line) = Just $ LSP. DocumentSymbol {.. }
100
+ documentSymbolForFieldLine (FieldLine pos line) =
101
+ Just
102
+ (defDocumentSymbol range)
103
+ { LSP. _name = decodeLatin1 line, -- since there is no ascii invariant (?)
104
+ LSP. _kind = LSP. SymbolKind_Field ,
105
+ LSP. _children = Nothing -- can't delete even though the base case covers this (?)
106
+ }
61
107
where
62
- _detail = Nothing
63
- _deprecated = Nothing
64
- _name = decodeLatin1 line -- since there is no ascii invariant (?)
65
-
66
- _kind = LSP. SymbolKind_Field
67
- _range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII line
68
- _selectionRange = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII line
69
- _children = Nothing
70
- _tags = Nothing
108
+ range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII line
71
109
72
110
cabalPositionToLSPRange :: Position -> LSP. Range
73
111
cabalPositionToLSPRange pos = LSP. Range lspPos lspPos
74
- where lspPos = cabalPositionToLSPPosition pos
112
+ where
113
+ lspPos = cabalPositionToLSPPosition pos
75
114
76
115
addNameLengthToLSPRange :: LSP. Range -> T. Text -> LSP. Range
77
116
addNameLengthToLSPRange (LSP. Range pos1 (LSP. Position line char)) name =
78
- LSP. Range
79
- pos1
80
- (LSP. Position line (char + fromIntegral (T. length name)))
117
+ LSP. Range
118
+ pos1
119
+ (LSP. Position line (char + fromIntegral (T. length name)))
120
+
121
+ defDocumentSymbol :: LSP. Range -> LSP. DocumentSymbol
122
+ defDocumentSymbol range = LSP. DocumentSymbol {.. }
123
+ where
124
+ _detail = Nothing
125
+ _deprecated = Nothing
126
+ _name = " "
127
+ _kind = LSP. SymbolKind_File
128
+ _range = range
129
+ _selectionRange = range
130
+ _children = Nothing
131
+ _tags = Nothing
0 commit comments