Skip to content

Commit

Permalink
Extract prompt into a separate proxy/pdb.lua #194
Browse files Browse the repository at this point in the history
  • Loading branch information
sakhnik committed Aug 1, 2023
1 parent 9c8dcf1 commit 77a9756
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
11 changes: 4 additions & 7 deletions lib/proxy/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Proxy.__index = Proxy
-- Get rid of the script, leave the arguments only
arg[0] = nil

function Proxy.new()
function Proxy.new(prompt)
local self = {}
setmetatable(self, Proxy)
self.prompt = prompt

self.stdin = uv.new_tty(0, true) -- 0 represents stdin file descriptor
local result, error_msg = self.stdin:set_mode(1) -- uv.TTY_MODE_RAW
Expand Down Expand Up @@ -132,7 +133,7 @@ function Proxy:on_stdout(data1, data2)
if self.current_request ~= nil then
self.buffer = self.buffer .. data1 .. data2
local plain_buffer = self.buffer:gsub('%[[^a-zA-Z]*[a-zA-Z]', '')
local start_index = plain_buffer:find('[\n\r]%(Pdb%+*%) ')
local start_index = plain_buffer:find(self.prompt)
if start_index then
local req_id, cmd, addr = unpack(self.current_request)
local response = plain_buffer:sub(#cmd + 1, start_index):match('^%s*(.-)%s*$')
Expand Down Expand Up @@ -181,8 +182,4 @@ function Proxy:send_response(req_id, response, addr)
end)
end

do
local proxy = Proxy.new()
proxy:start()
vim.wait(10^9, function() return false end)
end
return Proxy
10 changes: 10 additions & 0 deletions lib/proxy/pdb.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local uv = vim.loop

local dir = uv.fs_realpath(arg[0]:match('^(.*)[/\\]'))
package.path = dir .. '/?.lua;' .. package.path

local Proxy = require'base'

local proxy = Proxy.new('[\n\r]%(Pdb%+*%) ')
proxy:start()
vim.wait(10^9, function() return false end)
2 changes: 1 addition & 1 deletion lua/nvimgdb/backend/pdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ end
---@return string[] command to launch the debugger with termopen()
function C.get_launch_cmd(client_cmd, tmp_dir, proxy_addr)
local _ = tmp_dir
local cmd = {'nvim', '--clean', '-u', 'NONE', '-l', utils.get_plugin_file_path('lib', 'proxy', 'base.lua'), '-a', proxy_addr}
local cmd = {'nvim', '--clean', '-u', 'NONE', '-l', utils.get_plugin_file_path('lib', 'proxy', 'pdb.lua'), '-a', proxy_addr}
-- Append the rest of arguments
for i = 1, #client_cmd do
cmd[#cmd + 1] = client_cmd[i]
Expand Down

0 comments on commit 77a9756

Please sign in to comment.