Skip to content
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

Broken indentation of continuation lines #59

Open
albireox opened this issue Apr 8, 2020 · 5 comments
Open

Broken indentation of continuation lines #59

albireox opened this issue Apr 8, 2020 · 5 comments

Comments

@albireox
Copy link

albireox commented Apr 8, 2020

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?

@kbrose
Copy link
Owner

kbrose commented Apr 10, 2020

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.

@kbrose
Copy link
Owner

kbrose commented Apr 10, 2020

If you want to look into it I'd be happy to review an MR that adds this functionality.

@albireox
Copy link
Author

Sounds good. I'm very unexperienced with TS and the VSCode API, but I can give it a try.

@kbrose
Copy link
Owner

kbrose commented Apr 16, 2020

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.

@TedKus
Copy link

TedKus commented Jun 29, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants