Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Implement PrintAST for Go #260

Closed
aeisenberg opened this issue Jul 16, 2020 · 14 comments · Fixed by #262
Closed

Implement PrintAST for Go #260

aeisenberg opened this issue Jul 16, 2020 · 14 comments · Fixed by #262
Assignees

Comments

@aeisenberg
Copy link
Contributor

This issue is about adding support to the CodeQL VS Code extension for viewing ASTs of Go files. See the parent issue github/vscode-codeql#492.

@aeisenberg
Copy link
Contributor Author

See also #179.

@aeisenberg
Copy link
Contributor Author

I have created a simple printAst.ql contextual query for Go and things are generally working quite nicely. However, there are a few rough edges:

  1. Comments are included in the ast. I'm not very familiar with go, so maybe that's something users expect, but from my perspective it clutters things up.
  2. Also, comment nodes all seem to be top-level (ie- even if they are inside a function, they don't have a parent node)
  3. And, it looks like all files are being returned in the ast, even though I am only requesting a single file at a time.
  4. Looks like lists of ParameterDecl and ResultVariableDecl are reversed order. Eg- func unquoteBytes(s []byte) (t []byte, ok bool) lists ok first and s last.

I'll create a PR for the query I am using and hopefully we can use this to debug these issues.

@smowton
Copy link
Contributor

smowton commented Jul 20, 2020

Re: no. 4, this should fix it: #263

@smowton
Copy link
Contributor

smowton commented Jul 20, 2020

Re: no. 3, how about #264 ?

Comments are still second level (children of Files but not of anything else). This is how the Go parser describes them -- we'd have to use source location information, which might be a bit brittle, to give them a better parent. Does that cause you much trouble? I could add a skipComments option to the config if you want?

@aeisenberg
Copy link
Contributor Author

Thanks for the related PRs.

Regarding comments in the AST, I'm not an avid go user (I haven't done much more than the intro tutorials a few years ago), so it's hard to know how useful they are. My thoughts are that if comments are regularly returned as useful results in codeql-go queries, then we should include them in the AST. If they're not (or rarely are), then let's remove them. More precisely, only if comments are regularly involved with security issues, let's keep them.

It all depends on what users expect and what they find useful.

@smowton
Copy link
Contributor

smowton commented Jul 20, 2020

I'm not aware of any existing query where we pay attention to them. Do you want a flag in the config to omit them, or is it simple to omit them your side?

@aeisenberg
Copy link
Contributor Author

I think it is reasonable to have the printAst.ql query from #262 determine which ast types it will include. Though, not sure how to specify that in the PrintAstConfiguration. Do you have a suggestion? Maybe a flag is the only way, though.

@sauyon
Copy link
Contributor

sauyon commented Jul 20, 2020

This is how the Go parser describes them -- we'd have to use source location information, which might be a bit brittle, to give them a better parent.

Is that the case? The Go AST library provides CommentMap, which seems like the natural way to parent comment groups.

@smowton
Copy link
Contributor

smowton commented Jul 21, 2020

Ah nice, ok so we're using an old API that describes comments only as File children, but there's a better one that will give them best-possible parents. For now do you just want me to add a configuration filter for commentgroups?

@aeisenberg
Copy link
Contributor Author

I think that would be easiest from my perspective.

@smowton
Copy link
Contributor

smowton commented Jul 21, 2020

Alright, coming up

@smowton
Copy link
Contributor

smowton commented Jul 21, 2020

Added to #264 along with the refinements suggested by @sauyon

@smowton
Copy link
Contributor

smowton commented Jul 28, 2020

@aeisenberg you ok with marking this done?

@aeisenberg
Copy link
Contributor Author

We're done here. Thanks!

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 a pull request may close this issue.

3 participants