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

Adjust some of the source lines produced for Ruby

This commit is contained in:
Timothy Clem 2020-01-15 09:26:05 -08:00
parent 6535d4b70a
commit 6c773b546f

View File

@ -26,11 +26,12 @@ import Data.Foldable
import Data.Text as Text import Data.Text as Text
import GHC.Generics import GHC.Generics
import Source.Loc import Source.Loc
import Source.Range import Source.Range as Range
import Source.Source as Source import Source.Source as Source
import Tags.Tag import Tags.Tag
import qualified Tags.Tagging.Precise as Tags import qualified Tags.Tagging.Precise as Tags
import qualified TreeSitter.Ruby.AST as Rb import qualified TreeSitter.Ruby.AST as Rb
import qualified TreeSitter.Unmarshal as TS
class ToTags t where class ToTags t where
tags tags
@ -127,39 +128,55 @@ yieldTag name kind loc range = do
instance ToTagsBy 'Custom Rb.Class where instance ToTagsBy 'Custom Rb.Class where
tags' t@Rb.Class tags' t@Rb.Class
{ ann = loc@Loc { byteRange = range } { ann = loc@Loc { byteRange = Range { start } }
, name = expr , name = expr
, extraChildren
} = enterScope True $ case expr of } = enterScope True $ case expr of
Prj Rb.Constant { text } -> yield text Prj Rb.Constant { text } -> yield text
Prj Rb.ScopeResolution { name = Prj Rb.Constant { text } } -> yield text Prj Rb.ScopeResolution { name = Prj Rb.Constant { text } } -> yield text
Prj Rb.ScopeResolution { name = Prj Rb.Identifier { text } } -> yield text Prj Rb.ScopeResolution { name = Prj Rb.Identifier { text } } -> yield text
_ -> gtags t _ -> gtags t
where where
yield name = yieldTag name Class loc range >> gtags t range' = case extraChildren of
Prj Rb.Superclass { ann = Loc { byteRange = Range { end }}} : _ -> Range start end
_ -> Range start (getEnd expr)
getEnd = Range.end . byteRange . TS.gann
yield name = yieldTag name Class loc range' >> gtags t
instance ToTagsBy 'Custom Rb.SingletonClass where instance ToTagsBy 'Custom Rb.SingletonClass where
tags' t@Rb.SingletonClass tags' t@Rb.SingletonClass
{ ann = loc@Loc { byteRange = range } { ann = loc@Loc { byteRange = range@Range { start } }
, value = Rb.Arg expr , value = Rb.Arg expr
, extraChildren
} = enterScope True $ case expr of } = enterScope True $ case expr of
Prj (Rb.Primary (Prj (Rb.Lhs (Prj (Rb.Variable (Prj Rb.Constant { text })))))) -> yield text Prj (Rb.Primary (Prj (Rb.Lhs (Prj (Rb.Variable (Prj Rb.Constant { text })))))) -> yield text
Prj (Rb.Primary (Prj (Rb.Lhs (Prj Rb.ScopeResolution { name = Prj Rb.Constant { text } })))) -> yield text Prj (Rb.Primary (Prj (Rb.Lhs (Prj Rb.ScopeResolution { name = Prj Rb.Constant { text } })))) -> yield text
Prj (Rb.Primary (Prj (Rb.Lhs (Prj Rb.ScopeResolution { name = Prj Rb.Identifier { text } })))) -> yield text Prj (Rb.Primary (Prj (Rb.Lhs (Prj Rb.ScopeResolution { name = Prj Rb.Identifier { text } })))) -> yield text
_ -> gtags t _ -> gtags t
where where
yield name = yieldTag name Class loc range >> gtags t range' = case extraChildren of
x : _ -> Range start (getStart x)
_ -> range
getStart = Range.start . byteRange . TS.gann
yield name = yieldTag name Class loc range' >> gtags t
instance ToTagsBy 'Custom Rb.Module where instance ToTagsBy 'Custom Rb.Module where
tags' t@Rb.Module tags' t@Rb.Module
{ ann = loc@Loc { byteRange = range } { ann = loc@Loc { byteRange = Range { start } }
, name = expr , name = expr
, extraChildren
} = enterScope True $ case expr of } = enterScope True $ case expr of
Prj Rb.Constant { text = name } -> yield name Prj Rb.Constant { text = name } -> yield name
Prj Rb.ScopeResolution { name = Prj Rb.Constant { text = name } } -> yield name Prj Rb.ScopeResolution { name = Prj Rb.Constant { text = name } } -> yield name
Prj Rb.ScopeResolution { name = Prj Rb.Identifier { text = name } } -> yield name Prj Rb.ScopeResolution { name = Prj Rb.Identifier { text = name } } -> yield name
_ -> gtags t _ -> gtags t
where where
yield name = yieldTag name Module loc range >> gtags t range' = case extraChildren of
x : _ -> Range start (getStart x)
_ -> Range start (getEnd expr)
getEnd = Range.end . byteRange . TS.gann
getStart = Range.start . byteRange . TS.gann
yield name = yieldTag name Module loc range' >> gtags t
yieldMethodNameTag yieldMethodNameTag
:: ( Has (State [Text]) sig m :: ( Has (State [Text]) sig m
@ -191,18 +208,27 @@ enterScope createNew m = do
instance ToTagsBy 'Custom Rb.Method where instance ToTagsBy 'Custom Rb.Method where
tags' t@Rb.Method tags' t@Rb.Method
{ ann = loc@Loc { byteRange = range@Range { start } } { ann = loc@Loc { byteRange = Range { start } }
, name = expr , name
, parameters , parameters
} = case parameters of } = yieldMethodNameTag t loc range' name
Just Rb.MethodParameters { ann = Loc { byteRange = Range { end } }} -> yieldMethodNameTag t loc (Range start end) expr where
_ -> yieldMethodNameTag t loc range expr range' = case parameters of
Just Rb.MethodParameters { ann = Loc { byteRange = Range { end } }} -> Range start end
_ -> Range start (getEnd name)
getEnd = Range.end . byteRange . TS.gann
instance ToTagsBy 'Custom Rb.SingletonMethod where instance ToTagsBy 'Custom Rb.SingletonMethod where
tags' t@Rb.SingletonMethod tags' t@Rb.SingletonMethod
{ ann = loc@Loc { byteRange = range } { ann = loc@Loc { byteRange = Range { start } }
, name = expr , name
} = yieldMethodNameTag t loc range expr , parameters
} = yieldMethodNameTag t loc range' name
where
range' = case parameters of
Just Rb.MethodParameters { ann = Loc { byteRange = Range { end } }} -> Range start end
_ -> Range start (getEnd name)
getEnd = Range.end . byteRange . TS.gann
instance ToTagsBy 'Custom Rb.Block where instance ToTagsBy 'Custom Rb.Block where
tags' = enterScope False . gtags tags' = enterScope False . gtags