@@ -22,7 +22,7 @@ import qualified Data.Text as T
22
22
import Development.IDE.Core.Rules
23
23
import Development.IDE.Core.Shake
24
24
import Development.IDE.GHC.Compat
25
- import Development.IDE.GHC.Error ( srcSpanToRange )
25
+ import Development.IDE.GHC.Error ( realSrcSpanToRange )
26
26
import Development.IDE.LSP.Server
27
27
import Development.IDE.Types.Location
28
28
import Outputable ( Outputable
@@ -46,12 +46,14 @@ moduleOutline _lsp ideState DocumentSymbolParams { _textDocument = TextDocumentI
46
46
Just ParsedModule { pm_parsed_source = L _ltop HsModule { hsmodName, hsmodDecls, hsmodImports } }
47
47
-> let
48
48
declSymbols = mapMaybe documentSymbolForDecl hsmodDecls
49
- moduleSymbol = hsmodName <&> \ (L l m) ->
50
- (defDocumentSymbol l :: DocumentSymbol )
51
- { _name = pprText m
52
- , _kind = SkFile
53
- , _range = Range (Position 0 0 ) (Position maxBound 0 ) -- _ltop is 0 0 0 0
54
- }
49
+ moduleSymbol = hsmodName >>= \ case
50
+ (L (RealSrcSpan l) m) -> Just $
51
+ (defDocumentSymbol l :: DocumentSymbol )
52
+ { _name = pprText m
53
+ , _kind = SkFile
54
+ , _range = Range (Position 0 0 ) (Position maxBound 0 ) -- _ltop is 0 0 0 0
55
+ }
56
+ _ -> Nothing
55
57
importSymbols = maybe [] pure $
56
58
documentSymbolForImportSummary
57
59
(mapMaybe documentSymbolForImport hsmodImports)
@@ -68,7 +70,7 @@ moduleOutline _lsp ideState DocumentSymbolParams { _textDocument = TextDocumentI
68
70
Nothing -> pure $ Right $ DSDocumentSymbols (List [] )
69
71
70
72
documentSymbolForDecl :: Located (HsDecl GhcPs ) -> Maybe DocumentSymbol
71
- documentSymbolForDecl (L l (TyClD FamDecl { tcdFam = FamilyDecl { fdLName = L _ n, fdInfo, fdTyVars } }))
73
+ documentSymbolForDecl (L ( RealSrcSpan l) (TyClD FamDecl { tcdFam = FamilyDecl { fdLName = L _ n, fdInfo, fdTyVars } }))
72
74
= Just (defDocumentSymbol l :: DocumentSymbol )
73
75
{ _name = showRdrName n
74
76
<> (case pprText fdTyVars of
@@ -78,7 +80,7 @@ documentSymbolForDecl (L l (TyClD FamDecl { tcdFam = FamilyDecl { fdLName = L _
78
80
, _detail = Just $ pprText fdInfo
79
81
, _kind = SkClass
80
82
}
81
- documentSymbolForDecl (L l (TyClD ClassDecl { tcdLName = L _ name, tcdSigs, tcdTyVars }))
83
+ documentSymbolForDecl (L ( RealSrcSpan l) (TyClD ClassDecl { tcdLName = L _ name, tcdSigs, tcdTyVars }))
82
84
= Just (defDocumentSymbol l :: DocumentSymbol )
83
85
{ _name = showRdrName name
84
86
<> (case pprText tcdTyVars of
@@ -92,13 +94,13 @@ documentSymbolForDecl (L l (TyClD ClassDecl { tcdLName = L _ name, tcdSigs, tcdT
92
94
[ (defDocumentSymbol l :: DocumentSymbol )
93
95
{ _name = showRdrName n
94
96
, _kind = SkMethod
95
- , _selectionRange = srcSpanToRange l'
97
+ , _selectionRange = realSrcSpanToRange l'
96
98
}
97
- | L l (ClassOpSig False names _) <- tcdSigs
98
- , L l' n <- names
99
+ | L ( RealSrcSpan l) (ClassOpSig False names _) <- tcdSigs
100
+ , L ( RealSrcSpan l') n <- names
99
101
]
100
102
}
101
- documentSymbolForDecl (L l (TyClD DataDecl { tcdLName = L _ name, tcdDataDefn = HsDataDefn { dd_cons } }))
103
+ documentSymbolForDecl (L ( RealSrcSpan l) (TyClD DataDecl { tcdLName = L _ name, tcdDataDefn = HsDataDefn { dd_cons } }))
102
104
= Just (defDocumentSymbol l :: DocumentSymbol )
103
105
{ _name = showRdrName name
104
106
, _kind = SkStruct
@@ -107,11 +109,11 @@ documentSymbolForDecl (L l (TyClD DataDecl { tcdLName = L _ name, tcdDataDefn =
107
109
[ (defDocumentSymbol l :: DocumentSymbol )
108
110
{ _name = showRdrName n
109
111
, _kind = SkConstructor
110
- , _selectionRange = srcSpanToRange l'
112
+ , _selectionRange = realSrcSpanToRange l'
111
113
, _children = conArgRecordFields (getConArgs x)
112
114
}
113
- | L l x <- dd_cons
114
- , L l' n <- getConNames x
115
+ | L ( RealSrcSpan l ) x <- dd_cons
116
+ , L ( RealSrcSpan l') n <- getConNames x
115
117
]
116
118
}
117
119
where
@@ -122,48 +124,48 @@ documentSymbolForDecl (L l (TyClD DataDecl { tcdLName = L _ name, tcdDataDefn =
122
124
, _kind = SkField
123
125
}
124
126
| L _ cdf <- lcdfs
125
- , L l n <- rdrNameFieldOcc . unLoc <$> cd_fld_names cdf
127
+ , L ( RealSrcSpan l) n <- rdrNameFieldOcc . unLoc <$> cd_fld_names cdf
126
128
]
127
129
conArgRecordFields _ = Nothing
128
- documentSymbolForDecl (L l (TyClD SynDecl { tcdLName = L l' n })) = Just
130
+ documentSymbolForDecl (L ( RealSrcSpan l) (TyClD SynDecl { tcdLName = L ( RealSrcSpan l') n })) = Just
129
131
(defDocumentSymbol l :: DocumentSymbol ) { _name = showRdrName n
130
132
, _kind = SkTypeParameter
131
- , _selectionRange = srcSpanToRange l'
133
+ , _selectionRange = realSrcSpanToRange l'
132
134
}
133
- documentSymbolForDecl (L l (InstD ClsInstD { cid_inst = ClsInstDecl { cid_poly_ty } }))
135
+ documentSymbolForDecl (L ( RealSrcSpan l) (InstD ClsInstD { cid_inst = ClsInstDecl { cid_poly_ty } }))
134
136
= Just (defDocumentSymbol l :: DocumentSymbol ) { _name = pprText cid_poly_ty
135
137
, _kind = SkInterface
136
138
}
137
- documentSymbolForDecl (L l (InstD DataFamInstD { dfid_inst = DataFamInstDecl HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } } }))
139
+ documentSymbolForDecl (L ( RealSrcSpan l) (InstD DataFamInstD { dfid_inst = DataFamInstDecl HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } } }))
138
140
= Just (defDocumentSymbol l :: DocumentSymbol )
139
141
{ _name = showRdrName (unLoc feqn_tycon) <> " " <> T. unwords
140
142
(map pprText feqn_pats)
141
143
, _kind = SkInterface
142
144
}
143
- documentSymbolForDecl (L l (InstD TyFamInstD { tfid_inst = TyFamInstDecl HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } } }))
145
+ documentSymbolForDecl (L ( RealSrcSpan l) (InstD TyFamInstD { tfid_inst = TyFamInstDecl HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } } }))
144
146
= Just (defDocumentSymbol l :: DocumentSymbol )
145
147
{ _name = showRdrName (unLoc feqn_tycon) <> " " <> T. unwords
146
148
(map pprText feqn_pats)
147
149
, _kind = SkInterface
148
150
}
149
- documentSymbolForDecl (L l (DerivD DerivDecl { deriv_type })) =
151
+ documentSymbolForDecl (L ( RealSrcSpan l) (DerivD DerivDecl { deriv_type })) =
150
152
gfindtype deriv_type <&> \ (L (_ :: SrcSpan ) name) ->
151
153
(defDocumentSymbol l :: DocumentSymbol ) { _name = pprText @ (HsType GhcPs )
152
154
name
153
155
, _kind = SkInterface
154
156
}
155
- documentSymbolForDecl (L l (ValD FunBind {fun_id = L _ name})) = Just
157
+ documentSymbolForDecl (L ( RealSrcSpan l) (ValD FunBind {fun_id = L _ name})) = Just
156
158
(defDocumentSymbol l :: DocumentSymbol )
157
159
{ _name = showRdrName name
158
160
, _kind = SkFunction
159
161
}
160
- documentSymbolForDecl (L l (ValD PatBind {pat_lhs})) = Just
162
+ documentSymbolForDecl (L ( RealSrcSpan l) (ValD PatBind {pat_lhs})) = Just
161
163
(defDocumentSymbol l :: DocumentSymbol )
162
164
{ _name = pprText pat_lhs
163
165
, _kind = SkFunction
164
166
}
165
167
166
- documentSymbolForDecl (L l (ForD x)) = Just
168
+ documentSymbolForDecl (L ( RealSrcSpan l) (ForD x)) = Just
167
169
(defDocumentSymbol l :: DocumentSymbol )
168
170
{ _name = case x of
169
171
ForeignImport {} -> name
@@ -203,7 +205,7 @@ documentSymbolForImportSummary importSymbols =
203
205
}
204
206
205
207
documentSymbolForImport :: Located (ImportDecl GhcPs ) -> Maybe DocumentSymbol
206
- documentSymbolForImport (L l ImportDecl { ideclName, ideclQualified }) = Just
208
+ documentSymbolForImport (L ( RealSrcSpan l) ImportDecl { ideclName, ideclQualified }) = Just
207
209
(defDocumentSymbol l :: DocumentSymbol )
208
210
{ _name = " import " <> pprText ideclName
209
211
, _kind = SkModule
@@ -213,18 +215,16 @@ documentSymbolForImport (L l ImportDecl { ideclName, ideclQualified }) = Just
213
215
, _detail = if ideclQualified then Just " qualified" else Nothing
214
216
#endif
215
217
}
216
- #if MIN_GHC_API_VERSION(8,6,0)
217
- documentSymbolForImport (L _ XImportDecl {}) = Nothing
218
- #endif
218
+ documentSymbolForImport _ = Nothing
219
219
220
- defDocumentSymbol :: SrcSpan -> DocumentSymbol
220
+ defDocumentSymbol :: RealSrcSpan -> DocumentSymbol
221
221
defDocumentSymbol l = DocumentSymbol { .. } where
222
222
_detail = Nothing
223
223
_deprecated = Nothing
224
224
_name = " "
225
225
_kind = SkUnknown 0
226
- _range = srcSpanToRange l
227
- _selectionRange = srcSpanToRange l
226
+ _range = realSrcSpanToRange l
227
+ _selectionRange = realSrcSpanToRange l
228
228
_children = Nothing
229
229
230
230
showRdrName :: RdrName -> Text
0 commit comments