1
1
"""Main Nvim interface."""
2
2
3
+ from __future__ import annotations
4
+
3
5
import asyncio
4
6
import os
5
7
import sys
56
58
"""
57
59
58
60
59
- class Nvim (object ):
60
-
61
+ class Nvim :
61
62
"""Class that represents a remote Nvim instance.
62
63
63
64
This class is main entry point to Nvim remote API, it is a wrapper
@@ -81,7 +82,7 @@ class Nvim(object):
81
82
"""
82
83
83
84
@classmethod
84
- def from_session (cls , session : ' Session' ) -> ' Nvim' :
85
+ def from_session (cls , session : Session ) -> Nvim :
85
86
"""Create a new Nvim instance for a Session instance.
86
87
87
88
This method must be called to create the first Nvim instance, since it
@@ -102,14 +103,14 @@ def from_session(cls, session: 'Session') -> 'Nvim':
102
103
return cls (session , channel_id , metadata , types )
103
104
104
105
@classmethod
105
- def from_nvim (cls , nvim : ' Nvim' ) -> ' Nvim' :
106
+ def from_nvim (cls , nvim : Nvim ) -> Nvim :
106
107
"""Create a new Nvim instance from an existing instance."""
107
108
return cls (nvim ._session , nvim .channel_id , nvim .metadata ,
108
109
nvim .types , nvim ._decode , nvim ._err_cb )
109
110
110
111
def __init__ (
111
112
self ,
112
- session : ' Session' ,
113
+ session : Session ,
113
114
channel_id : int ,
114
115
metadata : Dict [str , Any ],
115
116
types : Dict [int , Any ],
@@ -168,7 +169,7 @@ def _to_nvim(self, obj: Any) -> Any:
168
169
return ExtType (* obj .code_data )
169
170
return obj
170
171
171
- def _get_lua_private (self ) -> ' LuaFuncs' :
172
+ def _get_lua_private (self ) -> LuaFuncs :
172
173
if not getattr (self ._session , "_has_lua" , False ):
173
174
self .exec_lua (lua_module , self .channel_id )
174
175
self ._session ._has_lua = True # type: ignore[attr-defined]
@@ -269,7 +270,7 @@ def close(self) -> None:
269
270
"""Close the nvim session and release its resources."""
270
271
self ._session .close ()
271
272
272
- def __enter__ (self ) -> ' Nvim' :
273
+ def __enter__ (self ) -> Nvim :
273
274
"""Enter nvim session as a context manager."""
274
275
return self
275
276
@@ -280,7 +281,7 @@ def __exit__(self, *exc_info: Any) -> None:
280
281
"""
281
282
self .close ()
282
283
283
- def with_decode (self , decode : Literal [True ] = True ) -> ' Nvim' :
284
+ def with_decode (self , decode : Literal [True ] = True ) -> Nvim :
284
285
"""Initialize a new Nvim instance."""
285
286
return Nvim (self ._session , self .channel_id ,
286
287
self .metadata , self .types , decode , self ._err_cb )
@@ -575,8 +576,7 @@ def tabpage(self, tabpage: Union[Tabpage, int]) -> None:
575
576
return self ._session .request ('nvim_set_current_tabpage' , tabpage )
576
577
577
578
578
- class Funcs (object ):
579
-
579
+ class Funcs :
580
580
"""Helper class for functional vimscript interface."""
581
581
582
582
def __init__ (self , nvim : Nvim ):
@@ -586,15 +586,14 @@ def __getattr__(self, name: str) -> Callable[..., Any]:
586
586
return partial (self ._nvim .call , name )
587
587
588
588
589
- class LuaFuncs (object ):
590
-
589
+ class LuaFuncs :
591
590
"""Wrapper to allow lua functions to be called like python methods."""
592
591
593
592
def __init__ (self , nvim : Nvim , name : str = "" ):
594
593
self ._nvim = nvim
595
594
self .name = name
596
595
597
- def __getattr__ (self , name : str ) -> ' LuaFuncs' :
596
+ def __getattr__ (self , name : str ) -> LuaFuncs :
598
597
"""Return wrapper to named api method."""
599
598
prefix = self .name + "." if self .name else ""
600
599
return LuaFuncs (self ._nvim , prefix + name )
0 commit comments