nrepl-lazuli 0.3.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2439208ce1a3db5af7c886aa95b577bb713667461c92d129e997f378ca704926
4
- data.tar.gz: 6aabf3d36d3996ff158a2c50ebaa6239570e4799614a8d7110d50df7ca1ede4f
3
+ metadata.gz: 8c38f3cd330d07e579fff5971c656a12c4ee9f9a1488aba33d8183dd80b1236c
4
+ data.tar.gz: a63be29edddccc449e4a5bbdd9f80a05e2fb2fa0b3ca0b271ee50830da521118
5
5
  SHA512:
6
- metadata.gz: 755e29ac97e588baca03a48914cc968d23d96961c66c4a3778554bc29b2d14f05ac236f9d15a1b565318cab9a11c28bc1a07cf096911da656f1450c4ae52ac7f
7
- data.tar.gz: a6fabeadef479c719f9fa60b53587e85d0d25fd88e96a03311103b0a5a581cccb54425ebd68c9e75cb01e69335dc755631699153bb44501ec51d756d0dc693a8
6
+ metadata.gz: 2d75413ea25c513b6107daacd4f4128649c7696fc170f8536d8f636a166ce5fcb9ba675a4c218de9b9ec906f488c7cc9dfbdd48afbce0e828677d08c0bc96283
7
+ data.tar.gz: a3bb98a1bc7d9ba46d9bbc0cd1ea3b30dfa186da9444a80acf03015c427430962d4bf3f14dfc0d695b7050fe8caf632b14c1bac0a92edbe65ee9fd0f04a803c5
@@ -16,10 +16,11 @@ module NREPL
16
16
  @binding = binding
17
17
  @bindings = bindings
18
18
  @bindings_by_id = bindings_by_id
19
+ @retries = 0
19
20
  end
20
21
 
21
22
  def treat_messages!
22
- bencode = BEncode::Parser.new(@in)
23
+ bencode = BEncode.new(@in)
23
24
  loop do
24
25
  break if @in.eof?
25
26
  msg = bencode.parse!
@@ -30,6 +31,8 @@ module NREPL
30
31
  @pending_evals.each { |(i, _)| clear_eval!(i) }
31
32
  rescue Errno::ECONNRESET
32
33
  @pending_evals.each { |(i, _)| clear_eval!(i) }
34
+ rescue => e
35
+ STDOUT.puts "CRASH! #{e}"
33
36
  end
34
37
 
35
38
  def treat_msg(msg)
@@ -87,13 +90,42 @@ module NREPL
87
90
  'status' => ['done', 'interrupted'],
88
91
  'op' => msg['op']
89
92
  }))
90
-
91
93
  else
92
94
  send_msg(response_for(msg, {
93
95
  'status' => ['done'],
94
96
  'op' => msg['op']
95
97
  }))
96
98
  end
99
+ when 'update_watch_lines'
100
+ msg['id'] ||= "eval_#{@counter += 1}"
101
+ file = msg['file']
102
+ initial_line = msg['line']
103
+ delta = msg['delta']
104
+ rows_bindings = @bindings[file] || {}
105
+ rows_bindings.keys.each do |row|
106
+ if row > initial_line
107
+ watch = rows_bindings.delete(row)
108
+ new_row = row + delta
109
+ old_id = "#{file}:#{row+1}"
110
+ new_id = "#{file}:#{new_row+1}"
111
+
112
+ watch.keys.each do |id|
113
+ if id == old_id
114
+ watch_per_id = @bindings_by_id.delete(id)
115
+ @bindings_by_id[new_id] = watch_per_id.update(row: new_row)
116
+ else
117
+ @bindings_by_id[id][:row] = new_row
118
+ end
119
+ end
120
+ rows_bindings[new_row] = watch
121
+ old_binding = watch.delete(old_id)
122
+ watch[new_id] = old_binding if(old_binding)
123
+ end
124
+ end
125
+
126
+ get_watches(msg)
127
+ when 'get_watches'
128
+ get_watches(msg)
97
129
  when 'watches_for_file'
98
130
  msg['id'] ||= "eval_#{@counter += 1}"
99
131
  file = msg['file']
@@ -112,6 +144,22 @@ module NREPL
112
144
  end
113
145
  end
114
146
 
147
+ private def get_watches(msg)
148
+ msg['id'] ||= "eval_#{@counter += 1}"
149
+ file = msg['file']
150
+ rows_bindings = @bindings[file] || {}
151
+ watches = rows_bindings.flat_map do |row, watch|
152
+ watch.map do |id, _|
153
+ { 'file' => file, 'line' => row, 'id' => id }
154
+ end
155
+ end
156
+ send_msg(response_for(msg, {
157
+ 'status' => ['done'],
158
+ 'watches' => watches.sort_by { |w| w['line'] },
159
+ 'op' => msg['op']
160
+ }))
161
+ end
162
+
115
163
  private def eval_op(msg, stop)
116
164
  msg['id'] ||= "eval_#{@counter += 1}"
117
165
  id = msg['id']
@@ -174,7 +222,7 @@ module NREPL
174
222
  end
175
223
 
176
224
  private def evaluate_code(code, file, line, bind)
177
- bind ||= @@binding
225
+ bind ||= TOPLEVEL_BINDING.dup
178
226
  line = line ? line + 1 : 1
179
227
  eval(code, bind, file || "EVAL", line).inspect
180
228
  end
@@ -251,11 +299,11 @@ module NREPL
251
299
 
252
300
  def send_msg(msg)
253
301
  debug "Sending", msg
254
- @out.write(msg.bencode)
302
+ @out.write_nonblock(BEncode.encode(msg))
255
303
  @out.flush
304
+ rescue IO::EAGAINWaitWritable
305
+ @retries += 1
306
+ @out.close if @retries > 50
256
307
  end
257
308
  end
258
309
  end
259
-
260
- # To avoid locally binding with the NREPL::Connection module
261
- NREPL::Connection.class_variable_set(:@@binding, binding)
@@ -3,8 +3,8 @@
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
 
@@ -43,8 +43,18 @@ module NREPL
43
43
  @debug = debug
44
44
  @connections = Set.new
45
45
  @binding = binding
46
- @bindings = {}
47
- @bindings_by_id = {}
46
+ loc = caller_locations.reject { |x| x.absolute_path =~ /nrepl\-lazuli/ }[0]
47
+ loc = caller_locations[0] if(!loc)
48
+ path = loc.absolute_path
49
+ line = loc.lineno - 1
50
+ @bindings = {path => {line => {"NREPL::Server.start" => binding}}}
51
+ @bindings_by_id = {
52
+ "NREPL::Server.start" => {
53
+ binding: binding,
54
+ file: path,
55
+ row: line
56
+ }
57
+ }
48
58
  @tracing = tracing
49
59
  Thread.current[:nrepl_server] = self
50
60
  NREPL.class_variable_set(:@@connections, @connections)
@@ -96,17 +106,20 @@ module NREPL
96
106
  def auto_create_bindings!
97
107
  dir_regex = Regexp.new("^#{Regexp.escape(@pwd)}")
98
108
  @call_trace = TracePoint.new(:class, :call) do |tp|
99
- id = "#{tp.path}:#{tp.lineno}"
109
+ path = tp.path
110
+ next if tp.path =~ /^(\<|.eval)/
111
+ path = File.join(@pwd, path) if File.dirname(path) == '.'
112
+ id = "#{path}:#{tp.lineno}"
100
113
  b = tp.binding
101
- @bindings_by_id[id] = {binding: b, file: tp.path, row: tp.lineno-1}
102
- @bindings[tp.path] ||= {}
103
- @bindings[tp.path][tp.lineno-1] ||= {}
104
- @bindings[tp.path][tp.lineno-1][id] = b
105
- if tp.path =~ dir_regex
114
+ @bindings_by_id[id] = {binding: b, file: path, row: tp.lineno-1}
115
+ @bindings[path] ||= {}
116
+ @bindings[path][tp.lineno-1] ||= {}
117
+ @bindings[path][tp.lineno-1][id] = b
118
+ if path =~ dir_regex
106
119
  @connections.each do |connection|
107
120
  connection.send_msg(
108
121
  'op' => 'hit_auto_watch',
109
- 'file' => tp.path,
122
+ 'file' => path,
110
123
  'line' => tp.lineno-1,
111
124
  'status' => ['done']
112
125
  )
data/lib/nrepl-lazuli.rb CHANGED
@@ -27,7 +27,7 @@ module NREPL
27
27
  'op' => 'hit_watch',
28
28
  'id' => id,
29
29
  'file' => file,
30
- 'line' => row,
30
+ 'line' => row - 1,
31
31
  'status' => ['done']
32
32
  )
33
33
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nrepl-lazuli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maurício Szabo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-11 00:00:00.000000000 Z
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
11
+ date: 2024-11-13 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: A Ruby nREPL server, made to be used with Lazuli plug-in (but can be
28
14
  used with any nREPL client too)
29
15
  email: mauricio@szabo.link
@@ -38,7 +24,8 @@ files:
38
24
  homepage: https://gitlab.com/clj-editors/nrepl-lazuli
39
25
  licenses:
40
26
  - MIT
41
- metadata: {}
27
+ metadata:
28
+ source_code_uri: https://gitlab.com/clj-editors/nrepl-lazuli
42
29
  post_install_message:
43
30
  rdoc_options: []
44
31
  require_paths:
@@ -54,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
41
  - !ruby/object:Gem::Version
55
42
  version: '0'
56
43
  requirements: []
57
- rubygems_version: 3.5.9
44
+ rubygems_version: 3.5.11
58
45
  signing_key:
59
46
  specification_version: 4
60
47
  summary: A Ruby nREPL server