pax_global_header00006660000000000000000000000064135741147210014517gustar00rootroot0000000000000052 comment=2da5151b59b52a3547365929ae5dbefa27399013 lua-client-0.2.1-1/000077500000000000000000000000001357411472100137125ustar00rootroot00000000000000lua-client-0.2.1-1/.ci/000077500000000000000000000000001357411472100143635ustar00rootroot00000000000000lua-client-0.2.1-1/.ci/before_cache.sh000077500000000000000000000010131357411472100173020ustar00rootroot00000000000000#!/usr/bin/env bash set -e set -o pipefail # Don't cache pip's log and selfcheck. rm -rf "${HOME}/.cache/pip/log" rm -f "${HOME}/.cache/pip/selfcheck.json" # Update the third-party dependency cache only if the build was successful. if [[ -f "${SUCCESS_MARKER}" ]]; then if [[ ! -f "${CACHE_MARKER}" ]] || [[ "${BUILD_DEPS}" == true ]]; then echo "Updating dependencies cache." rm -rf "${HOME}/.cache/nvim-deps" mv -T "${DEPS_INSTALL_PREFIX}" "${HOME}/.cache/nvim-deps" touch "${CACHE_MARKER}" fi fi lua-client-0.2.1-1/.ci/script.sh000077500000000000000000000017441357411472100162340ustar00rootroot00000000000000#!/usr/bin/env bash set -e set -o pipefail #set -o xtrace SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" get_nvim() { mkdir "$NVIM_INSTALL_PREFIX" curl -L https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz \ | tar xzf - --strip-components=1 -C "$NVIM_INSTALL_PREFIX" "$NVIM_PROG" --version } get_or_build_deps() { rm -rf "${DEPS_INSTALL_PREFIX}" # Use cached dependencies if available (and not forced). if [[ -f "${CACHE_MARKER}" ]] && [[ "${BUILD_NVIM_DEPS}" != true ]]; then echo "Using cached dependencies (last updated: $(stat -c '%y' "${CACHE_MARKER}"))." mkdir -p "$(dirname "${DEPS_INSTALL_PREFIX}")" ln -Ts "${HOME}/.cache/nvim-deps" "${DEPS_INSTALL_PREFIX}" return fi ${MAKE_CMD} deps get_nvim } run_tests() { make test echo "${SUCCESS_MARKER}" touch "${SUCCESS_MARKER}" } get_or_build_deps # Display info for logs. "${DEPS_INSTALL_PREFIX}/bin/luarocks" list ${NVIM_PROG} --version run_tests lua-client-0.2.1-1/.gitignore000066400000000000000000000003071357411472100157020ustar00rootroot00000000000000local.mk build .deps # Object files *.o *.ko *.obj *.elf # Libraries *.lib *.a # Shared objects (inc. Windows DLLs) *.dll *.so *.so.* *.dylib # Executables *.exe *.out *.app *.i*86 *.x86_64 *.hex lua-client-0.2.1-1/.luacheckrc000066400000000000000000000002461357411472100160210ustar00rootroot00000000000000-- Don't report unused self arguments of methods. self = false ignore = { "212/_.*", -- unused argument, for vars with "_" prefix } -- vim: ft=lua tw=80 sw=2 et lua-client-0.2.1-1/.travis.yml000066400000000000000000000025521357411472100160270ustar00rootroot00000000000000dist: xenial language: c env: global: - DEPS_INSTALL_PREFIX="${TRAVIS_BUILD_DIR}/.deps" - NVIM_INSTALL_PREFIX="${DEPS_INSTALL_PREFIX}/nvim" - NVIM_PROG="${NVIM_INSTALL_PREFIX}/bin/nvim" # Travis has 1.5 virtual cores. # http://docs.travis-ci.com/user/speeding-up-the-build/#Paralellizing-your-build-on-one-VM - MAKE_CMD="make -j2" - DEPS_PREFIX=${DEPS_INSTALL_PREFIX} - DEPS_INCLUDE_FLAGS="-I${DEPS_INSTALL_PREFIX}/include -I${DEPS_INSTALL_PREFIX}/include/luajit-2.0" - LUA=${DEPS_INSTALL_PREFIX}/bin/luajit # Cache marker for dependencies cache: indicates that the cache exists # and has pre-built dependencies. - CACHE_MARKER="$HOME/.cache/nvim-deps/.travis_cache_marker" # Test success marker: indicates that all tests were successful. # Required because we only want to update the cache if the tests were # successful, but don't have this information available in before_cache # (which is run before after_success). - SUCCESS_MARKER="$TRAVIS_BUILD_DIR/.tests_successful" matrix: include: - env: LUA_URL=https://www.lua.org/ftp/lua-5.1.5.tar.gz - env: LUA_URL=https://www.lua.org/ftp/lua-5.3.5.tar.gz script: .ci/script.sh before_cache: .ci/before_cache.sh cache: apt: true directories: - "$HOME/.cache/pip" - "$HOME/.cache/nvim-deps" addons: apt: packages: - gdb lua-client-0.2.1-1/.ycm_extra_conf.py000066400000000000000000000006111357411472100173400ustar00rootroot00000000000000import os import os.path cwd = os.path.dirname(os.path.abspath(__file__)) flags = [ '-g', '-fPIC', '-Wall', '-Wextra', '-Werror', '-Wextra', '-Wconversion', '-Wstrict-prototypes', '-pedantic', '-isystem', os.path.join(cwd, '.deps', 'usr', 'include') ] def FlagsForFile(filename, **kwargs): return { 'flags': flags, 'do_cache': True } lua-client-0.2.1-1/LICENSE000066400000000000000000000260741357411472100147300ustar00rootroot00000000000000Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. lua-client-0.2.1-1/Makefile000066400000000000000000000054131357411472100153550ustar00rootroot00000000000000# This Makefile creates a project-private prefix ".deps/usr" with all # dependencies required for building/testing. # local.mk is ignored by git, use it for local build settings. -include local.mk # Use TEST_TAG=foo to pass --tags=foo to busted. _TEST_TAG := $(if $(TEST_TAG),--tags=$(TEST_TAG),) # Dependencies prefix DEPS_DIR ?= $(shell pwd)/.deps DEPS_PREFIX ?= $(DEPS_DIR)/usr DEPS_BIN ?= $(DEPS_PREFIX)/bin # Lua-related configuration LUA_URL ?= http://www.lua.org/ftp/lua-5.1.5.tar.gz LUAROCKS_URL ?= https://github.com/keplerproject/luarocks/archive/v2.2.0.tar.gz LUA_TARGET ?= linux LUA ?= $(DEPS_BIN)/lua LUAROCKS ?= $(DEPS_BIN)/luarocks BUSTED ?= $(DEPS_BIN)/busted LUV ?= $(DEPS_PREFIX)/lib/luarocks/rocks/luv MPACK ?= $(DEPS_PREFIX)/lib/luarocks/rocks/mpack COXPCALL ?= $(DEPS_PREFIX)/lib/luarocks/rocks/coxpcall # Compilation CC ?= gcc CFLAGS ?= -g -fPIC -Wall -Wextra -Werror -Wconversion -Wextra \ -Wstrict-prototypes -pedantic LDFLAGS ?= -shared -fPIC DEPS_INCLUDE_FLAGS ?= -I$(DEPS_PREFIX)/include # Misc # Options used by the 'valgrind' target, which runs the tests under valgrind VALGRIND_OPTS ?= --log-file=valgrind.log --leak-check=yes --track-origins=yes # Command that will download a file and pipe it's contents to stdout FETCH ?= curl -L -o - # Command that will gunzip/untar a file from stdin to the current directory, # stripping one directory component UNTGZ ?= tar xfz - --strip-components=1 all: deps nvim/native.so deps: | $(MPACK) $(COXPCALL) $(BUSTED) $(LUV) test: all NVIM_LOG_FILE=nvimlog $(BUSTED) -v $(_TEST_TAG) \ '--lpath=./nvim/?.lua;' '--cpath=./nvim/?.so;' -o gtest test valgrind: all eval $$($(LUAROCKS) path); \ valgrind $(VALGRIND_OPTS) $(LUA) \ $(DEPS_PREFIX)/lib/luarocks/rocks/busted/2.0.rc11-0/bin/busted \ '--lpath=./nvim/?.lua;' '--cpath=./nvim/?.so;' test cat valgrind.log clean: rm -f nvim/*.o nvim/*.so distclean: clean rm -rf $(DEPS_DIR) nvim/native.o: nvim/native.c $(LUA) $(LIBUV) $(CC) $(CFLAGS) -o $@ -c $< $(DEPS_INCLUDE_FLAGS) nvim/native.so: nvim/native.o $(CC) $(LDFLAGS) $< -o $@ $(BUSTED): | $(LUAROCKS) $(LUAROCKS) install busted $(LUAROCKS) install inspect # helpful for debugging $(LUV): $(LUAROCKS) $(LUAROCKS) install luv $(MPACK): $(LUAROCKS) $(LUAROCKS) install mpack $(COXPCALL): $(LUAROCKS) $(LUAROCKS) install coxpcall $(LUAROCKS): $(LUA) dir="$(DEPS_DIR)/src/luarocks"; \ mkdir -p $$dir && cd $$dir && \ $(FETCH) $(LUAROCKS_URL) | $(UNTGZ) && \ ./configure --prefix=$(DEPS_PREFIX) --force-config \ --with-lua=$(DEPS_PREFIX) && make bootstrap $(LUA): dir="$(DEPS_DIR)/src/lua"; \ mkdir -p $$dir && cd $$dir && \ $(FETCH) $(LUA_URL) | $(UNTGZ) && \ sed -i -e '/^CFLAGS/s/-O2/-g/' src/Makefile && \ make $(LUA_TARGET) install INSTALL_TOP=$(DEPS_PREFIX) .PHONY: all deps test valgrind clean distclean lua-client-0.2.1-1/README.md000066400000000000000000000022141357411472100151700ustar00rootroot00000000000000lua-client ========== [![Build Status](https://travis-ci.org/neovim/lua-client.svg?branch=master)](https://travis-ci.org/neovim/lua-client) Lua client for Neovim Build ----- The `Makefile` pulls and builds various dependencies into `.deps`. make Test ---- Run tests against whatever `nvim` is in `$PATH`: make test Use a specific `nvim`: NVIM_PROG=/path/to/nvim make test Use test tags (`it('#foo', function() ...`): NVIM_PROG=/path/to/nvim make test TEST_TAG=foo Release ------- 1. [Bump](https://github.com/neovim/lua-client/commit/018a562992f1e1a54e111a5603fc6f603be51cca) the rockspec version and filename. 2. Create and push a new tag. ``` TAG=$(echo *.rockspec | grep -o '[0-9].[0-9].[0-9].[0-9]') git tag -a "$TAG" -m "nvim-client $TAG" git push --follow-tags --dry-run git push --follow-tags ``` 3. [Generate](https://luarocks.org/settings/api-keys) LuaRocks API key 4. Upload the new rockspec. ``` ./.deps/usr/bin/luarocks upload --api-key=xxx nvim-client-*.rockspec ``` - Note: `luarocks upload` requires a JSON library. ``` ./.deps/usr/bin/luarocks install dkjson ``` lua-client-0.2.1-1/nvim-client-0.2.1-1.rockspec000066400000000000000000000014661357411472100204730ustar00rootroot00000000000000package = 'nvim-client' version = '0.2.1-1' source = { url = 'https://github.com/neovim/lua-client/archive/' .. version .. '.tar.gz', dir = 'lua-client-' .. version, } description = { summary = 'Lua client to Nvim', license = 'Apache' } dependencies = { 'lua >= 5.1', 'mpack', 'luv', 'coxpcall' } local function make_modules() return { ['nvim.socket_stream'] = 'nvim/socket_stream.lua', ['nvim.tcp_stream'] = 'nvim/tcp_stream.lua', ['nvim.stdio_stream'] = 'nvim/stdio_stream.lua', ['nvim.child_process_stream'] = 'nvim/child_process_stream.lua', ['nvim.msgpack_rpc_stream'] = 'nvim/msgpack_rpc_stream.lua', ['nvim.session'] = 'nvim/session.lua', ['nvim.native'] = { sources = {'nvim/native.c'} } } end build = { type = 'builtin', modules = make_modules(), } lua-client-0.2.1-1/nvim/000077500000000000000000000000001357411472100146635ustar00rootroot00000000000000lua-client-0.2.1-1/nvim/_compat.lua000066400000000000000000000010101357411472100170000ustar00rootroot00000000000000-- Lua 5.1 forward-compatibility layer. -- For background see https://github.com/neovim/neovim/pull/9280 -- -- Reference the lua-compat-5.2 project for hints: -- https://github.com/keplerproject/lua-compat-5.2/blob/c164c8f339b95451b572d6b4b4d11e944dc7169d/compat52/mstrict.lua -- https://github.com/keplerproject/lua-compat-5.2/blob/c164c8f339b95451b572d6b4b4d11e944dc7169d/tests/test.lua local lua_version = _VERSION:sub(-3) if lua_version >= "5.2" then unpack = table.unpack -- luacheck: ignore 121 143 end lua-client-0.2.1-1/nvim/child_process_stream.lua000066400000000000000000000025201357411472100215610ustar00rootroot00000000000000local uv = require('luv') local native = require('nvim.native') local ChildProcessStream = {} ChildProcessStream.__index = ChildProcessStream function ChildProcessStream.spawn(argv, env) local self = setmetatable({ _child_stdin = uv.new_pipe(false), _child_stdout = uv.new_pipe(false) }, ChildProcessStream) local prog = argv[1] local args = {} for i = 2, #argv do args[#args + 1] = argv[i] end self._proc, self._pid = uv.spawn(prog, { stdio = {self._child_stdin, self._child_stdout, 2}, args = args, env = env, }, function() self:close() end) if not self._proc then local err = self._pid error(err) end return self end function ChildProcessStream:write(data) self._child_stdin:write(data) end function ChildProcessStream:read_start(cb) self._child_stdout:read_start(function(err, chunk) if err then error(err) end cb(chunk) end) end function ChildProcessStream:read_stop() self._child_stdout:read_stop() end function ChildProcessStream:close(signal) if self._closed then return end self._closed = true self:read_stop() self._child_stdin:close() self._child_stdout:close() if type(signal) == 'string' then self._proc:kill('sig'..signal) end self._proc:close() uv.run('nowait') native.pid_wait(self._pid) end return ChildProcessStream lua-client-0.2.1-1/nvim/msgpack_rpc_stream.lua000066400000000000000000000063311357411472100212350ustar00rootroot00000000000000local mpack = require('mpack') -- temporary hack to be able to manipulate buffer/window/tabpage local Buffer = {} Buffer.__index = Buffer function Buffer.new(id) return setmetatable({id=id}, Buffer) end local Window = {} Window.__index = Window function Window.new(id) return setmetatable({id=id}, Window) end local Tabpage = {} Tabpage.__index = Tabpage function Tabpage.new(id) return setmetatable({id=id}, Tabpage) end local Response = {} Response.__index = Response function Response.new(msgpack_rpc_stream, request_id) return setmetatable({ _msgpack_rpc_stream = msgpack_rpc_stream, _request_id = request_id }, Response) end function Response:send(value, is_error) local data = self._msgpack_rpc_stream._session:reply(self._request_id) if is_error then data = data .. self._msgpack_rpc_stream._pack(value) data = data .. self._msgpack_rpc_stream._pack(mpack.NIL) else data = data .. self._msgpack_rpc_stream._pack(mpack.NIL) data = data .. self._msgpack_rpc_stream._pack(value) end self._msgpack_rpc_stream._stream:write(data) end local MsgpackRpcStream = {} MsgpackRpcStream.__index = MsgpackRpcStream function MsgpackRpcStream.new(stream) return setmetatable({ _stream = stream, _pack = mpack.Packer({ ext = { [Buffer] = function(o) return 0, mpack.pack(o.id) end, [Window] = function(o) return 1, mpack.pack(o.id) end, [Tabpage] = function(o) return 2, mpack.pack(o.id) end } }), _session = mpack.Session({ unpack = mpack.Unpacker({ ext = { [0] = function(_c, s) return Buffer.new(mpack.unpack(s)) end, [1] = function(_c, s) return Window.new(mpack.unpack(s)) end, [2] = function(_c, s) return Tabpage.new(mpack.unpack(s)) end } }) }), }, MsgpackRpcStream) end function MsgpackRpcStream:write(method, args, response_cb) local data if response_cb then assert(type(response_cb) == 'function') data = self._session:request(response_cb) else data = self._session:notify() end data = data .. self._pack(method) .. self._pack(args) self._stream:write(data) end function MsgpackRpcStream:read_start(request_cb, notification_cb, eof_cb) self._stream:read_start(function(data) if not data then return eof_cb() end local type, id_or_cb, method_or_error, args_or_result local pos = 1 local len = #data while pos <= len do type, id_or_cb, method_or_error, args_or_result, pos = self._session:receive(data, pos) if type == 'request' or type == 'notification' then if type == 'request' then request_cb(method_or_error, args_or_result, Response.new(self, id_or_cb)) else notification_cb(method_or_error, args_or_result) end elseif type == 'response' then if method_or_error == mpack.NIL then method_or_error = nil else args_or_result = nil end id_or_cb(method_or_error, args_or_result) end end end) end function MsgpackRpcStream:read_stop() self._stream:read_stop() end function MsgpackRpcStream:close(signal) self._stream:close(signal) end return MsgpackRpcStream lua-client-0.2.1-1/nvim/native.c000066400000000000000000000013771357411472100163250ustar00rootroot00000000000000#define LUA_LIB #include #include #define UNUSED(x) ((void)x) #ifdef _WIN32 static int pid_wait(lua_State *L) { (void)(L); return 0; } #else #include #include static int pid_wait(lua_State *L) { int status; pid_t pid = (pid_t)luaL_checkinteger(L, 1); /* Work around libuv bug that leaves defunct children: * https://github.com/libuv/libuv/issues/154 */ while (!kill(pid, 0)) waitpid(pid, &status, WNOHANG); return 0; } #endif static const luaL_Reg native_lib_f[] = { {"pid_wait", pid_wait}, {NULL, NULL} }; int luaopen_nvim_native(lua_State *L) { lua_newtable(L); #if LUA_VERSION_NUM >= 502 luaL_setfuncs(L, native_lib_f, 0); #else luaL_register(L, NULL, native_lib_f); #endif return 1; } lua-client-0.2.1-1/nvim/session.lua000066400000000000000000000105221357411472100170510ustar00rootroot00000000000000local coxpcall = require('coxpcall') local uv = require('luv') local MsgpackRpcStream = require('nvim.msgpack_rpc_stream') require('nvim._compat') local Session = {} Session.__index = Session local function resume(co, ...) local status, result = coroutine.resume(co, ...) if coroutine.status(co) == 'dead' then if not status then error(result) end return end assert(coroutine.status(co) == 'suspended') result(co) end local function coroutine_exec(func, ...) local args = {...} local on_complete if #args > 0 and type(args[#args]) == 'function' then -- completion callback on_complete = table.remove(args) end resume(coroutine.create(function() local status, result, flag = coxpcall.pcall(func, unpack(args)) if on_complete then coroutine.yield(function() -- run the completion callback on the main thread on_complete(status, result, flag) end) end end)) end function Session.new(stream) return setmetatable({ _msgpack_rpc_stream = MsgpackRpcStream.new(stream), _pending_messages = {}, _prepare = uv.new_prepare(), _timer = uv.new_timer(), _is_running = false }, Session) end function Session:next_message(timeout) local function on_request(method, args, response) table.insert(self._pending_messages, {'request', method, args, response}) uv.stop() end local function on_notification(method, args) table.insert(self._pending_messages, {'notification', method, args}) uv.stop() end if self._is_running then error('Event loop already running') end if #self._pending_messages > 0 then return table.remove(self._pending_messages, 1) end self:_run(on_request, on_notification, timeout) return table.remove(self._pending_messages, 1) end function Session:notify(method, ...) self._msgpack_rpc_stream:write(method, {...}) end function Session:request(method, ...) local args = {...} local err, result if self._is_running then err, result = self:_yielding_request(method, args) else err, result = self:_blocking_request(method, args) end if err then return false, err end return true, result end function Session:run(request_cb, notification_cb, setup_cb, timeout) local function on_request(method, args, response) coroutine_exec(request_cb, method, args, function(status, result, flag) if status then response:send(result, flag) else response:send(result, true) end end) end local function on_notification(method, args) coroutine_exec(notification_cb, method, args) end self._is_running = true if setup_cb then coroutine_exec(setup_cb) end while #self._pending_messages > 0 do local msg = table.remove(self._pending_messages, 1) if msg[1] == 'request' then on_request(msg[2], msg[3], msg[4]) else on_notification(msg[2], msg[3]) end end self:_run(on_request, on_notification, timeout) self._is_running = false end function Session:stop() uv.stop() end function Session:close(signal) if not self._timer:is_closing() then self._timer:close() end if not self._prepare:is_closing() then self._prepare:close() end self._msgpack_rpc_stream:close(signal) end function Session:_yielding_request(method, args) return coroutine.yield(function(co) self._msgpack_rpc_stream:write(method, args, function(err, result) resume(co, err, result) end) end) end function Session:_blocking_request(method, args) local err, result local function on_request(method_, args_, response) table.insert(self._pending_messages, {'request', method_, args_, response}) end local function on_notification(method_, args_) table.insert(self._pending_messages, {'notification', method_, args_}) end self._msgpack_rpc_stream:write(method, args, function(e, r) err = e result = r uv.stop() end) self:_run(on_request, on_notification) return err, result end function Session:_run(request_cb, notification_cb, timeout) if type(timeout) == 'number' then self._prepare:start(function() self._timer:start(timeout, 0, function() uv.stop() end) self._prepare:stop() end) end self._msgpack_rpc_stream:read_start(request_cb, notification_cb, uv.stop) uv.run() self._prepare:stop() self._timer:stop() self._msgpack_rpc_stream:read_stop() end return Session lua-client-0.2.1-1/nvim/socket_stream.lua000066400000000000000000000020041357411472100202250ustar00rootroot00000000000000local uv = require('luv') local SocketStream = {} SocketStream.__index = SocketStream function SocketStream.open(file) local socket = uv.new_pipe(false) local self = setmetatable({ _socket = socket, _stream_error = nil }, SocketStream) uv.pipe_connect(socket, file, function (err) self._stream_error = self._stream_error or err end) return self end function SocketStream:write(data) if self._stream_error then error(self._stream_error) end uv.write(self._socket, data, function(err) if err then error(self._stream_error or err) end end) end function SocketStream:read_start(cb) if self._stream_error then error(self._stream_error) end uv.read_start(self._socket, function(err, chunk) if err then error(err) end cb(chunk) end) end function SocketStream:read_stop() if self._stream_error then error(self._stream_error) end uv.read_stop(self._socket) end function SocketStream:close() uv.close(self._socket) end return SocketStream lua-client-0.2.1-1/nvim/stdio_stream.lua000066400000000000000000000012011357411472100200550ustar00rootroot00000000000000local uv = require('luv') local StdioStream = {} StdioStream.__index = StdioStream function StdioStream.open() local self = setmetatable({ _in = uv.new_pipe(false), _out = uv.new_pipe(false) }, StdioStream) self._in:open(0) self._out:open(1) return self end function StdioStream:write(data) self._out:write(data) end function StdioStream:read_start(cb) self._in:read_start(function(err, chunk) if err then error(err) end cb(chunk) end) end function StdioStream:read_stop() self._in:read_stop() end function StdioStream:close() self._in:close() self._out:close() end return StdioStream lua-client-0.2.1-1/nvim/tcp_stream.lua000066400000000000000000000017531357411472100175350ustar00rootroot00000000000000local uv = require('luv') local TcpStream = {} TcpStream.__index = TcpStream function TcpStream.open(host, port) local client = uv.new_tcp() local self = setmetatable({ _socket = client, _stream_error = nil }, TcpStream) uv.tcp_connect(client, host, port, function (err) self._stream_error = self._stream_error or err end) return self end function TcpStream:write(data) if self._stream_error then error(self._stream_error) end uv.write(self._socket, data, function(err) if err then error(self._stream_error or err) end end) end function TcpStream:read_start(cb) if self._stream_error then error(self._stream_error) end uv.read_start(self._socket, function(err, chunk) if err then error(err) end cb(chunk) end) end function TcpStream:read_stop() if self._stream_error then error(self._stream_error) end uv.read_stop(self._socket) end function TcpStream:close() uv.close(self._socket) end return TcpStream lua-client-0.2.1-1/test/000077500000000000000000000000001357411472100146715ustar00rootroot00000000000000lua-client-0.2.1-1/test/session_spec.lua000066400000000000000000000211371357411472100200750ustar00rootroot00000000000000local ChildProcessStream = require('nvim.child_process_stream') local TcpStream = require('nvim.tcp_stream') local SocketStream = require('nvim.socket_stream') local Session = require('nvim.session') local coxpcall = require('coxpcall') local busted = require('busted') require('nvim._compat') local nvim_prog = os.getenv('NVIM_PROG') or 'nvim' local child_session local socket_session local socket_file local tcp_session do math.randomseed(os.time()) socket_file = string.format("/tmp/nvim.socket-%d", math.random(1000,9999)) end local function test_session(description, session_factory, session_destroy) local get_api_info = function (session) local ok, res = session:request('vim_get_api_info') return ok, unpack(res) end describe(description, function() local closed, session before_each(function() closed = false session = session_factory() end) after_each(function() if not closed then session:request('vim_command', 'qa!') end end) it('can make requests to nvim', function() assert.are.same({true, {1, 2, 3}}, {session:request('vim_eval', '[1, 2, 3]')}) end) it('can get api metadata', function() local res, channel_id, api_t = get_api_info(session) assert.is_true(res) assert.is_true(type(channel_id) == "number") assert.is_true(type(api_t) == "table") assert.is_true(type(api_t["functions"]) == "table") assert.is_true(type(api_t["error_types"]) == "table") assert.is_true(type(api_t["types"]) == "table") end) it('can receive messages from nvim', function() local _, channel_id, _ = get_api_info(session) assert.are.same({true, 1}, {session:request('vim_eval', string.format('rpcnotify(%d, "lua_event", 1, [1])', channel_id))}) assert.are.same({'notification', 'lua_event', {1, {1}}}, session:next_message()) end) it('can receive requests from nvim', function() local notified = 0 local _, channel_id, _ = get_api_info(session) local function on_request(method, args) if method == 'lua_notify' then assert.are.same({true, 1}, {session:request('vim_eval', string.format('rpcnotify(%d, "lua_event", 2, [2])', channel_id))}) assert.are.same({true, 1}, {session:request('vim_eval', string.format('rpcnotify(%d, "lua_event", 2, [2])', channel_id))}) return 'notified!' elseif method == 'lua_error' then return 'error message', true end assert.are.same('lua_method', method) assert.are.same({1, {1}}, args) return {'hello from lua!'} end local function on_notification(method, args) notified = notified + 1 assert.are.same('lua_event', method) assert.are.same({2, {2}}, args) assert.are.same({true, {2, {3}}}, {session:request('vim_eval', '[2, [3]')}) end local err session:run(on_request, on_notification, function() _, err = coxpcall.pcall(function() assert.are.same({true, 'notified!'}, {session:request('vim_eval' , string.format('rpcrequest(%d, "lua_notify")', channel_id))}) assert.are.same({true, 'notified!'}, {session:request('vim_eval' , string.format('rpcrequest(%d, "lua_notify")', channel_id))}) assert.are.same({true, 'notified!'}, {session:request('vim_eval' , string.format('rpcrequest(%d, "lua_notify")', channel_id))}) assert.are.same({true, {'hello from lua!'}}, {session:request('vim_eval', string.format('rpcrequest(%d, "lua_method", 1, [1])', channel_id))}) assert.are.same({false, {0, string.format( "Vim:Error invoking 'lua_error' on channel %d:\nerror message", channel_id)}}, {session:request('vim_eval', string.format('rpcrequest(%d, "lua_error")', channel_id))}) end) session:stop() end) if err then busted.fail(err, 2) end assert.are.equal(6, notified) end) it('can deal with recursive requests from nvim', function() local requested = 0 local _, channel_id, _ = get_api_info(session) local function on_request(method) assert.are.same("method", method) requested = requested + 1 if requested < 10 then session:request('vim_eval' , string.format('rpcrequest(%d, "method")', channel_id)) end return requested end session:run(on_request, nil, function() session:request('vim_eval' , string.format('rpcrequest(%d, "method")', channel_id)) session:stop() end) assert.are.equal(10, requested) end) it('can receive errors from nvim', function() local _, channel_id, _ = get_api_info(session) local status, result = session:request('vim_eval', string.format('rpcrequest(%d, "method", 1, 2', channel_id)) assert.is_false(status) -- Improved parsing in nvim changed the error message between 0.2.2 and -- 0.3.0, but accept either to ease transition between versions if string.match(result[2], 'Failed') then assert.are.equal('Failed to evaluate expression', result[2]) else assert.are.equal('Vim:E116: Invalid arguments for function rpcrequest', result[2]) end end) it('can break out of event loop with a timeout', function() local responded = false session:run(nil, nil, function() session:request('vim_command' , 'sleep 5') responded = true end, 50) assert.is_false(responded) if session_destroy then session_destroy() else session:close() end closed = true end) end) end -- Session using ChildProcessStream test_session("Session using ChidProcessStream", function () local proc_stream = ChildProcessStream.spawn({ nvim_prog, '-u', 'NONE', '--embed', }) return Session.new(proc_stream) end) -- Session using SocketStream test_session(string.format("Session using SocketStream [%s]", socket_file), function () child_session = Session.new(ChildProcessStream.spawn({ nvim_prog, '-u', 'NONE', '--embed', '--headless', '--cmd', string.format('call serverstart("%s")', socket_file) })) child_session:request('vim_eval', '1') -- wait for nvim to start local socket_stream = SocketStream.open(socket_file) socket_session = Session.new(socket_stream) return socket_session end, function () child_session:close() socket_session:close() -- clean up leftovers if something goes wrong local fd = io.open(socket_file) if fd then os.execute(string.format("rm %s", socket_file)) fd:close() end end) describe('Session using SocketStream', function () before_each(function() local socket_stream = SocketStream.open("/tmp/nvim.sock") socket_session = Session.new(socket_stream) end) after_each(function() socket_session:close() end) it('throws ENOENT error when socket does not exist', function () assert.has_error(function () socket_session:request('vim_eval', '1 + 1 + 1') end, "ENOENT") end) end) -- Session using TcpStream test_session("Session using TcpStream", function () child_session = Session.new(ChildProcessStream.spawn({ nvim_prog, '-u', 'NONE', '--embed', '--headless', '--cmd', 'call serverstart("127.0.0.1:6666")' })) child_session:request('vim_eval', '1') -- wait for nvim to start local tcp_stream = TcpStream.open("127.0.0.1", 6666) tcp_session = Session.new(tcp_stream) return tcp_session end, function () child_session:close() tcp_session:close() end) describe('Session using TcpStream', function () before_each(function() local tcp_stream = TcpStream.open("127.0.0.1", 6666) tcp_session = Session.new(tcp_stream) end) after_each(function() tcp_session:close() end) it('throws ECONNREFUSED error if neovim does not expose the TCP socket', function () assert.has_error(function () tcp_session:request('vim_eval', '1 + 1 + 1') end, "ECONNREFUSED") end) end) -- get the path to the lua interpreter, taken from -- http://stackoverflow.com/a/18304231 local i_min = 0 while arg[ i_min ] do i_min = i_min - 1 end i_min = i_min + 1 describe('stdio', function() it('sends and receive data through stdout/stdin', function() local proc_stream = ChildProcessStream.spawn({ arg[i_min], 'test/stdio_fixture.lua', package.path, package.cpath }) local session = Session.new(proc_stream) session:notify('a', 0, 1) assert.are.same({'notification', 'b', {2, 3}}, session:next_message()) session:notify('c', 4, 5) assert.are.same({'notification', 'd', {6, 7}}, session:next_message()) end) end) lua-client-0.2.1-1/test/stdio_fixture.lua000066400000000000000000000010641357411472100202650ustar00rootroot00000000000000--- stdio test fixture / program. -- -- Lua's paths are passed as arguments to reflect the path in the test itself. package.path = arg[1] package.cpath = arg[2] local assert = require("luassert") local StdioStream = require('nvim.stdio_stream') local Session = require('nvim.session') local stdio_stream = StdioStream.open() local session = Session.new(stdio_stream) assert.are.same({'notification', 'a', {0, 1}}, session:next_message()) session:notify('b', 2, 3) assert.are.same({'notification', 'c', {4, 5}}, session:next_message()) session:notify('d', 6, 7)