pub struct Session { /* private fields */ }
Expand description
The current Neovim session
Used to send and receive messages to the Neovim session
Implementations§
Source§impl Session
impl Session
Sourcepub fn from_tcp(addr: &str) -> Result<Session, Error>
pub fn from_tcp(addr: &str) -> Result<Session, Error>
Create a session using a TCP socket
This allows RPC communication with a Neovim instance started with
nvim --listen 127.0.0.1:6666
The current Neovim server can be found using
:echo v:servername
§Example
use rsnvim::session::Session;
let mut session = match Session::from_tcp("127.0.0.1:6666") {
Ok(session) => session,
Err(error) => panic!("Couldn't open TCP socket: {}", error)
};
Sourcepub fn from_parent() -> Result<Session, Error>
pub fn from_parent() -> Result<Session, Error>
Create a Neovim connection using stdin/stdout
This allows RPC communication with the Neovim instance that spawned this process.
§Example
use rsnvim::api::Nvim;
let mut nvim = match Nvim::from_parent() {
Ok(nvim) => nvim,
Err(error) => panic!("Couldn't connect to parent session: {}", error)
};
Sourcepub fn from_unix(path: &str) -> Result<Session, Error>
pub fn from_unix(path: &str) -> Result<Session, Error>
Create a session using a Unix socket
This allows RPC communication with any Neovim instance as it creates a default RPC socket on startup.
The current Neovim server can be found using
:echo v:servername
§Example
use rsnvim::session::Session;
let mut session = match Session::from_unix("/run/user/1000/nvim.XXXXX.X") {
Ok(session) => session,
Err(error) => panic!("Couldn't open UNIX socket: {}", error)
};
Sourcepub fn start_event_loop(
&mut self,
request_handler: Option<Box<dyn RequestHandler + Send>>,
notification_handler: Option<Box<dyn NotificationHandler + Send>>,
)
pub fn start_event_loop( &mut self, request_handler: Option<Box<dyn RequestHandler + Send>>, notification_handler: Option<Box<dyn NotificationHandler + Send>>, )
Begin the RPC event loop
This function must be called before RPC messages can be sent as it
handles the return values, though it is also exposed though the Nvim
struct.
This function allows for up to two custom handlers:
§request_handler
The request_handler
struct must implement the RequestHandler
trait
which then allows it to process incoming RPC requests from Neovim. If
None
is passed the DefaultHandler
will be used which responds with
a NotImplemented
error.
§notification_handler
The notification_handler
struct must implement the ‘NotificationHandler’
trait which then allows it to process incoming RPC notifications from Neovim.
If ‘None’ is passed the DefaultHandler
will be used which ignores all
RPC notifications.