-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[JS code hints] Argument type guessing is too ambitious sometimes #3573
Comments
Also, as an aside... I'm not sure how to interpret type hints like "String.prototype" or "Event.prototype." Does that mean something different from just "String" or "Event"? |
Reviewing code hinting issues. I think this one is medium priority because it's a case where the information displayed is not correct. |
Reviewed. Assigned @eztierney as placeholder for LCVM team in general (we still need to add the others to the GitHub org). |
Oh my. I think what is happening is that tern is parsing the function declarations after 'foo(' as the arguments to 'foo'. The next function is function addQuickOpenPlugin(pluginDef) { ... } Which explains where the fn(pluginDef) hint comes from. And if I move the call to 'foo' around then the hints change based on what function decls come next, probably because they look like function expressions which are being passed to the function. And if you close the parens, 'foo()' then you get the correct hints. Clearly this isn't ideal, though I'm not quite sure how to fix this yet. |
I reassigned this issue to @dangoor to workaround an issue with GitHub. Nobody could add comments to this issue. I followed up with GitHub support and they suggested assigning the issue to someone who still has permissions to commit to brackets. I don't know exactly what @eztierney has as permissions, but I do know @dangoor has permission to work on brackets, so let's see if this fixes the problem... Update: Yes, that fixed the problem. |
@lkcampbell I opened an issue with Tern previously about whitespace sensitivity. Marijn said that the loose Acorn parser is sensitive to whitespace, but fixing it would be a lot of work. |
@peterflynn, do you think this problem is a duplicate of #5263 or can you repro the problem when the code is properly indented as well? |
Following the original repro steps, this problem no longer reproduces. It's quite possible (likely?) that this is because the contents of QuickOpen.js have changed, because I think this problem original was the whitespace sensitivity issue as listed above. I'm going to close this now... @peterflynn feel free to reopen or open a fresh one if you encounter this again and it does not appear to be whitespace related). |
(
Result: hint suggests the arguments are of type "fn:(pluginDef: ?)" and "fn()" respectively.
Expected: if I place the same code at the top or bottom of the module, it says "?" for both types.
It seems to vary a lot by position within the file. If I place the code after _filenameFromPath() I get "fn(query: String.prototype) -> number" and "fn() -> [?]" instead. It seems like the first argument is always inferred to be essentially a function with the same signature as whatever function came right before foo() in the code. I'm not sure why it would make sense to guess that, though.
The text was updated successfully, but these errors were encountered: