vsc-python-indent
vsc-python-indent copied to clipboard
Broken indentation of continuation lines
If I have the following code
sql = ('SELECT mode FROM pg_locks JOIN pg_class '
'ON pg_class.oid = pg_locks.relation '
'JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace '
f'WHERE pg_class.relname = {table_name!r} '
f'AND pg_namespace.nspname = {schema!r};')
And press tab I would expect the whole block to be indented four spaces, maintaining the lines alined. Instead I get
sql = ('SELECT mode FROM pg_locks JOIN pg_class '
'ON pg_class.oid = pg_locks.relation '
'JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace '
f'WHERE pg_class.relname = {table_name!r} '
f'AND pg_namespace.nspname = {schema!r};')
Not sure if this is a larger VSCode problem (it does the same without Python Indent). Is there any way to get this to work?
Not sure if this is a larger VSCode problem (it does the same without Python Indent).
This is definitely an issue with how VSCode behaves, but we might be able to override the behavior here.
If you want to look into it I'd be happy to review an MR that adds this functionality.
Sounds good. I'm very unexperienced with TS and the VSCode API, but I can give it a try.
I actually just ran into a case similar to this where I think we'd need to be careful:
I wanted to refactor some code that looked like this
my_list = some_function(
[some_long_function(x)
for x in my_other_list]
)
into this:
my_list = some_function(
[
some_long_function(x)
for x in my_other_list
]
)
As an intermediate step, I found myself in this position (|
represents the cursor):
my_list = some_function(
[
some_long_function(x)
|for x in my_other_list
]
)
In this case, I would expect the status quo behavior -- VSCode adds exactly three spaces when I press tab, which is what I want in this case. We'd need to make sure behavior like this isn't broken. Maybe it'd be best if you start any MR with a full description of the behavior you're aiming for before spending too much time trying to learn typescript / VSCode APIs.
Using his code snippet from above, perhaps I can clarify what is requested:
ttt,sql = ('SELECT mode FROM pg_locks JOIN pg_class ' ttt,ttt,---'ON pg_class.oid = pg_locks.relation ' ttt,ttt,---'JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace ' ttt,ttt,---f'WHERE pg_class.relname = {table_name!r} ' ttt,ttt,---f'AND pg_namespace.nspname = {schema!r};')
"ttt," is 4-spaces as part of a tab (3 t's and a comma for my eyes) and "-" is white spaces for alignment. You can see one tab on the first line, and two tabs plus 3 white spaces for the rest. if the entire bit of code is highlighted, and tab is pressed, vscode adds a full tab (4 spaces in my case) to the first line and aligns the subsequent lines to the tab presets:
ttt,ttt,sql = ('SELECT mode FROM pg_locks JOIN pg_class ' ttt,ttt,ttt,'ON pg_class.oid = pg_locks.relation ' ttt,ttt,ttt,'JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace ' ttt,ttt,ttt,f'WHERE pg_class.relname = {table_name!r} ' ttt,ttt,ttt,f'AND pg_namespace.nspname = {schema!r};')
I think what is needed, is a recognition that multiple lines are being indented then replace the end of line on the first line of selected code upto and including the whitespace of the next line, and insert a new "enter" here to align using the existing extension behavior.. and repeat with each subsequent line until the indentation is recovered. This would highlight the " ttt,ttt,ttt," bit of line 1 to line 2, then replace it, and so on with the following lines until the selection was processed. I have no idea how to do it, or i'd offer the code in a pull request.