@@ -50,7 +50,9 @@ moduleOutline _lsp ideState DocumentSymbolParams { _textDocument = TextDocumentI
50 , _kind = SkFile
50 , _kind = SkFile
51 , _range = Range (Position 0 0) (Position maxBound 0) -- _ltop is 0 0 0 0
51 , _range = Range (Position 0 0) (Position maxBound 0) -- _ltop is 0 0 0 0
53+ importSymbols = maybe [] pure $
54+ documentSymbolForImportSummary
53− importSymbols = mapMaybe documentSymbolForImport hsmodImports
55+ (mapMaybe documentSymbolForImport hsmodImports)
54 allSymbols = case moduleSymbol of
56 allSymbols = case moduleSymbol of
55 Nothing -> importSymbols <> declSymbols
57 Nothing -> importSymbols <> declSymbols
@@ -167,6 +169,25 @@ documentSymbolForDecl (L l (ForD x)) = Just
168documentSymbolForDecl _ = Nothing
170documentSymbolForDecl _ = Nothing
172+-- | Wrap the Document imports into a hierarchical outline for
173+-- a better overview of symbols in scope.
174+-- If there are no imports, then no hierarchy will be created.
175+documentSymbolForImportSummary :: [DocumentSymbol] -> Maybe DocumentSymbol
176+documentSymbolForImportSummary [] = Nothing
177+documentSymbolForImportSummary importSymbols =
179+ -- safe because if we have no ranges then we don't take this branch
180+ mergeRanges xs = Range (minimum $ map _start xs) (maximum $ map _end xs)
181+ importRange = mergeRanges $ map (_range :: DocumentSymbol -> Range) importSymbols
183+ Just (defDocumentSymbol empty :: DocumentSymbol)
186+ , _children = Just (List importSymbols)
187+ , _range = importRange
188+ , _selectionRange = importRange
170documentSymbolForImport :: Located (ImportDecl GhcPs) -> Maybe DocumentSymbol
191documentSymbolForImport :: Located (ImportDecl GhcPs) -> Maybe DocumentSymbol
171documentSymbolForImport (L l ImportDecl { ideclName, ideclQualified }) = Just
192documentSymbolForImport (L l ImportDecl { ideclName, ideclQualified }) = Just
172 (defDocumentSymbol l :: DocumentSymbol)
193 (defDocumentSymbol l :: DocumentSymbol)