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

vim.current.range is not supported #35

Closed
bjin opened this issue Sep 26, 2014 · 9 comments
Closed

vim.current.range is not supported #35

bjin opened this issue Sep 26, 2014 · 9 comments

Comments

@bjin
Copy link

bjin commented Sep 26, 2014

I tried to run clang-format.py with python client, but noticed that vim.current.range is not supported yet. Is there any plan on supporting it or any other workarounds?

File "/usr/lib/clang-format/clang-format.py", line 48, in main
lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1)
AttributeError: 'Current' object has no attribute 'range'

@tarruda
Copy link
Member

tarruda commented Sep 26, 2014

This shouldn't be too hard to implement, I'm gonna give a shot after #34 is merged. Thanks for reporting.

@bjin
Copy link
Author

bjin commented Oct 17, 2014

Ping. It will be great to have it implemented.

@tarruda
Copy link
Member

tarruda commented Oct 17, 2014

Ping. It will be great to have it implemented.

Sorry, I had completely forgot about this. I'm a bit out of time lately, could you test if this patch fixes the problem? If it does I will merge to master later today.

diff --git a/neovim/api/buffer.py b/neovim/api/buffer.py
index c33c249..e0f7b3b 100644
--- a/neovim/api/buffer.py
+++ b/neovim/api/buffer.py
@@ -115,7 +115,9 @@ class Buffer(Remote):

     def range(self, start, end):
         """Return a `Range` object, which represents part of the Buffer."""
-        return Range(self, start, end)
+        rv = Range(self, start, end)
+        self._session.current_range = rv
+        return rv

     @property
     def name(self):
diff --git a/neovim/api/nvim.py b/neovim/api/nvim.py
index cd9eb4c..f55143c 100644
--- a/neovim/api/nvim.py
+++ b/neovim/api/nvim.py
@@ -229,6 +229,10 @@ class Current(object):
     def tabpage(self, tabpage):
         return self._session.request('vim_set_current_tabpage', tabpage)

+    @property
+    def range(self):
+        return getattr(self._session, 'current_range', None)
+

 class ExtHook(SessionHook):
     def __init__(self, types):

@bjin
Copy link
Author

bjin commented Oct 17, 2014

It now gives error AttributeError("'NoneType' object has no attribute 'start'",)

@tarruda
Copy link
Member

tarruda commented Oct 19, 2014

Now that I read python-vim documentation more carefully, I saw that this will requires changes on both nvim and the python client. The problem is that the python/pyfile commands can receive ranges but it's not currently being passed to the python provider. Would you mind opening an issue on nvim repository?

@bjin
Copy link
Author

bjin commented Oct 19, 2014

I opened a new issue at the main repo.

@tarruda
Copy link
Member

tarruda commented Oct 19, 2014

@bjin thanks, I tagged the issue as entry-level. If no one does this until the of next week I will do it myself.

@tarruda
Copy link
Member

tarruda commented Nov 4, 2014

@bjin If you update Neovim/python-client to the latest versions this issue should be fixed

@bjin
Copy link
Author

bjin commented Nov 4, 2014

Yes, I can verify that it works. Thanks. Closing

@bjin bjin closed this as completed Nov 4, 2014
blueyed pushed a commit to blueyed/python-client that referenced this issue Sep 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants