Skip to content

Commit 6357ae0

Browse files
committed
misc: update docs and clear code
1 parent 3412be9 commit 6357ae0

File tree

8 files changed

+30
-112
lines changed

8 files changed

+30
-112
lines changed

.github/workflows/update-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
uses: rhysd/action-setup-vim@v1
1616
with:
1717
neovim: true
18-
version: stable
18+
version: nightly
1919
- name: Make document
2020
run: |
2121
make document

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ Configure `JupyterLab` in side panel
133133
"SUSTech-data/neopyter",
134134
dependencies = {
135135
'nvim-lua/plenary.nvim',
136+
'nvim-treesitter/nvim-treesitter', -- neopyter don't depend on `nvim-treesitter`, but does depend on treesitter parser of python
136137
'AbaoFromCUG/websocket.nvim', -- for mode='direct'
137-
'nvim-treesitter',
138138
},
139139

140140
---@type neopyter.Option

lua/neopyter/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function M.check()
1919
local nvim_plugin_ver = jupyter.jupyterlab:get_nvim_plugin_version()
2020
if status then
2121
health.info(string.format("neovim plugin(neopyter@%s) status: active", nvim_plugin_ver))
22-
local is_connecting = jupyter.jupyterlab.client:is_connecting()
22+
local is_connecting = jupyter.jupyterlab:is_connecting()
2323
if is_connecting then
2424
local jupyterlab_extension_ver = jupyter.jupyterlab:get_jupyterlab_extension_version()
2525
health.info(string.format("jupyter lab extension(neopyter@%s): active", jupyterlab_extension_ver))

lua/neopyter/jupyter/jupyterlab.lua

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,12 @@ function JupyterLab:new(opts)
5050
local config = require("neopyter").config
5151
local RpcClient
5252
if config["rpc_client"] ~= nil then
53-
vim.notify(
54-
"`rpc_client` is deprecated, please reference to https://github.com/SUSTech-data/neopyter/issues/4",
55-
vim.log.levels.ERROR,
56-
{ title = "Neopyter" }
57-
)
53+
utils.notify_error("`rpc_client` is deprecated, please reference to https://github.com/SUSTech-data/neopyter/issues/4")
5854
end
5955
if config.mode == "direct" then
60-
RpcClient = require("neopyter.rpc.wsserverclient")
56+
RpcClient = require("neopyter.rpc.direct")
6157
else
62-
RpcClient = require("neopyter.rpc.asyncclient")
58+
RpcClient = require("neopyter.rpc.proxy")
6359
end
6460
o.client = RpcClient:new({
6561
address = opts.address,

lua/neopyter/jupyter/notebook.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ function Notebook:attach()
7878
on_lines = function(_, _, _, start_row, old_end_row, new_end_row, _)
7979
a.run(function()
8080
local syncable = self:safe_sync()
81-
-- local connecting = self.client:is_connecting()
82-
-- local line = api.nvim_buf_get_lines(self.bufnr, a.fn.line(".") - 1, a.fn.line("."), true)[1]
83-
-- vim.notify(line.. "/" .. vim.inspect(connecting) .. "/" .. vim.inspect(syncable), nil, { id = "current line" })
84-
8581
if syncable then
8682
self:partial_sync(start_row, old_end_row - 1, new_end_row - 1)
8783
else

lua/neopyter/rpc/blockclient.lua

Lines changed: 0 additions & 74 deletions
This file was deleted.

lua/neopyter/rpc/wsserverclient.lua renamed to lua/neopyter/rpc/direct.lua

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ local logger = require("neopyter.logger")
55
local websocket = require("websocket")
66
local a = require("plenary.async")
77

8-
---@class neopyter.WSServerClient:neopyter.RpcClient
8+
---@class neopyter.DirectRpcClient:neopyter.RpcClient
99
---@field server? websocket.Server # nil means not connect
1010
---@field single_connection? websocket.Connection
1111
---@field private msg_count number
1212
---@field private request_pool table<number, fun(...):any>
13-
local WSServerClient = RpcClient:new({}) --[[@as neopyter.WSServerClient]]
13+
local DirectRpcClient = RpcClient:new({}) --[[@as neopyter.DirectRpcClient]]
1414

1515
---RpcClient constructor
1616
---@param opt neopyter.NewRpcClientOption
17-
---@return neopyter.WSServerClient
18-
function WSServerClient:new(opt)
19-
local o = setmetatable(opt or {}, { __index = self }) --[[@as neopyter.WSServerClient]]
17+
---@return neopyter.DirectRpcClient
18+
function DirectRpcClient:new(opt)
19+
local o = setmetatable(opt or {}, { __index = self }) --[[@as neopyter.DirectRpcClient]]
2020
o.msg_count = 0
2121
o.request_pool = {}
2222
return o
@@ -26,7 +26,7 @@ end
2626
---@param address? string
2727
---@param on_connected? fun() # call while connected
2828
---@async
29-
function WSServerClient:connect(address, on_connected)
29+
function DirectRpcClient:connect(address, on_connected)
3030
local restart_server = address ~= nil and self.address ~= address
3131
for _, fun in pairs(self.request_pool) do
3232
fun(false, "cancel")
@@ -75,7 +75,7 @@ function WSServerClient:connect(address, on_connected)
7575
end
7676

7777
---disconnect connect
78-
function WSServerClient:disconnect()
78+
function DirectRpcClient:disconnect()
7979
if self.single_connection then
8080
self.single_connection:close()
8181
self.single_connection = nil
@@ -92,11 +92,11 @@ end
9292

9393
---check client is connecting
9494
---@return boolean
95-
function WSServerClient:is_connecting()
95+
function DirectRpcClient:is_connecting()
9696
return self.single_connection ~= nil
9797
end
9898

99-
function WSServerClient:gen_id()
99+
function DirectRpcClient:gen_id()
100100
self.msg_count = self.msg_count + 1
101101
return self.msg_count
102102
end
@@ -105,7 +105,7 @@ end
105105
---@param method string
106106
---@param ... unknown # name
107107
---@return unknown|nil
108-
function WSServerClient:request(method, ...)
108+
function DirectRpcClient:request(method, ...)
109109
if self.server == nil then
110110
utils.notify_error(string.format("RPC websocket server is stop, can't request [%s]", method))
111111
return
@@ -139,7 +139,7 @@ end
139139
---handle rpc response
140140
---@param data string
141141
---@package
142-
function WSServerClient:handle_response(data)
142+
function DirectRpcClient:handle_response(data)
143143
local mpack = vim.base64.decode(data)
144144
local status, msg = pcall(vim.mpack.decode, mpack)
145145
if not status then
@@ -174,13 +174,13 @@ function WSServerClient:handle_response(data)
174174
end
175175
end
176176

177-
function WSServerClient:notify(event, ...) end
177+
function DirectRpcClient:notify(event, ...) end
178178

179-
function WSServerClient:reset_request()
179+
function DirectRpcClient:reset_request()
180180
for _, fun in pairs(self.request_pool) do
181181
fun(false, "reset")
182182
end
183183
self.request_pool = {}
184184
end
185185

186-
return WSServerClient
186+
return DirectRpcClient

lua/neopyter/rpc/asyncclient.lua renamed to lua/neopyter/rpc/proxy.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ local a = require("plenary.async")
99
---@field private msg_count number
1010
---@field private request_pool table<number, fun(...):any>
1111
---@field private decoder neopyter.MsgpackDecoder
12-
local AsyncRpcClient = RpcClient:new({}) --[[@as neopyter.AsyncRpcClient]]
12+
local ProxyRpcClient = RpcClient:new({}) --[[@as neopyter.AsyncRpcClient]]
1313

1414
---RpcClient constructor
1515
---@param opt neopyter.NewRpcClientOption
1616
---@return neopyter.AsyncRpcClient
17-
function AsyncRpcClient:new(opt)
17+
function ProxyRpcClient:new(opt)
1818
opt = opt or {}
1919
local o = setmetatable(opt, self)
2020
self.__index = self
@@ -29,7 +29,7 @@ end
2929
---@param address? string
3030
---@param on_connected? fun() # call while connected
3131
---@async
32-
function AsyncRpcClient:connect(address, on_connected)
32+
function ProxyRpcClient:connect(address, on_connected)
3333
self.address = address or self.address
3434
assert(self.tcp_client == nil, "current connection exists, can't call connect, please disconnect first")
3535
assert(self.address, "Rpc client address is empty")
@@ -59,7 +59,7 @@ function AsyncRpcClient:connect(address, on_connected)
5959
end
6060

6161
---disconnect connect
62-
function AsyncRpcClient:disconnect()
62+
function ProxyRpcClient:disconnect()
6363
if self.tcp_client then
6464
self.tcp_client:close()
6565
self.tcp_client = nil
@@ -72,11 +72,11 @@ end
7272

7373
---check client is connecting
7474
---@return boolean
75-
function AsyncRpcClient:is_connecting()
75+
function ProxyRpcClient:is_connecting()
7676
return self.tcp_client ~= nil
7777
end
7878

79-
function AsyncRpcClient:gen_id()
79+
function ProxyRpcClient:gen_id()
8080
self.msg_count = self.msg_count + 1
8181
return self.msg_count
8282
end
@@ -85,7 +85,7 @@ end
8585
---@param method string
8686
---@param ... unknown # name
8787
---@return unknown|nil
88-
function AsyncRpcClient:request(method, ...)
88+
function ProxyRpcClient:request(method, ...)
8989
if not self:is_connecting() then
9090
utils.notify_error(string.format("RPC tcp client is disconnected, can't request [%s]", method))
9191
return
@@ -116,7 +116,7 @@ end
116116
---handle rpc response
117117
---@param data string
118118
---@package
119-
function AsyncRpcClient:handle_response(data)
119+
function ProxyRpcClient:handle_response(data)
120120
self.decoder:feed(data)
121121
while true do
122122
local msg = self.decoder:next()
@@ -141,6 +141,6 @@ function AsyncRpcClient:handle_response(data)
141141
end
142142
end
143143

144-
function AsyncRpcClient:notify(event, ...) end
144+
function ProxyRpcClient:notify(event, ...) end
145145

146-
return AsyncRpcClient
146+
return ProxyRpcClient

0 commit comments

Comments
 (0)