Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up Pysa syntax highlighting #426

Closed
wants to merge 1 commit into from

Conversation

gracewgao
Copy link
Contributor

@gracewgao gracewgao commented May 11, 2021

The goal here is to highlight taint.config files as regular JSON files and highlight .pysa files using Python grammar rules with a couple of modifications.

To do this, I declared new languages for both file types in package.json, and made a TextMate file for each. For the taint.config, it includes the source.json scope for the entire file and inherits all the grammar rules so that it's essentially treated the same as a JSON file. For the Pysa files, I initially tried to include the Python grammar rules and define new ones on top of that, but there were a lot of conflicts between the scopes. It also seemed redundant to undefine already-defined rules and I think forking the rules directly would also allow for more flexible customization in the future.

So, I forked the official Python copy from here and made the following changes:

  • Highlighting feature annotations mentioned in these Pysa docs - TaintSource, TaintSink, TaintInTaintOut, Sanitize, Via, AttachToSource, AttachToSink, AttachToTito, AddFeatureToArgument, ViaValueOf, WithTag, ViaDynamicFeature as part of the support.class.pysa scope
  • Highlighting fully-qualified function names as part of the entity.name.function.pysa scope
  • Removing self, type, __init__ from the Python grammar rules

For more information about naming conventions of scopes, check the TextMate scope docs.

Here are some screenshots from running the extension in my VSCode environment:

Highlighting for feature annotations:

Highlighting for fully-qualified functions

Highlighting for fully-qualified functions:

Highlighting for feature annotations

Highlighting for taint.config files:

Highlighting for taint.config files

Let me know if I missed anything or if you have any other ideas for syntax highlighting!

tools/ide_plugins/pysa-vscode/language-configuration.json Outdated Show resolved Hide resolved
tools/ide_plugins/pysa-vscode/language-configuration.json Outdated Show resolved Hide resolved
tools/ide_plugins/pysa-vscode/language-configuration.json Outdated Show resolved Hide resolved
tools/ide_plugins/pysa-vscode/package.json Outdated Show resolved Hide resolved
tools/ide_plugins/pysa-vscode/package.json Outdated Show resolved Hide resolved
tools/ide_plugins/pysa-vscode/package.json Outdated Show resolved Hide resolved
@@ -0,0 +1,4007 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor

@gbleaney gbleaney May 12, 2021

Choose a reason for hiding this comment

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

Can you point out which specific lines you changed? Maybe the output of diff or something? It'll be too cumbersome to review a whole fork of a 3k line file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, for sure - I've made a gist here to compare the differences. To summarize, I basically just changed the scope names to be pysa rather than python, fixed the UUID, and made all the other changes I mentioned in the PR description.

tools/ide_plugins/pysa-vscode/syntaxes/Pysa.tmLanguage Outdated Show resolved Hide resolved
tools/ide_plugins/pysa-vscode/package.json Outdated Show resolved Hide resolved
@facebook-github-bot
Copy link
Contributor

@gbleaney has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@gracewgao has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@gracewgao has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@gbleaney gbleaney left a comment

Choose a reason for hiding this comment

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

Looking pretty good! Just a few more changes and then I think we're good to land

<array>
<dict>
<key>comment</key>
<string>feature annotations in Pysa</string>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<string>feature annotations in Pysa</string>
<string>Taint and Feature keywords in Pysa</string>

@facebook-github-bot
Copy link
Contributor

@gracewgao has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@gbleaney has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@gbleaney
Copy link
Contributor

LGTM now. Thanks for the quick turnaround. It'll go through our internal review process now, so there may be a couple more comments, but we're on the path to landing!

@facebook-github-bot
Copy link
Contributor

@gbleaney merged this pull request in 375ceeb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants