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 name kind loc range = do
src <- ask @Source
let sliced = slice src range
Tags.yield (Tag name kind loc (Tags.firstLine sliced) Nothing)
Tags.yield (Tag name kind loc (Tags.firstLine src range) Nothing)
instance ToTags Go.ArgumentList

View File

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

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 kind loc range = do
src <- ask @Source
let sliced = slice src range
Tags.yield (Tag name kind loc (Tags.firstLine sliced) Nothing)
Tags.yield (Tag name kind loc (Tags.firstLine src range) Nothing)
instance ToTags Rb.Class where
tags t@Rb.Class

View File

@ -38,6 +38,7 @@ import GHC.Generics
import Prelude hiding (span)
import Source.Loc (Loc (..))
import Source.Source as Source
import Source.Range (Range)
import Source.Span
import Tags.Tag
@ -60,8 +61,9 @@ runTagging source
. execWriter
. runReader source
firstLine :: Source -> Text
firstLine = Text.stripEnd . Text.take 180 . Text.takeWhile (/= '\n') . Source.toText
-- | Slices a range out of 'Source' and gives back the first line of source up to 180 characters.
firstLine :: Source -> Range -> Text
firstLine src = Text.stripEnd . Text.take 180 . Text.takeWhile (/= '\n') . Source.toText . slice src
-- 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 kind loc range = do
src <- ask @Source
let sliced = slice src range
Tags.yield (Tag name kind loc (Tags.firstLine sliced) Nothing)
Tags.yield (Tag name kind loc (Tags.firstLine src range) Nothing)
instance ToTags Tsx.AbstractClassDeclaration
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 kind loc range = do
src <- ask @Source
let sliced = slice src range
Tags.yield (Tag name kind loc (Tags.firstLine sliced) Nothing)
Tags.yield (Tag name kind loc (Tags.firstLine src range) Nothing)
instance ToTags Ts.AbstractClassDeclaration
instance ToTags Ts.AbstractMethodSignature