33class Vdebug
44 class BufferNotFound < StandardError ; end ;
55
6- attr_reader :vim
6+ attr_reader :vim , :watch_win_marker
77
88 def initialize ( vim )
99 @lock_file = "../vdebug.lock"
1010 @instance_id = SecureRandom ::hex ( 3 )
1111 @vim = vim
12+ @watch_win_marker = option_value ( "marker_default" )
1213 end
1314
1415 def start_listening
@@ -75,8 +76,8 @@ def watch_window_content
7576
7677 def watch_vars
7778 watch_lines = watch_window_content . split ( "\n " ) [ 4 ..-1 ]
78- Hash [ watch_lines . join ( "" ) . split ( '|' ) . map { |v |
79- v [ 3 ..- 1 ] . split ( "=" , 2 ) . map ( &:strip )
79+ p Hash [ watch_lines . join ( "" ) . split ( '|' ) . map { |v |
80+ v . gsub ( /^.* #{ watch_win_marker } / , "" ) . split ( "=" , 2 ) . map ( &:strip )
8081 } ]
8182 end
8283
@@ -109,19 +110,30 @@ def status
109110 end
110111
111112 def remove_lock_file!
112- if File . exists? ( @lock_file ) && File . read ( @lock_file ) == @instance_id
113- puts "Deleting lock file for #{ @instance_id } "
114- File . delete ( @lock_file )
113+ if File . exists? ( @lock_file )
114+ lock_file_id = File . read ( @lock_file )
115+ if lock_file_id == @instance_id
116+ puts "Releasing lock (#{ @instance_id } )"
117+ File . delete ( @lock_file )
118+ else
119+ puts "Lock file #{ @lock_file } is for instance #{ lock_file_id } , whereas current instance is #{ @instance_id } "
120+ end
115121 end
116122 end
117123
118124protected
119125 def write_lock_file!
120- while File . exists? ( @lock_file )
121- puts "Waiting for lock to be removed"
122- sleep 0.1
126+ if File . exists? ( @lock_file )
127+
128+ puts "Waiting for vdebug lock to be released"
129+ i = 0
130+ while File . exists? ( @lock_file )
131+ sleep 0.5
132+ i += 1
133+ raise "Failed to acquire vdebug lock" if i >= 20
134+ end
123135 end
124- puts "Creating lock file for #{ @instance_id } "
136+ puts "Acquiring vdebug lock ( #{ @instance_id } ) "
125137 File . write ( @lock_file , @instance_id )
126138 end
127139
@@ -140,4 +152,8 @@ def fetch_buffers
140152 end
141153 Hash [ names . compact ]
142154 end
155+
156+ def option_value ( name )
157+ vim . echo ( "g:vdebug_options['#{ name } ']" )
158+ end
143159end
0 commit comments