nrepl-lazuli 0.3.2 → 0.5.0
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.
- checksums.yaml +4 -4
- data/lib/nrepl-lazuli/connection.rb +17 -3
- data/lib/nrepl-lazuli/server.rb +45 -9
- data/lib/nrepl-lazuli.rb +1 -0
- metadata +4 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e7940230b6c771925c5ee557cecd7a98e043cbe94fed89efe8dee2ce77611c5
|
4
|
+
data.tar.gz: e36fda8c9c90cdb098e8e5e8307ce487cb28776d3c0de28e075964fea7acb4ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7a121b406ed724c1c433cd9a854f6082d1628b0557ebc9fb9bbd6f9e6c8a26c2f9c0390708f954ef3154b107d5234d7a332e343911426585c7fb9ec82b35247
|
7
|
+
data.tar.gz: e183f6dc2766a16297f27fbf08b7c164b9b43e8c88b753fff43bedb96b1a3ef2b7649187a53703a6d591e18c6c1d3fc7d578f7af9ac4b5b39b87c861b392f490
|
@@ -3,12 +3,16 @@ module NREPL
|
|
3
3
|
@@debug_counter = 0
|
4
4
|
|
5
5
|
def initialize(
|
6
|
-
input,
|
6
|
+
input,
|
7
|
+
server:,
|
8
|
+
debug: false,
|
9
|
+
out: input,
|
7
10
|
binding: nil,
|
8
11
|
bindings: {},
|
9
12
|
bindings_by_id: {}
|
10
13
|
)
|
11
14
|
@debug = debug
|
15
|
+
@server = server
|
12
16
|
@in = input
|
13
17
|
@out = out
|
14
18
|
@pending_evals = {}
|
@@ -16,10 +20,11 @@ module NREPL
|
|
16
20
|
@binding = binding
|
17
21
|
@bindings = bindings
|
18
22
|
@bindings_by_id = bindings_by_id
|
23
|
+
@retries = 0
|
19
24
|
end
|
20
25
|
|
21
26
|
def treat_messages!
|
22
|
-
bencode = BEncode
|
27
|
+
bencode = BEncode.new(@in)
|
23
28
|
loop do
|
24
29
|
break if @in.eof?
|
25
30
|
msg = bencode.parse!
|
@@ -30,6 +35,8 @@ module NREPL
|
|
30
35
|
@pending_evals.each { |(i, _)| clear_eval!(i) }
|
31
36
|
rescue Errno::ECONNRESET
|
32
37
|
@pending_evals.each { |(i, _)| clear_eval!(i) }
|
38
|
+
rescue => e
|
39
|
+
STDOUT.puts "CRASH! #{e}"
|
33
40
|
end
|
34
41
|
|
35
42
|
def treat_msg(msg)
|
@@ -132,6 +139,10 @@ module NREPL
|
|
132
139
|
'rows' => rows_bindings.keys.sort,
|
133
140
|
'op' => msg['op']
|
134
141
|
}))
|
142
|
+
when 'set_trace'
|
143
|
+
disable = msg['trace'] == 0
|
144
|
+
disable ? @server.call_trace.disable : @server.call_trace.enable
|
145
|
+
send_msg(response_for(msg, { 'op' => msg['op'], 'status' => ['done'] }))
|
135
146
|
else
|
136
147
|
send_msg(response_for(msg, {
|
137
148
|
'op' => msg['op'],
|
@@ -296,8 +307,11 @@ module NREPL
|
|
296
307
|
|
297
308
|
def send_msg(msg)
|
298
309
|
debug "Sending", msg
|
299
|
-
@out.
|
310
|
+
@out.write_nonblock(BEncode.encode(msg))
|
300
311
|
@out.flush
|
312
|
+
rescue IO::EAGAINWaitWritable
|
313
|
+
@retries += 1
|
314
|
+
@out.close if @retries > 50
|
301
315
|
end
|
302
316
|
end
|
303
317
|
end
|
data/lib/nrepl-lazuli/server.rb
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
# A Ruby port of ogion https://gitlab.com/technomancy/ogion &
|
4
4
|
# https://github.com/borkdude/nrepl-server/blob/master/src/borkdude/nrepl_server.clj
|
5
5
|
|
6
|
-
require 'bencode'
|
7
6
|
require 'socket'
|
7
|
+
require_relative 'bencode'
|
8
8
|
require_relative 'connection'
|
9
9
|
require_relative 'fake_stdout'
|
10
10
|
|
11
11
|
module NREPL
|
12
12
|
class Server
|
13
|
-
attr_reader :debug, :port, :host
|
13
|
+
attr_reader :debug, :port, :host, :call_trace
|
14
14
|
alias debug? debug
|
15
15
|
|
16
16
|
def self.spawn(args = {})
|
@@ -35,7 +35,8 @@ module NREPL
|
|
35
35
|
debug: false,
|
36
36
|
binding: nil,
|
37
37
|
pwd: Dir.pwd,
|
38
|
-
tracing: true
|
38
|
+
tracing: true,
|
39
|
+
loader: nil
|
39
40
|
)
|
40
41
|
@port = port
|
41
42
|
@pwd = pwd
|
@@ -43,9 +44,20 @@ module NREPL
|
|
43
44
|
@debug = debug
|
44
45
|
@connections = Set.new
|
45
46
|
@binding = binding
|
46
|
-
|
47
|
-
|
47
|
+
loc = caller_locations.reject { |x| x.absolute_path =~ /nrepl\-lazuli/ }[0]
|
48
|
+
loc = caller_locations[0] if(!loc)
|
49
|
+
path = loc.absolute_path
|
50
|
+
line = loc.lineno - 1
|
51
|
+
@bindings = {path => {line => {"NREPL::Server.start" => binding}}}
|
52
|
+
@bindings_by_id = {
|
53
|
+
"NREPL::Server.start" => {
|
54
|
+
binding: binding,
|
55
|
+
file: path,
|
56
|
+
row: line
|
57
|
+
}
|
58
|
+
}
|
48
59
|
@tracing = tracing
|
60
|
+
@loader = loader
|
49
61
|
Thread.current[:nrepl_server] = self
|
50
62
|
NREPL.class_variable_set(:@@connections, @connections)
|
51
63
|
NREPL.class_variable_set(:@@bindings, @bindings)
|
@@ -66,7 +78,7 @@ module NREPL
|
|
66
78
|
@old_out, @old_err = $stdout, $stderr
|
67
79
|
$stdout = FakeStdout.new(@connections, STDOUT, "out")
|
68
80
|
$stderr = FakeStdout.new(@connections, STDERR, "err")
|
69
|
-
auto_create_bindings!
|
81
|
+
auto_create_bindings!
|
70
82
|
|
71
83
|
Signal.trap("INT") { stop }
|
72
84
|
Signal.trap("TERM") { stop }
|
@@ -77,7 +89,8 @@ module NREPL
|
|
77
89
|
Thread.start(@socket.accept) do |client|
|
78
90
|
connection = Connection.new(
|
79
91
|
client,
|
80
|
-
|
92
|
+
server: self,
|
93
|
+
debug: @debug,
|
81
94
|
binding: @binding,
|
82
95
|
bindings_by_id: @bindings_by_id,
|
83
96
|
bindings: @bindings
|
@@ -95,7 +108,7 @@ module NREPL
|
|
95
108
|
|
96
109
|
def auto_create_bindings!
|
97
110
|
dir_regex = Regexp.new("^#{Regexp.escape(@pwd)}")
|
98
|
-
|
111
|
+
trace_proc = proc do |tp|
|
99
112
|
path = tp.path
|
100
113
|
next if tp.path =~ /^(\<|.eval)/
|
101
114
|
path = File.join(@pwd, path) if File.dirname(path) == '.'
|
@@ -105,6 +118,13 @@ module NREPL
|
|
105
118
|
@bindings[path] ||= {}
|
106
119
|
@bindings[path][tp.lineno-1] ||= {}
|
107
120
|
@bindings[path][tp.lineno-1][id] = b
|
121
|
+
path
|
122
|
+
end
|
123
|
+
@class_trace = TracePoint.new(:class, &trace_proc)
|
124
|
+
@class_trace.enable
|
125
|
+
|
126
|
+
@call_trace = TracePoint.new(:call) do |tp|
|
127
|
+
path = trace_proc.call(tp)
|
108
128
|
if path =~ dir_regex
|
109
129
|
@connections.each do |connection|
|
110
130
|
connection.send_msg(
|
@@ -116,7 +136,23 @@ module NREPL
|
|
116
136
|
end
|
117
137
|
end
|
118
138
|
end
|
119
|
-
@call_trace.enable
|
139
|
+
@call_trace.enable if @tracing
|
140
|
+
|
141
|
+
if @loader
|
142
|
+
need_to_pause = true
|
143
|
+
original_trace = nil
|
144
|
+
@loader.on_load do
|
145
|
+
next unless need_to_pause
|
146
|
+
need_to_pause = false
|
147
|
+
original_trace = call_trace.enabled?
|
148
|
+
@call_trace.disable
|
149
|
+
Thread.new do
|
150
|
+
sleep 5
|
151
|
+
@call_trace.enable if original_trace
|
152
|
+
need_to_pause = true
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
120
156
|
|
121
157
|
@ex_trace = TracePoint.new(:raise) do |tp|
|
122
158
|
e = tp.raised_exception
|
data/lib/nrepl-lazuli.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nrepl-lazuli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maurício Szabo
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bencode
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.8.2
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8.2
|
10
|
+
date: 2025-04-04 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
27
12
|
description: A Ruby nREPL server, made to be used with Lazuli plug-in (but can be
|
28
13
|
used with any nREPL client too)
|
29
14
|
email: mauricio@szabo.link
|
@@ -40,7 +25,6 @@ licenses:
|
|
40
25
|
- MIT
|
41
26
|
metadata:
|
42
27
|
source_code_uri: https://gitlab.com/clj-editors/nrepl-lazuli
|
43
|
-
post_install_message:
|
44
28
|
rdoc_options: []
|
45
29
|
require_paths:
|
46
30
|
- lib
|
@@ -55,8 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
39
|
- !ruby/object:Gem::Version
|
56
40
|
version: '0'
|
57
41
|
requirements: []
|
58
|
-
rubygems_version: 3.
|
59
|
-
signing_key:
|
42
|
+
rubygems_version: 3.6.2
|
60
43
|
specification_version: 4
|
61
44
|
summary: A Ruby nREPL server
|
62
45
|
test_files: []
|