-
Notifications
You must be signed in to change notification settings - Fork 184
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
feature request: Injected code - Indentation of final whitespace-only line #280
Comments
Can you give #340 a try and see if it fixes your issue? |
Thank you @stevearc, but it doesn't seem to be working quite right: If I start with this: class Example1:
def test():
query = """
select
a
from
table1
""" and format it once it becomes (an extra new line inserted right before the final line): class Example1:
def test():
query = """
select
a
from
table1
""" A second time it becomes (An extra new line is inserted after the spaces of the final line): class Example1:
def test():
query = """
select
a
from
table1
........ # This line has 8 spaces
""" And formatting a 3rd time becomes (removing the line with just spaces): class Example1:
def test():
query = """
select
a
from
table1
""" This is then stable without further changes. I think the approach your just ignoring the last line of whitespace is probably the better and more conservative approach and less likely to cause issues for other people than my more aggressive suggestion of copying indentation whitespace from the |
Interesting...I tried using your injection and formatting that exact example and it's working perfectly for me. I'm using sql-formatter 15.3.0. Could you check that version and also set your
|
Sorry, that was on me. I forgot I wrote a custom python script parser which was the issue. When I use sql_formatter, it works just like you said! My python script is supposed to be a pretty basic wrapper for sql-formatter that just stops the formatter from splitting up 1-line queries into multiple lines so
Yeah, seems like my formatter is kicking back an extra new line at the end which kicks off the whole sequence of corrections. Thanks so much for your help and the great plugin you created! |
I modified my parser to do:
And now it all works perfectly, even with my custom parser. |
Great news! |
Did you check existing requests?
Describe the feature
I'd like to adjust how
confirm.nvim
handles a final whitespace-only line of injected code in order to prevent the end quotes from getting no indentation at all. Especially in python, its odd to see elements of an otherwise indented block of code having 0 indentation. Also, how much whitespace this final line has effects the indentation of the rest injected section.Provide background
Here is an example of what formatting SQL code inside of python code looks like today if strings aren't defined at a global level (without indentation). Here is my example config:
And I format the following code:
And this is the results:
The important things to notice are
"""
was indented prior to formatting determines how much indentation theselect
ends up with"""
has been moved all the way to the left despite being in a code block that is all indented 8 spaces.What I'd like to see happen instead:
"""
should have nothing to do with what the formatter sent back (maybe that is true already). But, instead of ending up with 0 indentation, it should match indentation level ofquery = """
line at the start of the injected block, unless there are other things in the injected code at the 0 indentation level. Then it'd be okay to leave the final"""
at 0. I say this last exception because in python all that extra whitespaces is actually part of the variable that is getting defined, so I suppose someone might not like their variable to contain a ton of extra whitespace characters in the string.What is the significance of this feature?
nice to have
Additional details
No response
The text was updated successfully, but these errors were encountered: