Use the value not the label for the print ast node#666
Conversation
adityasharad
left a comment
There was a problem hiding this comment.
Generally looks good, some questions about fallback behaviour and testing.
| const item = { | ||
| id, | ||
| label: entity.label, | ||
| label: value, |
There was a problem hiding this comment.
What happens if we have an AST query that doesn't set semmle.label on its nodes? For example
query predicate nodes(Node node) { ... }
In that case I would expect value here to be falsy, and I suggest we fall back to entity.label in that default case.
There was a problem hiding this comment.
Sounds reasonable.
There was a problem hiding this comment.
To clarify: I think we should handle that in the default: case too, in case semmle.label is not set at all.
There was a problem hiding this comment.
I don't think that's the behaviour we want. Right now, I don't know what the other kind of labels there are, but we don't want them to overwrite whatever is in the semmle.label. And more importantly, we don't even know what would be in the value field and if it makes any sense to display.
There was a problem hiding this comment.
If we can assume all AST queries follow this pattern:
query predicate nodes(Node node, string key, string value) {
key = "semmle.label" and ...
}
then the nodes table will have tuples with semmle.label set, and this PR is good to go.
I am trying to be cautious about the possibility that no such label is set, which will happen if you write:
query predicate nodes(Node node) { ... }
In that case I think we'd have to create an item under the default: case of the switch in this code, which uses entity.label. Perhaps that's not something we need to handle in this PR if we know it won't arise from any of the implementations.
There was a problem hiding this comment.
If an entity does not have a semmle.label tupleType, then I think this is a bug. As far as I know existing languages all borrow from the cpp implementation which always creates a semmle.label for each node. This is not mentioned in the specs and maybe we should clarify.
There was a problem hiding this comment.
71a7642 to
e7ad3e4
Compare
e7ad3e4 to
3b39e6e
Compare
adityasharad
left a comment
There was a problem hiding this comment.
I'm convinced! Ship it.
Fixes #659
Checklist
@github/docs-content-dsphas been cc'd in all issues for UI or other user-facing changes made by this pull request.