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

Treatment of whitespace is inconsistent/inconvenient #69

Open
bkoropoff opened this issue Jun 10, 2021 · 7 comments
Open

Treatment of whitespace is inconsistent/inconvenient #69

bkoropoff opened this issue Jun 10, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@bkoropoff
Copy link

Consider a python snippet like the following with the cursor placed at the caret:

print( "a" , "b" , "c" )
            ^

If you try to select parameter.inner or parameter.outer, nothing will happen.

If the cursor is in a different location:

print( "a" , "b" , "c" )
                ^

Now parameter.outer will select something (the "b" parameter up to its comma, but not its leading space),
but parameter.inner still does nothing.

This is probably technically correct according to the way the syntax tree maps to tokens, but it's not very convenient for editing. You'll get similar behavior if you happen to be in whitespace for other text objects, e.g.:

def foo(bar):
    print(bar)
  ^

Here function.outer will select the entire function and body as expected, but function.inner selects nothing.

When the cursor is on whitespace, it should probably "snap" to the next non-whitespace token before looking for the surrounding text object.

@bkoropoff bkoropoff added the bug Something isn't working label Jun 10, 2021
@zeertzjq
Copy link

The behavior is even weirder when selecting function.inner in the beginning whitespace of a nested function: function.outer selects the inner function, whereas function.inner selects the outer function.

@theHamsta
Copy link
Member

At the moment we have no treatment of whitespaces at at all in this plugin. I always wanted to do this finally but I've never come to point to actually handle it. But I hope that at least some weirdness regard parameter.{inner/outer} got fixed by #87. For all other white space issues I would really recommend to submit a whitespace handling strategy to this plugin because at the moment we don't have any.

@IndianBoy42
Copy link
Contributor

I just tried to fix some whitespace stuff here for parameter.inner and outer, (#87). The problem basically is that treesitter "smartly" ignores whitespace. The parameter node in the syntax tree doesn't include the white space. The only way to capture whitespace (that i know) is to make a range from two nodes, which will capture the whitespace between those. This is why outer sometimes works in the cases you mentioned but inner generally won't

If you know a way to capture pre or post whitespace (without capturing the prev/next token) then we could fix a lot of these problems. I'd be happy to do the work if someone finds a technique

@stsewd
Copy link
Member

stsewd commented Dec 21, 2021

This is already fixed, you need to set the lookahead option to true

- lookahead: `true` or `false`, whether or not to look ahead for the textobject
.

@stsewd stsewd closed this as completed Dec 21, 2021
@bkoropoff
Copy link
Author

Look ahead doesn't work. In my second example, it would actually have to look backwards to find the parameter.

@bkoropoff
Copy link
Author

@stsewd can you reopen this, please?

@theHamsta theHamsta reopened this Jan 6, 2022
@stsewd
Copy link
Member

stsewd commented Jan 13, 2022

@bkoropoff we do support the lookbehind option too

, those options are currently global, I have opened this issue to make the settings per-mapping #156.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants