Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

[JS code hints] Argument type guessing is too ambitious sometimes #3573

Closed
peterflynn opened this issue Apr 24, 2013 · 9 comments
Closed

[JS code hints] Argument type guessing is too ambitious sometimes #3573

peterflynn opened this issue Apr 24, 2013 · 9 comments
Assignees

Comments

@peterflynn
Copy link
Member

  1. Open the Brackets src folder
  2. Open QuickOpen.js
  3. Insert the following code just below the QuickOpenPlugin() constructor:
    function foo(a, b) {
        return a + b;
    }
    foo(
  1. Press Ctrl+space after the (

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.

@peterflynn
Copy link
Member Author

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"?

@dangoor
Copy link
Contributor

dangoor commented Apr 25, 2013

Reviewing code hinting issues. I think this one is medium priority because it's a case where the information displayed is not correct.

@ghost ghost assigned eztierney May 2, 2013
@peterflynn
Copy link
Member Author

Reviewed. Assigned @eztierney as placeholder for LCVM team in general (we still need to add the others to the GitHub org).

@eztierney
Copy link
Contributor

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.

@ghost ghost assigned dangoor Oct 26, 2013
@lkcampbell
Copy link
Contributor

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
Copy link
Contributor

Testing this issue in Sprint 32, I discovered that indentation might be playing a role in the problem.

When I do not indent the newly inserted test, I get the wrong parameters:

incorrect

When I indent the newly inserted text properly, the parameters are correct:

correct

@dangoor
Copy link
Contributor

dangoor commented Oct 28, 2013

@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.

@lkcampbell
Copy link
Contributor

@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?

@dangoor
Copy link
Contributor

dangoor commented Mar 17, 2014

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).

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

No branches or pull requests

4 participants