1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 07:55:12 +03:00

Define a custom ToTagBy instance for ClassDeclaration.

This commit is contained in:
Rob Rix 2019-09-27 18:48:48 -04:00
parent 1d8e0cdc3d
commit 074967337a
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -47,6 +47,7 @@ type family ToTagsInstance t :: Strategy where
ToTagsInstance (_ :+: _) = 'Custom
ToTagsInstance Java.Program = 'Custom
ToTagsInstance Java.MethodDeclaration = 'Custom
ToTagsInstance Java.ClassDeclaration = 'Custom
ToTagsInstance _ = 'Generic
@ -82,6 +83,17 @@ instance ToTagsBy 'Custom Java.MethodDeclaration where
traverse_ tags extraChildren
traverse_ tags body
instance ToTagsBy 'Custom Java.ClassDeclaration where
tags' t@Java.ClassDeclaration
{ ann = Loc Range { start } span
, name = Java.Identifier { bytes = name }
, body = Java.ClassBody { ann = Loc Range { start = end } _ }
} = do
src <- ask @Source
let sliced = slice src (Range start end)
Tags.yield (Tag name Function span (firstLine sliced) Nothing)
gtags t
firstLine :: Source -> Text
firstLine = Text.takeWhile (/= '\n') . toText . Source.take 180