1
1
mirror of https://github.com/github/semantic.git synced 2024-12-28 09:21:35 +03:00

Slice the source in docComment.

This commit is contained in:
Rob Rix 2019-09-19 17:41:17 -04:00
parent 0a62bab659
commit d0c30bf4b5
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -110,9 +110,7 @@ instance ToTagBy 'Custom (Py.FunctionDefinition Location) where
} = do
src <- ask @Source
ctx <- ask @[Kind]
let docs = case listToMaybe extraChildren >>= docComment of
Just Py.String { ann } -> Just (toText (slice (locationByteRange ann) src))
_ -> Nothing
let docs = listToMaybe extraChildren >>= docComment src
sliced = slice (Range start end) src
yield (Tag name Function span ctx (Just (firstLine sliced)) docs)
local (Function:) $ do
@ -123,9 +121,9 @@ instance ToTagBy 'Custom (Py.FunctionDefinition Location) where
yield :: (Carrier sig m, Member (Writer (Endo [Tag])) sig) => Tag -> m ()
yield = tell . Endo . (:)
docComment :: Either (Py.CompoundStatement a) (Py.SimpleStatement a) -> Maybe (Py.String a)
docComment (Right (Py.ExpressionStatementSimpleStatement (Py.ExpressionStatement { extraChildren = Left (Py.PrimaryExpressionExpression (Py.StringPrimaryExpression s)) :|_ }))) = Just s
docComment _ = Nothing
docComment :: Source -> Either (Py.CompoundStatement Location) (Py.SimpleStatement Location) -> Maybe Text
docComment src (Right (Py.ExpressionStatementSimpleStatement (Py.ExpressionStatement { extraChildren = Left (Py.PrimaryExpressionExpression (Py.StringPrimaryExpression Py.String { ann })) :|_ }))) = Just (toText (slice (locationByteRange ann) src))
docComment _ _ = Nothing
firstLine :: Source -> Text
firstLine = T.take 180 . T.takeWhile (/= '\n') . toText