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

Hints are not coming up in demo app #63

Closed
MiguelCastillo opened this issue Apr 15, 2013 · 14 comments
Closed

Hints are not coming up in demo app #63

MiguelCastillo opened this issue Apr 15, 2013 · 14 comments

Comments

@MiguelCastillo
Copy link

  1. Launch demo app
  2. Copy and paste the code below
  3. Go to the end of line 3, which should end with "javascript";
  4. Press enter to get you to the next line.
  5. Type jsMode
  6. Type . and press Ctrl+Space.

Result, no hints come up.
Expected, hints for a string type should come up.

To see expected results, step 4 should be
4. Press enter to get you to the next line, press tab.
5. Type jsMode
6. Type . and press Ctrl+Space

Result, full hints will come up.

Sample code

define(function (require, exports, module) {
"use strict";
var jsMode = "javascript";

});

@MiguelCastillo
Copy link
Author

When copying the sample code, spaces are not properly copied and the issue cannot be reproduced... So, you can use this file https://github.com/MiguelCastillo/Brackets-Tern/blob/build/test/noAutocomplete.js

With this file, place your cursor on line 4 right after the dot. Press Ctrl-Space and you will not get hints, which is this issue being reported.

-Miguel

@marijnh
Copy link
Member

marijnh commented Apr 16, 2013

That has to do with the messy indentation. The error-tolerant parser uses indentation to try and compensate for missing braces, and it will consider the function block to close when the 4th line dedents compared to the first two lines.

The heuristics in acorn/acorn_loose.js could probably be improved, but the fundamental fact that a parser that uses indentation to guess structure can be confused by bad indentation won't be gotten around.

@peterflynn
Copy link

What if you ignore the heuristics if the code can be successfully parsed without errors (i.e. heuristics are unneeded)? Or does the code pass through invalid states so often while typing that it wouldn't help much to do that?

@marijnh
Copy link
Member

marijnh commented Apr 17, 2013

I do that already. First, acorn.parse gets a chance to parse the file. If that fails (in your example because of the trailing dot with no property name after it), acorn.parse_dammit kicks in.

@MiguelCastillo
Copy link
Author

The dot is there as a convenience. You could remove the dot and add it again to trigger the request for hints, which will result in an empty list.

I am rather unfamiliar as to why a parser takes indentation into account to guess structure. Could you please share some knowledge? What's the role of code structure in the parsing process?

Good or bad, indentation is to be expected when dealing with code, so it might be worth giving this issue a second look.

@marijnh
Copy link
Member

marijnh commented Apr 19, 2013

The dot is there as a convenience. You could remove the dot and add it again to trigger the request for hints, which will result in an empty list.

If I remove the dot and the last 'e' of jsMode, and then complete, it'll complete to jsMode as expected.

See http://marijnhaverbeke.nl/blog/parse-dammit.html for details on the error-tolerant parser.

@MiguelCastillo
Copy link
Author

Well, at this point I see that you understand the issue I am reporting. Hopefully, which you always end up doing anyways, you will come up with a sweet solution.

Thanks dude

@MiguelCastillo
Copy link
Author

BTW, if you want to hack something together to get some feedback on and need someone to test the life out of it, I will happily volunteer :)

@dgutov
Copy link
Contributor

dgutov commented Apr 22, 2013

@marijnh

If I remove the dot and the last 'e' of jsMode, and then complete, it'll complete to jsMode as expected.

I think the point @MiguelCastillo is trying to make is that you could, in theory, remove the obvious syntax error in the completion front-end before handing off the text to the parser. And after it parses, walk the AST to find the node before the cursor, based on the character position. This way, the error correction will only be used if there are some other syntax errors in the file.

Another option, I guess, would be to special-case the situation of no property name after a dot and not consider it a syntax error, or at least not try to recover from it the way you described. After all, when you encounter syntax errors other than extra/missing braces, looking at indentation won't improve things (right?).

@marijnh
Copy link
Member

marijnh commented Apr 26, 2013

Short story: Tern will occasionally get confused if your indentation is a mess. Wonfix, since I don't have a plan for how to fix it.

@marijnh marijnh closed this as completed Apr 26, 2013
@zchrykng
Copy link

Moral of story, don't have mess indentation.

@MiguelCastillo
Copy link
Author

Seems reasonable to me to close it with no plan to fix, but the moral of the story seems wrong... A hinting engine should NOT dictate indentation in your code; that's completely flawed...

@zchrykng
Copy link

I was not saying the engine should dictate that, but it seems that if you have code that is indented in a logical manner you will not have these issues.

But then again, I have been learning Python recently and if you don't indent properly you are doa.

@dgutov
Copy link
Contributor

dgutov commented Apr 26, 2013

Good indentation is mandatory, of course, but various things can happen when you're just writing the line for the first time. Sometimes you may prefer to indent it after the fact (Emacs makes that easy), and sometimes you're just exploring the API and will delete that piece of code soon afterwards. The problem with relying on indentation is, it's counter-intuitive, and a person may get stuck for a while wondering "why doesn't this work?".

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

5 participants