Giter VIP home page Giter VIP logo

nvim-client-proxy's Introduction

nvim_client_proxy

A proxy around neovim's lua client that provides an interface that matches the vim object within neovim.

local VimProxy = require('nvim_client_proxy')

-- create a proxy to the neovim running at NVIM_LISTEN_ADDRESS, e.g. the parent
-- neovim instance for a neovim terminal
local vim = VimProxy.new()

print(vim.o.grepprg)
--=> rg --vimgrep

The intended use case is to have convenient access to the parent neovim instance in a lua REPL, rather than using command-mode or something similar for testing neovim's API.

Install

Linux

luarocks install neovim-client-proxy

OSX

libmpack doesn't install cleanly on osx and requires the following patch:

Clone both repos and apply their respective patchs. This example uses gh.

# install patched libmpack
mkdir -p ~/src/libmpack/
gh repo clone libmpack/libmpack-lua ~/src/libmpack/libmpack-lua
cd ~/src/libmpack/libmpack-lua/ 
gh pr checkout 31
make
# install a patched libmpack-lua
luarocks make

# now nvim-client-proxy should install
luarocks install nvim-client-proxy

Build

For instructions on building locally, see CONTRIBUTING.md

Usage

Create an instance of a proxy from any of the following sources:

  • default The os environment variable NVIM_LISTEN_ADDRESS
  • A string whose value is the path to a neovim socket (e.g. the same path passed to nvim --listen <address>)
  • An existing Session
  • An existing SocketStream, ChildProcessStream or TcpStream

The proxy can do the following in the neovim session:

  • Read strings, booleans and numbers
  • Recursively read tables
  • Invoke functions
  • Set strings, booleans, numbers and arbitrarily nesteed tables

It cannot set any of:

  • userdata
  • thread
  • function
local VimProxy = require('nvim_client_proxy')

-- connect to the parent neovim process listening on NVIM_LISTEN_ADDRESS
local vim = VimProxy.new()

local ChildProcessStream = require('nvim.child_process_stream')
-- create a new instance of neovim and attach a proxy to it
local child_vim = VimProxy.new(ChildProcessStream.new({
  'nvim', '-u', 'NONE', '--embed'
}))

-- read vim options
print(vim.o.filetype)
print(vim.bo.autoread)
print(vim.wo.number)

--set vim options
vim.wo.number = true

--set vim options using the options api
vim.opt.runtimepath:append('/some/path')

nvim-client-proxy's People

Contributors

hjdivad avatar

Stargazers

Vera Rei avatar Egor Dementyev avatar  avatar

Watchers

 avatar

nvim-client-proxy's Issues

Add Support for Functions

local fn_info = debug.getinfo(fn, 's')
fn_info.source --=> @.repl.lua
fn_info.linedefined --=> 6
fn_info.lastlinedefined --=> 8
fn_info.nparams --=> 2
fn_info.isvararg --=> false
fn_info.nups --=> 1

This allows us to add support for functions defined outside of stdin. For a
REPL usecase, this means sending loadfile(<file>)() to the REPL instead of
the lines themselves.

nups ("number of upvalues") can be used to see if the function requires a closure.

With this information we can support functions that:

  1. Do not require closures (i.e. nups == 0)
  2. Are defined somewhere other than stdin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.