Skip to content
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

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

Open
core-ai-bot opened this issue Aug 29, 2021 · 9 comments

Comments

@core-ai-bot
Copy link
Member

Issue by peterflynn
Wednesday Apr 24, 2013 at 00:06 GMT
Originally opened as adobe/brackets#3573


  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.

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Wednesday Apr 24, 2013 at 00:07 GMT


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

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Thursday Apr 25, 2013 at 19:03 GMT


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

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Thursday May 02, 2013 at 20:29 GMT


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

@core-ai-bot
Copy link
Member Author

Comment by eztierney
Tuesday May 07, 2013 at 16:49 GMT


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.

@core-ai-bot
Copy link
Member Author

Comment by lkcampbell
Saturday Oct 26, 2013 at 12:22 GMT


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.

@core-ai-bot
Copy link
Member Author

Comment by lkcampbell
Saturday Oct 26, 2013 at 12:30 GMT


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

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Monday Oct 28, 2013 at 15:10 GMT


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

@core-ai-bot
Copy link
Member Author

Comment by lkcampbell
Monday Oct 28, 2013 at 16:51 GMT


@peterflynn, do you think this problem is a duplicate of adobe/brackets#5263 or can you repro the problem when the code is properly indented as well?

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Monday Mar 17, 2014 at 19:47 GMT


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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant