1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 14:54:16 +03:00

firstLine takes a range

This commit is contained in:
Timothy Clem 2020-01-16 12:14:40 -08:00
parent 0ffa50bdf4
commit 6bcc231355
7 changed files with 13 additions and 18 deletions

View File

@ -82,8 +82,7 @@ gtags = Tags.traverse1_ @ToTags (const (pure ())) tags . Tags.Generics
yieldTag :: (Has (Reader Source) sig m, Has (Writer Tags.Tags) sig m) => Text -> Kind -> Loc -> Range -> m () yieldTag :: (Has (Reader Source) sig m, Has (Writer Tags.Tags) sig m) => Text -> Kind -> Loc -> Range -> m ()
yieldTag name kind loc range = do yieldTag name kind loc range = do
src <- ask @Source src <- ask @Source
let sliced = slice src range Tags.yield (Tag name kind loc (Tags.firstLine src range) Nothing)
Tags.yield (Tag name kind loc (Tags.firstLine sliced) Nothing)
instance ToTags Go.ArgumentList instance ToTags Go.ArgumentList

View File

@ -49,12 +49,12 @@ instance ToTags Java.MethodDeclaration where
, body , body
} = do } = do
src <- ask @Source src <- ask @Source
let sliced = slice src range let line = Tags.firstLine src range
{ end = case body of { end = case body of
Just Java.Block { ann = Loc Range { end } _ } -> end Just Java.Block { ann = Loc Range { end } _ } -> end
Nothing -> end range Nothing -> end range
} }
Tags.yield (Tag name Method loc (Tags.firstLine sliced) Nothing) Tags.yield (Tag name Method loc line Nothing)
gtags t gtags t
instance ToTags Java.ClassDeclaration where instance ToTags Java.ClassDeclaration where
@ -64,8 +64,7 @@ instance ToTags Java.ClassDeclaration where
, body = Java.ClassBody { ann = Loc Range { start = end } _ } , body = Java.ClassBody { ann = Loc Range { start = end } _ }
} = do } = do
src <- ask @Source src <- ask @Source
let sliced = slice src (Range start end) Tags.yield (Tag name Class loc (Tags.firstLine src (Range start end)) Nothing)
Tags.yield (Tag name Class loc (Tags.firstLine sliced) Nothing)
gtags t gtags t
instance ToTags Java.MethodInvocation where instance ToTags Java.MethodInvocation where
@ -74,8 +73,7 @@ instance ToTags Java.MethodInvocation where
, name = Java.Identifier { text = name } , name = Java.Identifier { text = name }
} = do } = do
src <- ask @Source src <- ask @Source
let sliced = slice src range Tags.yield (Tag name Call loc (Tags.firstLine src range) Nothing)
Tags.yield (Tag name Call loc (Tags.firstLine sliced) Nothing)
gtags t gtags t

View File

@ -117,8 +117,7 @@ instance ToTags Py.Call where
yieldTag :: (Has (Reader Source) sig m, Has (Writer Tags.Tags) sig m) => Text -> Kind -> Loc -> Range -> Maybe Text -> m () yieldTag :: (Has (Reader Source) sig m, Has (Writer Tags.Tags) sig m) => Text -> Kind -> Loc -> Range -> Maybe Text -> m ()
yieldTag name kind loc range docs = do yieldTag name kind loc range docs = do
src <- ask @Source src <- ask @Source
let sliced = Tags.firstLine (slice src range) Tags.yield (Tag name kind loc (Tags.firstLine src range) docs)
Tags.yield (Tag name kind loc sliced docs)
docComment :: Source -> (Py.CompoundStatement :+: Py.SimpleStatement) Loc -> Maybe Text docComment :: Source -> (Py.CompoundStatement :+: Py.SimpleStatement) Loc -> Maybe Text
docComment src (R1 (Py.SimpleStatement (Prj Py.ExpressionStatement { extraChildren = L1 (Prj (Py.Expression (Prj (Py.PrimaryExpression (Prj Py.String { ann }))))) :|_ }))) = Just (toText (slice src (byteRange ann))) docComment src (R1 (Py.SimpleStatement (Prj Py.ExpressionStatement { extraChildren = L1 (Prj (Py.Expression (Prj (Py.PrimaryExpression (Prj Py.String { ann }))))) :|_ }))) = Just (toText (slice src (byteRange ann)))

View File

@ -74,8 +74,7 @@ yieldTag :: (Has (Reader Source) sig m, Has (Writer Tags.Tags) sig m) => Text ->
yieldTag name Call _ _ | name `elem` nameBlacklist = pure () yieldTag name Call _ _ | name `elem` nameBlacklist = pure ()
yieldTag name kind loc range = do yieldTag name kind loc range = do
src <- ask @Source src <- ask @Source
let sliced = slice src range Tags.yield (Tag name kind loc (Tags.firstLine src range) Nothing)
Tags.yield (Tag name kind loc (Tags.firstLine sliced) Nothing)
instance ToTags Rb.Class where instance ToTags Rb.Class where
tags t@Rb.Class tags t@Rb.Class

View File

@ -38,6 +38,7 @@ import GHC.Generics
import Prelude hiding (span) import Prelude hiding (span)
import Source.Loc (Loc (..)) import Source.Loc (Loc (..))
import Source.Source as Source import Source.Source as Source
import Source.Range (Range)
import Source.Span import Source.Span
import Tags.Tag import Tags.Tag
@ -60,8 +61,9 @@ runTagging source
. execWriter . execWriter
. runReader source . runReader source
firstLine :: Source -> Text -- | Slices a range out of 'Source' and gives back the first line of source up to 180 characters.
firstLine = Text.stripEnd . Text.take 180 . Text.takeWhile (/= '\n') . Source.toText firstLine :: Source -> Range -> Text
firstLine src = Text.stripEnd . Text.take 180 . Text.takeWhile (/= '\n') . Source.toText . slice src
-- FIXME: move Traversable1 into semantic-ast. -- FIXME: move Traversable1 into semantic-ast.

View File

@ -128,8 +128,7 @@ yieldTag :: (Has (Reader Source) sig m, Has (Writer Tags.Tags) sig m) => Text ->
yieldTag name Call _ _ | name `elem` nameBlacklist = pure () yieldTag name Call _ _ | name `elem` nameBlacklist = pure ()
yieldTag name kind loc range = do yieldTag name kind loc range = do
src <- ask @Source src <- ask @Source
let sliced = slice src range Tags.yield (Tag name kind loc (Tags.firstLine src range) Nothing)
Tags.yield (Tag name kind loc (Tags.firstLine sliced) Nothing)
instance ToTags Tsx.AbstractClassDeclaration instance ToTags Tsx.AbstractClassDeclaration
instance ToTags Tsx.AbstractMethodSignature instance ToTags Tsx.AbstractMethodSignature

View File

@ -121,8 +121,7 @@ yieldTag :: (Has (Reader Source) sig m, Has (Writer Tags.Tags) sig m) => Text ->
yieldTag name Call _ _ | name `elem` nameBlacklist = pure () yieldTag name Call _ _ | name `elem` nameBlacklist = pure ()
yieldTag name kind loc range = do yieldTag name kind loc range = do
src <- ask @Source src <- ask @Source
let sliced = slice src range Tags.yield (Tag name kind loc (Tags.firstLine src range) Nothing)
Tags.yield (Tag name kind loc (Tags.firstLine sliced) Nothing)
instance ToTags Ts.AbstractClassDeclaration instance ToTags Ts.AbstractClassDeclaration
instance ToTags Ts.AbstractMethodSignature instance ToTags Ts.AbstractMethodSignature