mirror of
https://github.com/github/semantic.git
synced 2024-12-11 08:45:48 +03:00
Cherry-pick cec6c73ea086e3cd5f164d612666c95ee0cc0ae7
This commit is contained in:
parent
834ecd717e
commit
d581f5a70b
@ -123,23 +123,26 @@ declarationAlgebra :: (Declaration.Function :< fs, Declaration.Method :< fs, Syn
|
||||
=> Blob
|
||||
-> RAlgebra (TermF (Union fs) (Record fields)) (Term (Union fs) (Record fields)) (Maybe Declaration)
|
||||
declarationAlgebra Blob{..} (a :< r)
|
||||
-- Do not summarize anonymous functions
|
||||
| Just (Declaration.Function _ (identifier, _) _ _) <- prj r
|
||||
, Just Syntax.Empty <- prj (unwrap identifier)
|
||||
= Nothing
|
||||
|
||||
-- Named functions
|
||||
| Just (Declaration.Function _ (identifier, _) _ _) <- prj r
|
||||
= Just $ FunctionDeclaration (getSource (extract identifier))
|
||||
|
||||
-- Methods without a receiver
|
||||
| Just (Declaration.Method _ (receiver, _) (identifier, _) _ _) <- prj r
|
||||
, Just Syntax.Empty <- prj (unwrap receiver)
|
||||
= Just $ MethodDeclaration (getSource (extract identifier))
|
||||
|
||||
-- Methods with a receiver (class methods) are formatted like `receiver.method_name`
|
||||
| Just (Declaration.Method _ (receiver, _) (identifier, _) _ _) <- prj r
|
||||
= Just $ MethodDeclaration (getSource (extract receiver) <> "." <> getSource (extract identifier))
|
||||
|
||||
| Just err@Syntax.Error{} <- prj r
|
||||
= Just $ ErrorDeclaration (T.pack (formatTOCError (Syntax.unError (sourceSpan a) err))) blobLanguage
|
||||
|
||||
| otherwise = Nothing
|
||||
where getSource = toText . flip Source.slice blobSource . byteRange
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user