Skip to content

Commit 7c4b626

Browse files
committed
add is_attached()
osv could be running but not attached to a debuggee instance. This function allows to differentiate those states.
1 parent 6ad8101 commit 7c4b626

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

doc/osv.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ is_running() *osv.is_running()*
164164
Return: ~
165165
True if osv is running.
166166

167+
is_attached() *osv.is_attached()*
168+
Checks whether |osv| is currently attached to a debuggee instance.
169+
170+
Return: ~
171+
True if osv is attached.
172+
167173
print_profiler() *osv.print_profiler()*
168174
Prints the last 1000 elapsed times in milliseconds for each profiled sections.
169175
See |osv.launch()| to enable the profiler.

lua/osv/init.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ local client
5454

5555
local debug_hook_conn
5656

57+
local is_attached = false
58+
5759
local cache = {}
5860

5961
local start_profiler
@@ -311,6 +313,8 @@ function M.prepare_attach(blocking)
311313

312314
M.stop_freeze = false
313315

316+
is_attached = false
317+
314318
if not request.terminateDebuggee then
315319
vim.schedule(function() M.prepare_attach(false) end)
316320
end
@@ -1086,6 +1090,8 @@ function M.prepare_attach(blocking)
10861090
end
10871091
end
10881092

1093+
is_attached = true
1094+
10891095
debug.sethook(function(event, line)
10901096
if lock_debug_loop then return end
10911097

@@ -1947,6 +1953,8 @@ function M.stop()
19471953

19481954
M.stop_freeze = false
19491955

1956+
is_attached = false
1957+
19501958
if exit_autocmd then
19511959
vim.api.nvim_del_autocmd(exit_autocmd)
19521960
exit_autocmd = nil
@@ -1958,6 +1966,9 @@ function M.is_running()
19581966
return nvim_server ~= nil
19591967
end
19601968

1969+
function M.is_attached()
1970+
return is_attached
1971+
end
19611972
function M.start_trace()
19621973
function line_hook(event, line)
19631974
local surface = 0

src/launch.lua.t2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function M.prepare_attach(blocking)
5858
; implement handlers
5959
local attach_now = function()
6060
; redefine debug traceback
61+
; set is attached
6162
; attach to current instance
6263
end
6364
if blocking then

src/stop.lua.t2

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,16 @@ function M.is_running()
5454
return nvim_server ~= nil
5555
end
5656

57+
;; script variables
58+
local is_attached = false
59+
60+
;; reset internal states
61+
is_attached = false
62+
63+
;; set is attached
64+
is_attached = true
65+
66+
;; implement
67+
function M.is_attached()
68+
return is_attached
69+
end

0 commit comments

Comments
 (0)