Comments (14)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Moral of story, don't have mess indentation.
from tern.
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.
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.
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)
- [Bug] The autocompletion for prototype HOT 3
- [BUG] defining the type for the argument of a function HOT 4
- how can i make any use of the !url tag?
- Tern plugin not avaliable in Jenkins
- require.js + defs
- es6 class arrow function method TypeError
- Function information tooltip
- No autocomplete on my objects HOT 2
- Failed to launch development process with webpack after installing tern@latest npm package HOT 2
- Bug fixed. Wrong filename for jump to definition
- acorn-lose error with tern 0.23.3 or up HOT 2
- Simple text search for tern HOT 4
- Is there any way to analyzed code in runtime?
- mix type definitions
- Using `es_modules` and `node` plugin together breaks jump to definition in some cases
- Jump to definition doesn't work from `export` es6 syntax
- Is Tern.js library in active development/support? HOT 9
- Tern not identifying js property references in the given case
- Avoid duplicate name definition
- Upgrade `glob` version to avoid memory leak.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tern.