Skip to content

Commit a5e7e53

Browse files
committed
remove fieldLines, one line Section display
1 parent fd0b2ea commit a5e7e53

File tree

1 file changed

+18
-47
lines changed
  • plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal

1 file changed

+18
-47
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Outline.hs

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import Distribution.Fields.Field
2424
Name (Name),
2525
SectionArg (SecArgName, SecArgOther, SecArgStr),
2626
)
27-
import Distribution.Parsec.Position (Position)
27+
import Distribution.Parsec.Position (Position (Position))
2828
import Ide.Plugin.Cabal.Completion.Types (ParseCabalFields (..), cabalPositionToLSPPosition)
2929
import Ide.Plugin.Cabal.Orphans ()
30-
import Ide.Types ( PluginMethodHandler )
30+
import Ide.Types (PluginMethodHandler)
3131
import Language.LSP.Protocol.Message qualified as LSP
3232
import Language.LSP.Protocol.Types qualified as LSP
3333

@@ -43,70 +43,41 @@ moduleOutline ideState _ LSP.DocumentSymbolParams {_textDocument = LSP.TextDocum
4343
Nothing -> pure $ LSP.InL []
4444
Nothing -> pure $ LSP.InL []
4545

46+
-- | Creates a DocumentSumbol object for the
47+
-- cabal AST, without displaying fieldLines and
48+
-- displaying Section name and SectionArgs in one line
4649
documentSymbolForField :: Field Position -> Maybe LSP.DocumentSymbol
47-
documentSymbolForField (Field (Name pos fieldName) fieldLines) =
50+
documentSymbolForField (Field (Name pos fieldName) _) =
4851
Just
4952
(defDocumentSymbol range)
5053
{ LSP._name = decodeUtf8 fieldName,
5154
LSP._kind = LSP.SymbolKind_Field,
52-
LSP._children = Just $ mapMaybe documentSymbolForFieldLine fieldLines
55+
LSP._children = Nothing
5356
}
5457
where
5558
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 fieldName
5659
documentSymbolForField (Section (Name pos fieldName) sectionArgs fields) =
5760
Just
5861
(defDocumentSymbol range)
59-
{ LSP._name = decodeUtf8 fieldName,
62+
{ LSP._name = joinedName,
6063
LSP._kind = LSP.SymbolKind_Object,
6164
LSP._children =
6265
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)
9567
}
9668
where
97-
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 string
69+
joinedName = decodeUtf8 fieldName <> " " <> joinedNameForSectionArgs sectionArgs
70+
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` joinedName
9871

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
10774
where
108-
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 line
75+
joinedName = T.unwords $ map getName sectionArgs
10976

77+
getName :: SectionArg Position -> T.Text
78+
getName (SecArgName _ identifier) = decodeUtf8 identifier
79+
getName (SecArgStr _ quotedString) = decodeUtf8 quotedString
80+
getName (SecArgOther _ string) = decodeUtf8 string
11081

11182
-- | Creates a single point LSP range
11283
-- using cabal position

0 commit comments

Comments
 (0)