tyru / current-func-info.vim

Get current function name
http://www.vim.org/scripts/script.php?script_id=3197
62 stars 14 forks source link

Reimplement python parsing to account for nested functions/classes #22

Closed jerojasro closed 6 years ago

jerojasro commented 6 years ago

The previous implementation did not work properly when there were empty lines between blocks of code inside a function.

I reimplemented it so:

Now the output returned shows the fully qualified function name (MyClass.my_function) if it applies

tyru commented 6 years ago

Please give an example.

jerojasro commented 6 years ago

This exemplifies the issue:

class AccountViewTestCase(BaseTestCase):

    def test_new_account(self):
        name = 'John'  # cfi#get_func_name() works fine when the cursor is here

        phone_number = '3551122333'  # cfi#get_func_name() doesn't show anything when the cursor is here
tyru commented 6 years ago

In addition to my review, in your example, at line 2, cfi#get_func_name() returns empty string. But it should be AccountViewTestCase (same as line 3). Can you fix this?

jerojasro commented 6 years ago

I made changes to:

I still haven't thought of a way of solving this situation:

class Blah:
# cursor here, asume it's an empty line; cfi should say "Blah", but thinks it is not inside any function
  pass

I'll give it some more thought today.

jerojasro commented 6 years ago

In addition to my review, in your example, at line 2, cfi#get_func_name() returns empty string. But it should be AccountViewTestCase (same as line 3). Can you fix this?

Fixed. I think it's ready for you to have another look.

tyru commented 6 years ago
class Blah:
# cursor here, asume it's an empty line; cfi should say "Blah", but thinks it is not inside any function
  pass

For such case, cfi.vim must inspect if the line is a comment or not. I don't want to inspect source code deeply, because there should be many corner cases.

And in this code, it seems to work fine. I think it is enough.

class Blah:
  # cursor here, has indent; cfi says "Blah"
  pass
tyru commented 6 years ago

Thanks! 🎉