-
Notifications
You must be signed in to change notification settings - Fork 353
dot chained calls are not indented correctly #139
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
Comments
Don't bother; I think this (indenting the chained calls) should be the default behaviour, we'll likely add support if the other maintainers agree. |
I would love this functionality as well, unfortunately I haven't been able to spend the time to figure out how the indent files actually work, so I am unable to fix at the this time. |
👍 I would have done this already if simply adding a regex would work... alas the indentation logic is quite complicated. |
yes it is. Although I can probably get this in, it should be similar to the comma logic. |
A great feature that is missing! +1 |
Any news on this one? |
+1 would love this |
I would also greatly appreciate this feature +1 |
+1 |
I'm not a vim scripter, but I have some very basic support for this here: https://github.com/doxavore/vim-javascript/tree/dot-chained-indent It handles things like one()
.then(two)
.then(function() {
}) But stumbles a little with the original example, creating: one()
.then(two)
.then(function() {
})
.fail(failHandler) If someone has some time to work on this, perhaps it will offer a start. |
Nice work doxavore. That is partially working for me. If I visually select a group it will correctly format things with an = call. However, it doesn't help if I'm writing a statement like this:
and then hit enter and type, I end up with this.
I'm also not really a Vim Scripter and not sure how plugins handle this sort of eventuality. |
+1 |
I really need to get around to learning how the indentation stuff works, because the absence of this feature has been bothering me for months. I'll try to look into it tonight. We'll see if I can't shake a stick at implementing decent behaviour for this. |
@qstrahl I've poked around a bit in the file, and it's not gonna be an easy task. As for everyone else in this thread, the person who wrote the indent logic for this originally is no longer contributing to the project. So editing/updating it is going to require one or some of us to figure it out. And it's been tough to find time to do this. Please note we aren't just ignoring the issue, I would love this feature too. |
Hey everyone maybe this is a good time to figure out and document some of the steps for testing this. seems like it would help us understand the code better. javascript has a pretty flexible syntax as many of us are aware and i'll bet a lot of it is not explicit, plus vimscript is witchcraft (this plugin is pretty hairy too, at least to me), and the creator is gone, so seems like a good reason to test some of this out. I'll try to figure something out tonight or tomorrow night, with the caveat that i have never made anything but the most trivial vimscripts. |
So, after taking a look at our indent file and vim's help files on indenting, I can see that our indent file kinda sorta does some of what I was thinking of doing. Basically, it uses a combination of regexes and keywords and syntax group cues to determine what the indent should be. I think we can cut that down to just using syntax cues. That is, we'll have a list of syntax items that, if the line ends with them, you should indent up/down. I don't think we need to be more specific than that, but if we do, I'm sure very very simple syntax patterns will be enough. I'm going to do a little more investigation (asking Freenode#vim) to see if this approach is a terrible idea, because I suspect it might be -- I think vim wants syntax and indent to be separate concerns. If this is the case, we can put it to a vote whether or not we care. =P |
@qstrahl Hey if it works it works, no need for my vote :) |
@jeffrom The issue (if there really is an issue) would be that you need to have syntax enabled in order for indent to work, which might be counter to what vim (and by extension, a vim user) expects. If that's the case, I feel it's important to have a consensus from users/devs before implementing, even if I'm pretty sure no modern editor has any such expectation of indent/syntax being separate concerns. =P |
I don't think there is any reliable way to do this and not force semi-colons (without tricks like syntax). Now for me that's totally okay since I like semi-colons (for this very reason) but many developers prefer the more renegade style of flexing JavaScript's auto semi-colon insertion (ASI). Thoughts? |
If it starts with a dot, indent. This is probably not bullet proof however. |
@goatslacker good point. I guess I took for granted that the dot can also be trailing. Investigating... |
So I did this for leading commas and it worked for 80% of the use cases, not sure if dot would be the same case or not. I haven't fully thought this through. Trailing dot wouldn't work, but I guess if the dot is trailing you could also indent. I think this is the current behaviour actually. |
Most style guides depict chained methods to have a leading dot ans be indented on level deeper then the initial statement. This patch adds a period as a key symbol for a nested indent. In the same fashion as the leading comma does. It allows an indent of the following: var x = { x: 'foo', y: 'bar', z: (function() { return [1, 2, 3] .map(toFruits) .compact() .sortBy('color'); })() }; This should close issue pangloss#139.
@goatslacker see PR #248. My dev tests show this as working. |
Any update on this? I'd be happy to spend some time getting this working. |
@devm33 No progress, I've learned to live with the dot as a line prefix not a suffix. |
Any progress on this issue? I'm having the same problem. |
+1 |
1 similar comment
+1 |
Had to build my own fix for the dot start https://github.com/randunel/vim-javascript. Would be nice to include something similar in this lib though. |
+1 |
@randunel Is that something you could make a pull request out of? How well does it work? |
+1 |
generally this will give us fairly accurate indents without having specific code for each operator.Thanks to pangloss#139 (comment) which this is based on I think this needs a few things before it's ready
generally this will give us fairly accurate indents without having specific code for each operator.Thanks to pangloss#139 (comment) which this is based on
generally this will give us fairly accurate indents without having specific code for each operator.Thanks to pangloss#139 (comment) which this is based on
generally this will give us fairly accurate indents without having specific code for each operator.Thanks to pangloss#139 (comment) which this is based on Update javascript.vim
generally this will give us fairly accurate indents without having specific code for each operator.Thanks to pangloss#139 (comment) which this is based on Update javascript.vim
generally this will give us fairly accurate indents without having specific code for each operator.Thanks to pangloss#139 (comment) which this is based on Update javascript.vim
generally this will give us fairly accurate indents without having specific code for each operator.Thanks to pangloss#139 (comment) which this is based on Update javascript.vim
a problem no longer |
A hero in our time |
So is this a case of squeaky wheel gets the grease? I liked the original behaviour better, can it be restored, maybe with a variable? |
|
When chaining calls together via the
.
operator, the following lines are not indented correctlyDesired
Current
Is there a way I can add a custom regular expression to perform additional indentation after the standard vim-javascript indent plugin has finished? Adding an additional two spaces to any line that begins with
.
would be a vast improvementThe text was updated successfully, but these errors were encountered: