summaryrefslogtreecommitdiff
path: root/rubylib
diff options
context:
space:
mode:
authorJon Cairns <jon@joncairns.com>2015-09-08 10:34:31 +0100
committerJon Cairns <jon@joncairns.com>2015-09-08 10:34:31 +0100
commitfb8dc22f835bfd2feb36ab7c3e1126b489867a52 (patch)
tree58a69a6392ccc1cb30c5d2096403c0bce3c663e2 /rubylib
parentb60356fc4cac743bfe1f03d93ba709867d56a540 (diff)
parent96b51f393cf56cd7add1046547d5d90ed1eb7de3 (diff)
downloadvdebug-fb8dc22f835bfd2feb36ab7c3e1126b489867a52.zip
Merge master branch into version 2
Diffstat (limited to 'rubylib')
-rw-r--r--rubylib/vdebug.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/rubylib/vdebug.rb b/rubylib/vdebug.rb
index 8718cd3..5ad99e7 100644
--- a/rubylib/vdebug.rb
+++ b/rubylib/vdebug.rb
@@ -1,17 +1,22 @@
+require 'securerandom'
+
class Vdebug
class BufferNotFound < StandardError; end;
attr_reader :vim
def initialize(vim)
+ @lock_file = "../vdebug.lock"
+ @instance_id = SecureRandom::hex(3)
@vim = vim
end
def start_listening
+ write_lock_file!
clear_buffer_cache!
vim.command "VdebugOpt background_listener 0"
vim.server.remote_send ":python debugger.run()<CR>"
- sleep 1
+ sleep 2
end
def messages
@@ -104,7 +109,23 @@ class Vdebug
/Status: (\S+)/.match(status_window_content)[1]
end
+ def remove_lock_file!
+ if File.exists?(@lock_file) && File.read(@lock_file) == @instance_id
+ puts "Deleting lock file for #{@instance_id}"
+ File.delete(@lock_file)
+ end
+ end
+
protected
+ def write_lock_file!
+ while File.exists?(@lock_file)
+ puts "Waiting for lock to be removed"
+ sleep 0.1
+ end
+ puts "Creating lock file for #{@instance_id}"
+ File.write(@lock_file, @instance_id)
+ end
+
def fetch_buffer_content(name)
bufnum = buffers.invert.fetch(name)
vim.echo(%Q{join(getbufline(#{bufnum}, 1, "$"), "\\n")})