ensime_bridge 0.0.6 → 0.0.7
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 +10 -32
- metadata +1 -1
data/lib/ensime_bridge.rb
CHANGED
@@ -22,13 +22,18 @@ class EnsimeBridge
|
|
22
22
|
true
|
23
23
|
end
|
24
24
|
def initialize path
|
25
|
-
@ensime = Ensime.new(path)
|
26
25
|
@quiet = false
|
27
26
|
@cache = "#{path}_cache/"
|
28
|
-
@queue = Queue.new
|
29
27
|
@bridge_file = "#{@cache}bridge"
|
30
28
|
@http_file = "#{@cache}http"
|
31
|
-
|
29
|
+
if not File.exists? path
|
30
|
+
@no_ensime_config = true
|
31
|
+
return
|
32
|
+
end
|
33
|
+
@ensime = Ensime.new(path)
|
34
|
+
@queue = Queue.new
|
35
|
+
@logger = Logger.new((File.exists?(@cache)?@cache:"/tmp/") +
|
36
|
+
"bridge.log", 2, 100000)
|
32
37
|
end
|
33
38
|
def remote_stop
|
34
39
|
if is_running?
|
@@ -39,6 +44,7 @@ class EnsimeBridge
|
|
39
44
|
end
|
40
45
|
def stop
|
41
46
|
@ensime.stop
|
47
|
+
File.delete @bridge_file if File.exists? @bridge_file
|
42
48
|
exit
|
43
49
|
end
|
44
50
|
def connect_to_ensime
|
@@ -58,16 +64,6 @@ class EnsimeBridge
|
|
58
64
|
@logger.info "Disconnected with status code: #{code} #{reason}"
|
59
65
|
end
|
60
66
|
end
|
61
|
-
def json packet
|
62
|
-
s = packet.to_json
|
63
|
-
@logger.info " to server => #{s}"
|
64
|
-
@socket.send s
|
65
|
-
end
|
66
|
-
def req message
|
67
|
-
@i ||= 0
|
68
|
-
@i += 1
|
69
|
-
json({"callId" => @i,"req" => message})
|
70
|
-
end
|
71
67
|
def unqueue
|
72
68
|
if @queue.size == 0
|
73
69
|
nil
|
@@ -91,6 +87,7 @@ class EnsimeBridge
|
|
91
87
|
return true
|
92
88
|
end
|
93
89
|
def run
|
90
|
+
return if @no_ensime_config
|
94
91
|
@ensime.quiet = quiet
|
95
92
|
@ensime.run
|
96
93
|
if is_running?
|
@@ -131,24 +128,5 @@ class EnsimeBridge
|
|
131
128
|
end
|
132
129
|
end
|
133
130
|
end
|
134
|
-
def to_position path, row, col
|
135
|
-
i = -1
|
136
|
-
File.open(path) do |f|
|
137
|
-
(row - 1).times do
|
138
|
-
i += f.readline.size
|
139
|
-
end
|
140
|
-
i += col
|
141
|
-
end
|
142
|
-
i
|
143
|
-
end
|
144
|
-
def complete path, row, col, contents = nil
|
145
|
-
i = to_position path, row, col
|
146
|
-
fileinfo = {"file"=>path}
|
147
|
-
if contents
|
148
|
-
fileinfo["contents"] = Base64.decode64(contents.gsub("!EOL!", "\n"))
|
149
|
-
end
|
150
|
-
req({"point"=>i, "maxResults"=>100,"typehint"=>"CompletionsReq",
|
151
|
-
"caseSens"=>true,"fileInfo"=> fileinfo,"reload"=>false})
|
152
|
-
end
|
153
131
|
end
|
154
132
|
EnsimeBridge.new(ARGV.size == 0 ? ".ensime" : ARGV[0]).run if __FILE__ == $0
|