GithubHelp home page GithubHelp logo

Comments (14)

MiguelCastillo avatar MiguelCastillo commented on July 26, 2024

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

from tern.

marijnh avatar marijnh commented on July 26, 2024

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.

from tern.

peterflynn avatar peterflynn commented on July 26, 2024

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?

from tern.

marijnh avatar marijnh commented on July 26, 2024

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.

from tern.

MiguelCastillo avatar MiguelCastillo commented on July 26, 2024

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.

from tern.

marijnh avatar marijnh commented on July 26, 2024

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.

from tern.

MiguelCastillo avatar MiguelCastillo commented on July 26, 2024

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

from tern.

MiguelCastillo avatar MiguelCastillo commented on July 26, 2024

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

from tern.

dgutov avatar dgutov commented on July 26, 2024

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

from tern.

marijnh avatar marijnh commented on July 26, 2024

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.

from tern.

zchrykng avatar zchrykng commented on July 26, 2024

Moral of story, don't have mess indentation.

from tern.

MiguelCastillo avatar MiguelCastillo commented on July 26, 2024

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

from tern.

zchrykng avatar zchrykng commented on July 26, 2024

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.

from tern.

dgutov avatar dgutov commented on July 26, 2024

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

from tern.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.