-
Notifications
You must be signed in to change notification settings - Fork 21
Fix search results that has only values #224
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
Conversation
src/components/UASTViewer.js
Outdated
// | ||
// for values (strings, ints, bool) we have to keep the wrapping node | ||
// otherwise it's not a tree and uast-viewer wouldn't be able to display it | ||
if (Array.isArray(rootNode.n) && rootNode.n.every(c => c.id)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably I'm missing something as I don't know much this part, but I don't understand this. In this condition, you're checking that rootNode.n
is an array and that each is element has an id
property that I guess is a proxy for checking that each element is a node. So this part:
// in case when all the results are nodes we can ignore wrapper node
// and display only results for better UI/UX.
is clear. The part that I don't understand is:
// for values (strings, ints, bool) we have to keep the wrapping node
// otherwise it's not a tree and uast-viewer wouldn't be able to display it
Shouldn't you return rootNode.n
if this rootNode.n.every(c => c.id)
it's not true?
if (Array.isArray(rootNode.n)) {
if (rootNode.n.every(c => c.id)) {
return rootNode.n.map(c => c.id);
} else {
return rootNode.n;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function returns root ids, not nodes.
If all the results are nodes it would return ids of them.
Otherwise, it would return null
and default root id (of the wrapper) would be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh ok! Thanks for the explanation!
src/components/UASTViewer.js
Outdated
// | ||
// for values (strings, ints, bool) we have to keep the wrapping node | ||
// otherwise it's not a tree and uast-viewer wouldn't be able to display it | ||
if (Array.isArray(rootNode.n) && rootNode.n.every(c => c.id)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that c.id
is 0
, making it false
? Would it be safer something like every(c => c.id !== undefined)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it's not possible. When we transform uast to flat json indexing starts with 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applied the suggestion in case the transformer logic would change in the future. 👍
Fix: #215 Signed-off-by: Maxim Sukharev <max@smacker.ru>
Fix: #215
Signed-off-by: Maxim Sukharev max@smacker.ru
This change is