X Tutup
The Wayback Machine - https://web.archive.org/web/20260201035710/https://github.com/github/semantic/pull/586
Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Conversation

@aymannadeem
Copy link
Contributor

@aymannadeem aymannadeem commented Jun 30, 2020

  • Update Data.Language
  • Update Parsing.Parser
  • Add running tests for rust to haskell.yml
  • [ ] Add custom ToTags instances for Language.Rust.Tags
  • darkship rust flag
  • lingo flag

@github/semantic-code can someone with more context/experience on this point me to things I've missed?

@rewinfrey
Copy link
Contributor

@aymannadeem I think the main thing is adding ToTags instances for the various Rust syntaxes we want to surface. This patch adding CodeQL support might be helpful https://github.com/github/semantic/pull/507/files. There are some additional changes we'll want to do on internal services (and best to move those conversations to those repos).

Copy link
Contributor

@patrickt patrickt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great start!

My recommendation, before you start fixing anything mentioned below, is to come up with a set of example .rs files that collectively exercise all the syntax types for which you’ve defined instances, commit them to a folder in the repository, and (ideally, but perhaps optionally) define .json fixtures and check that they’re commensurate with the tags output. This has the advantage of giving you a tight compile-test cycle as well as a guide to what we need and don’t need to tag.

_ -> pure ()
case name of
EPrj (Rust.Identifier {text, ann}) -> yield text ann
EPrj (Rust.Metavariable {text, ann}) -> yield text ann
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know exactly what a Metavariable appearing as the name of a function entails? Is it always going to be useful information?

Comment on lines +105 to +110
case returnType of
Just (Parse.Success type') -> gtags type'
_ -> pure ()
case typeParameters of
Just (Parse.Success typeParams) -> gtags typeParams
_ -> pure ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It occurs to me that you can elide these pattern matches entirely and just rely on gtags—instead of calling gtags block at the end, call gtags t, and the returnType and typeParameters and all its friends will be iterated automatically. (But check before and after and make sure the resulting trees are still correct!)

ann = loc@Loc {byteRange},
body = Parse.Success bod,
name = Parse.Success (Rust.TypeIdentifier {text, ann})
} = yieldTag text P.FUNCTION P.DEFINITION ann byteRange >> gtags t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not P.FUNCTION here, since this is a case of an enumeration… but honestly, I have no idea which SyntaxType we should use for this case. Maybe we should add a new one? Perhaps @tclem has some thoughts.

{ ann = loc@Loc {byteRange},
name = Parse.Success (Rust.FieldIdentifier {text, ann}),
type' = Parse.Success type''
} = yieldTag text P.FUNCTION P.DEFINITION ann byteRange >> gtags t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

EPrj (Rust.Identifier {text, ann}) -> yield text ann
EPrj (Rust.Metavariable {text, ann}) -> yield text ann
where
yield name ann = yieldTag name P.FUNCTION P.DEFINITION ann byteRange >> gtags t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to say whether this is the right thing without knowing what a FunctionSignatureItem constitutes.

_ -> pure ()
gtags t
where
yield function ann = yieldTag function P.FUNCTION P.DEFINITION ann byteRange >> gtags t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you only use this yield call in one place, you could remove it from the where if you liked.

Comment on lines +200 to +225
instance ToTags Rust.StructItem where
tags
t@Rust.StructItem
{
ann = loc@Loc {byteRange},
body,
name = Parse.Success (Rust.TypeIdentifier {text, ann})
} = yieldTag text P.FUNCTION P.REFERENCE ann byteRange >> gtags t

instance ToTags Rust.UnionItem where
tags
t@Rust.UnionItem
{
ann = loc@Loc {byteRange},
body,
name = Parse.Success (Rust.TypeIdentifier {text, ann})
} = yieldTag text P.FUNCTION P.DEFINITION ann byteRange >> gtags t

instance ToTags Rust.TraitItem where
tags
t@Rust.TraitItem
{
ann = loc@Loc {byteRange},
body,
name = Parse.Success (Rust.TypeIdentifier {text, ann})
} = yieldTag text P.FUNCTION P.DEFINITION ann byteRange >> gtags t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar uses of P.FUNCTION here that we don’t want.

Comment on lines +122 to +129
tags
t@Rust.CallExpression
{
ann = loc@Loc {byteRange},
function = Parse.Success expr,
arguments = Parse.Success args
} = gtags expr
tags _ = pure ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, too, I think we can just call gtags t—or, since that’s equivalent to the default instance, drop it entirely.

@aymannadeem
Copy link
Contributor Author

Going to pause this work for now in leiu of https://github.com/github/aleph/pull/503

@robrix robrix closed this Aug 25, 2021
@robrix robrix deleted the ship-rust branch August 25, 2021 13:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

X Tutup