File tree Expand file tree Collapse file tree 3 files changed +44
-13
lines changed Expand file tree Collapse file tree 3 files changed +44
-13
lines changed Original file line number Diff line number Diff line change 1
1
require 'vimrunner'
2
+ require 'securerandom'
2
3
require_relative "../../rubylib/vdebug"
3
4
4
- PHP_INI = File . expand_path ( '../../../.travis.php.ini' , __FILE__ )
5
+ begin
6
+ TMP_DIR = "tmpspace_#{ SecureRandom ::hex ( 3 ) } "
7
+ PHP_INI = File . expand_path ( '../../../.travis.php.ini' , __FILE__ )
5
8
6
- Before do
7
- Dir . mkdir 'tmpspace' unless Dir . exists? 'tmpspace'
8
- Dir . chdir 'tmpspace'
9
+ Before do
10
+ Dir . mkdir TMP_DIR unless Dir . exists? TMP_DIR
11
+ Dir . chdir TMP_DIR
9
12
10
- # Setup plugin in the Vim instance
11
- plugin_path = File . expand_path ( '../../..' , __FILE__ )
12
- vim . add_plugin ( plugin_path , 'plugin/vdebug.vim' )
13
- end
13
+ # Setup plugin in the Vim instance
14
+ plugin_path = File . expand_path ( '../../..' , __FILE__ )
15
+ vim . add_plugin ( plugin_path , 'plugin/vdebug.vim' )
16
+ end
17
+
18
+ After do
19
+ kill_vim
20
+ Dir . chdir '..'
21
+ system "rm -r #{ TMP_DIR } "
22
+ end
14
23
15
- After do
16
- kill_vim
17
- Dir . chdir '..'
18
- system "rm -r tmpspace"
24
+ rescue Exception
25
+ system "rm -r #{ TMP_DIR } "
26
+ raise
19
27
end
Original file line number Diff line number Diff line change @@ -13,7 +13,10 @@ def kill_vim
13
13
if @vim
14
14
@vim . kill
15
15
@vim = nil
16
- @vdebug = nil
16
+ if @vdebug
17
+ @vdebug . remove_lock_file!
18
+ @vdebug = nil
19
+ end
17
20
end
18
21
end
19
22
end
Original file line number Diff line number Diff line change
1
+ require 'securerandom'
2
+
1
3
class Vdebug
2
4
class BufferNotFound < StandardError ; end ;
3
5
4
6
attr_reader :vim
5
7
6
8
def initialize ( vim )
9
+ @lock_file = "../vdebug.lock"
10
+ @instance_id = SecureRandom ::hex ( 3 )
7
11
@vim = vim
8
12
end
9
13
10
14
def start_listening
15
+ write_lock_file!
11
16
clear_buffer_cache!
12
17
vim . server . remote_send ":python debugger.run()<CR>"
13
18
sleep 1
@@ -103,7 +108,22 @@ def status
103
108
/Status: (\S +)/ . match ( status_window_content ) [ 1 ]
104
109
end
105
110
111
+ 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 )
115
+ end
116
+ end
117
+
106
118
protected
119
+ def write_lock_file!
120
+ while File . exists? ( @lock_file )
121
+ sleep 0.1
122
+ end
123
+ puts "Creating lock file for #{ @instance_id } "
124
+ File . write ( @lock_file , @instance_id )
125
+ end
126
+
107
127
def fetch_buffer_content ( name )
108
128
bufnum = buffers . invert . fetch ( name )
109
129
vim . echo ( %Q{join(getbufline(#{ bufnum } , 1, "$"), "\\ n")} )
You can’t perform that action at this time.
0 commit comments