@@ -24,10 +24,10 @@ import Distribution.Fields.Field
24
24
Name (Name ),
25
25
SectionArg (SecArgName , SecArgOther , SecArgStr ),
26
26
)
27
- import Distribution.Parsec.Position (Position )
27
+ import Distribution.Parsec.Position (Position ( Position ) )
28
28
import Ide.Plugin.Cabal.Completion.Types (ParseCabalFields (.. ), cabalPositionToLSPPosition )
29
29
import Ide.Plugin.Cabal.Orphans ()
30
- import Ide.Types ( PluginMethodHandler )
30
+ import Ide.Types (PluginMethodHandler )
31
31
import Language.LSP.Protocol.Message qualified as LSP
32
32
import Language.LSP.Protocol.Types qualified as LSP
33
33
@@ -43,70 +43,41 @@ moduleOutline ideState _ LSP.DocumentSymbolParams {_textDocument = LSP.TextDocum
43
43
Nothing -> pure $ LSP. InL []
44
44
Nothing -> pure $ LSP. InL []
45
45
46
+ -- | Creates a DocumentSumbol object for the
47
+ -- cabal AST, without displaying fieldLines and
48
+ -- displaying Section name and SectionArgs in one line
46
49
documentSymbolForField :: Field Position -> Maybe LSP. DocumentSymbol
47
- documentSymbolForField (Field (Name pos fieldName) fieldLines ) =
50
+ documentSymbolForField (Field (Name pos fieldName) _ ) =
48
51
Just
49
52
(defDocumentSymbol range)
50
53
{ LSP. _name = decodeUtf8 fieldName,
51
54
LSP. _kind = LSP. SymbolKind_Field ,
52
- LSP. _children = Just $ mapMaybe documentSymbolForFieldLine fieldLines
55
+ LSP. _children = Nothing
53
56
}
54
57
where
55
58
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 fieldName
56
59
documentSymbolForField (Section (Name pos fieldName) sectionArgs fields) =
57
60
Just
58
61
(defDocumentSymbol range)
59
- { LSP. _name = decodeUtf8 fieldName ,
62
+ { LSP. _name = joinedName ,
60
63
LSP. _kind = LSP. SymbolKind_Object ,
61
64
LSP. _children =
62
65
Just
63
- ( mapMaybe documentSymbolForField fields
64
- ++ mapMaybe documentSymbolForSectionArgs sectionArgs
65
- )
66
- }
67
- where
68
- range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 fieldName
69
-
70
- documentSymbolForSectionArgs :: SectionArg Position -> Maybe LSP. DocumentSymbol
71
- documentSymbolForSectionArgs (SecArgName pos identifier) =
72
- Just
73
- (defDocumentSymbol range)
74
- { LSP. _name = decodeUtf8 identifier,
75
- LSP. _kind = LSP. SymbolKind_Variable ,
76
- LSP. _children = Nothing
77
- }
78
- where
79
- range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 identifier
80
- documentSymbolForSectionArgs (SecArgStr pos quotedString) =
81
- Just
82
- (defDocumentSymbol range)
83
- { LSP. _name = decodeUtf8 quotedString,
84
- LSP. _kind = LSP. SymbolKind_Constant ,
85
- LSP. _children = Nothing
86
- }
87
- where
88
- range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 quotedString
89
- documentSymbolForSectionArgs (SecArgOther pos string) =
90
- Just
91
- (defDocumentSymbol range)
92
- { LSP. _name = decodeUtf8 string,
93
- LSP. _kind = LSP. SymbolKind_String ,
94
- LSP. _children = Nothing
66
+ (mapMaybe documentSymbolForField fields)
95
67
}
96
68
where
97
- range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 string
69
+ joinedName = decodeUtf8 fieldName <> " " <> joinedNameForSectionArgs sectionArgs
70
+ range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` joinedName
98
71
99
- documentSymbolForFieldLine :: FieldLine Position -> Maybe LSP. DocumentSymbol
100
- documentSymbolForFieldLine (FieldLine pos line) =
101
- Just
102
- (defDocumentSymbol range)
103
- { LSP. _name = decodeUtf8 line,
104
- LSP. _kind = LSP. SymbolKind_Field ,
105
- LSP. _children = Nothing
106
- }
72
+ joinedNameForSectionArgs :: [SectionArg Position ] -> T. Text
73
+ joinedNameForSectionArgs sectionArgs = joinedName
107
74
where
108
- range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 line
75
+ joinedName = T. unwords $ map getName sectionArgs
109
76
77
+ getName :: SectionArg Position -> T. Text
78
+ getName (SecArgName _ identifier) = decodeUtf8 identifier
79
+ getName (SecArgStr _ quotedString) = decodeUtf8 quotedString
80
+ getName (SecArgOther _ string) = decodeUtf8 string
110
81
111
82
-- | Creates a single point LSP range
112
83
-- using cabal position
0 commit comments