ensime_bridge 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ensime_bridge.rb +17 -8
- metadata +1 -1
data/lib/ensime_bridge.rb
CHANGED
@@ -6,13 +6,14 @@ require_relative 'ensime'
|
|
6
6
|
class EnsimeBridge
|
7
7
|
attr_accessor :socket
|
8
8
|
attr_reader :cache
|
9
|
-
def get_socket
|
10
|
-
TCPSocket.open("localhost", File.read(
|
9
|
+
def get_socket file
|
10
|
+
TCPSocket.open("localhost", File.read(file).chomp)
|
11
11
|
end
|
12
|
-
def is_running?
|
13
|
-
|
12
|
+
def is_running? file = nil
|
13
|
+
file = file.nil? ? @bridge_file : file
|
14
|
+
return false if not File.exists? file
|
14
15
|
begin
|
15
|
-
get_socket.close
|
16
|
+
get_socket(file).close
|
16
17
|
rescue => e
|
17
18
|
return false
|
18
19
|
end
|
@@ -23,9 +24,10 @@ class EnsimeBridge
|
|
23
24
|
@cache = "#{path}_cache/"
|
24
25
|
@queue = Queue.new
|
25
26
|
@bridge_file = "#{@cache}bridge"
|
27
|
+
@http_file = "#{@cache}http"
|
26
28
|
end
|
27
29
|
def remote_stop
|
28
|
-
s = get_socket
|
30
|
+
s = get_socket(@bridge_file)
|
29
31
|
s.puts "self.stop"
|
30
32
|
s.close
|
31
33
|
end
|
@@ -67,11 +69,18 @@ class EnsimeBridge
|
|
67
69
|
@queue.pop(true)
|
68
70
|
end
|
69
71
|
end
|
72
|
+
def wait_for_ensime
|
73
|
+
while not is_running? @http_file
|
74
|
+
sleep 0.2
|
75
|
+
end
|
76
|
+
end
|
70
77
|
def run
|
71
78
|
if is_running?
|
72
79
|
puts "bridge is already running"
|
73
80
|
return
|
74
81
|
end
|
82
|
+
wait_for_ensime
|
83
|
+
puts "ensime is ready"
|
75
84
|
Thread.new do
|
76
85
|
EventMachine.run do
|
77
86
|
connect_to_ensime
|
@@ -81,10 +90,10 @@ class EnsimeBridge
|
|
81
90
|
File.write(@bridge_file, server.addr[1])
|
82
91
|
while @client = server.accept
|
83
92
|
begin
|
84
|
-
command = @client.readline
|
93
|
+
command = @client.readline.chomp
|
85
94
|
while true
|
86
95
|
result = instance_eval command
|
87
|
-
if command
|
96
|
+
if command == "unqueue"
|
88
97
|
if not result.nil? and not result.empty?
|
89
98
|
@client.puts result.gsub("\n", "")
|
90
99
|
else
|