-
Notifications
You must be signed in to change notification settings - Fork 377
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
Comments
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 |
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. |
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? |
I do that already. First, |
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. |
If I remove the dot and the last 'e' of See http://marijnhaverbeke.nl/blog/parse-dammit.html for details on the error-tolerant parser. |
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 |
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 :) |
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?). |
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. |
Moral of story, don't have mess indentation. |
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... |
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. |
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?". |
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";
});
The text was updated successfully, but these errors were encountered: