1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 17:04:47 +03:00

Straighten up how we trim docs

This commit is contained in:
Timothy Clem 2020-01-16 13:13:46 -08:00
parent ff4b282c58
commit d6b406b622

View File

@ -60,12 +60,13 @@ contextualizing source toKind = Streaming.mapMaybeM $ \case
Exit x r -> Nothing <$ exitScope (x, r)
Iden iden loc docsLiteralRange -> fmap go (get @[ContextToken]) where
go = \case
((x, r):("Context", cr):_) | Just kind <- toKind x -> Just $ Tag iden kind loc (firstLine (slice r)) (Just (slice cr))
((x, r):_) | Just kind <- toKind x -> Just $ Tag iden kind loc (firstLine (slice r)) (T.stripEnd . slice <$> docsLiteralRange)
((x, r):("Context", cr):_) | Just kind <- toKind x -> Just $ Tag iden kind loc (firstLine r) (Just (sliceDocs cr))
((x, r):_) | Just kind <- toKind x -> Just $ Tag iden kind loc (firstLine r) (sliceDocs <$> docsLiteralRange)
_ -> Nothing
where
slice = Source.toText . Source.slice source
firstLine = T.stripEnd . T.take 180 . T.takeWhile (/= '\n')
sliceDocs = T.stripEnd . slice
firstLine = T.stripEnd . T.take 180 . T.takeWhile (/= '\n') . slice
enterScope, exitScope :: Has (State [ContextToken]) sig m
=> ContextToken