nrepl-lazuli 0.3.0 → 0.3.2

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: 35d0ce415821f889b64d53b1ea8f88b11a96d43a8932e00108d991b3bfc7a7fb
4
- data.tar.gz: 6b72192793c3bc68883c1396c4c86d1a1dbed7976692f75e1dfc1f3a0fecf938
3
+ metadata.gz: eabdc5490b15f4402769dbdf5a21d3eb27e206df7a5e1effcbcd8d3d919ea9fa
4
+ data.tar.gz: f3d43cf6d6d1065f676147e87a03280d08fbe29bf28f9deeede58a8cfff126fd
5
5
  SHA512:
6
- metadata.gz: 5e6639603de1e57633eb29742732ffedb483d6c101cc96c2cb9c1d3a2940e2d2aa0a49c5510d8ac3eaceccc1ed69bea56dd0e20693813ef0714e9d5ecc3f1cad
7
- data.tar.gz: bc667ae67a50840cab449027e7b6d1e990303e2986809823effec71d278811399ddc53aee3a561c3fc4dd3c0fa75ca81bcc40401b0301b0ce49f1a97f9de9f4d
6
+ metadata.gz: 49da53ef4958b719b6c46835431bdc8cbc78a5d0624d28b88994b8589ffcfd06c71fb5d44056ee1af4ec73a49a8dcadab3d03c0d3b88d6882f6df5f5a1a8386f
7
+ data.tar.gz: fb81f3e46cd3e4ec8a5b2da284b5310d3da694ec552cd3246722b19f9a57fa4404e0998faee52c63db760d9cf009fbbb0b788a0ee30c944eb8d236a322fa9dec
@@ -87,13 +87,42 @@ module NREPL
87
87
  'status' => ['done', 'interrupted'],
88
88
  'op' => msg['op']
89
89
  }))
90
-
91
90
  else
92
91
  send_msg(response_for(msg, {
93
92
  'status' => ['done'],
94
93
  'op' => msg['op']
95
94
  }))
96
95
  end
96
+ when 'update_watch_lines'
97
+ msg['id'] ||= "eval_#{@counter += 1}"
98
+ file = msg['file']
99
+ initial_line = msg['line']
100
+ delta = msg['delta']
101
+ rows_bindings = @bindings[file] || {}
102
+ rows_bindings.keys.each do |row|
103
+ if row > initial_line
104
+ watch = rows_bindings.delete(row)
105
+ new_row = row + delta
106
+ old_id = "#{file}:#{row+1}"
107
+ new_id = "#{file}:#{new_row+1}"
108
+
109
+ watch.keys.each do |id|
110
+ if id == old_id
111
+ watch_per_id = @bindings_by_id.delete(id)
112
+ @bindings_by_id[new_id] = watch_per_id.update(row: new_row)
113
+ else
114
+ @bindings_by_id[id][:row] = new_row
115
+ end
116
+ end
117
+ rows_bindings[new_row] = watch
118
+ old_binding = watch.delete(old_id)
119
+ watch[new_id] = old_binding if(old_binding)
120
+ end
121
+ end
122
+
123
+ get_watches(msg)
124
+ when 'get_watches'
125
+ get_watches(msg)
97
126
  when 'watches_for_file'
98
127
  msg['id'] ||= "eval_#{@counter += 1}"
99
128
  file = msg['file']
@@ -112,6 +141,22 @@ module NREPL
112
141
  end
113
142
  end
114
143
 
144
+ private def get_watches(msg)
145
+ msg['id'] ||= "eval_#{@counter += 1}"
146
+ file = msg['file']
147
+ rows_bindings = @bindings[file] || {}
148
+ watches = rows_bindings.flat_map do |row, watch|
149
+ watch.map do |id, _|
150
+ { 'file' => file, 'line' => row, 'id' => id }
151
+ end
152
+ end
153
+ send_msg(response_for(msg, {
154
+ 'status' => ['done'],
155
+ 'watches' => watches.sort_by { |w| w['line'] },
156
+ 'op' => msg['op']
157
+ }))
158
+ end
159
+
115
160
  private def eval_op(msg, stop)
116
161
  msg['id'] ||= "eval_#{@counter += 1}"
117
162
  id = msg['id']
@@ -173,6 +218,12 @@ module NREPL
173
218
  end
174
219
  end
175
220
 
221
+ private def evaluate_code(code, file, line, bind)
222
+ bind ||= TOPLEVEL_BINDING.dup
223
+ line = line ? line + 1 : 1
224
+ eval(code, bind, file || "EVAL", line).inspect
225
+ end
226
+
176
227
  private def find_row_based_binding(msg)
177
228
  file = msg['file']
178
229
  row = msg['line']
@@ -250,11 +301,3 @@ module NREPL
250
301
  end
251
302
  end
252
303
  end
253
-
254
- # To avoid locally binding with the NREPL::Connection module
255
- b = binding
256
- define_method(:evaluate_code) do |code, file, line, bind|
257
- bind ||= b
258
- line = line ? line + 1 : 1
259
- eval(code, bind, file || "EVAL", line).inspect
260
- end
@@ -13,7 +13,7 @@ module NREPL
13
13
  attr_reader :debug, :port, :host
14
14
  alias debug? debug
15
15
 
16
- def self.spawn(args)
16
+ def self.spawn(args = {})
17
17
  t = Thread.new {
18
18
  new(**args).start
19
19
  }
@@ -96,17 +96,20 @@ module NREPL
96
96
  def auto_create_bindings!
97
97
  dir_regex = Regexp.new("^#{Regexp.escape(@pwd)}")
98
98
  @call_trace = TracePoint.new(:class, :call) do |tp|
99
- id = "#{tp.path}:#{tp.lineno}"
99
+ path = tp.path
100
+ next if tp.path =~ /^(\<|.eval)/
101
+ path = File.join(@pwd, path) if File.dirname(path) == '.'
102
+ id = "#{path}:#{tp.lineno}"
100
103
  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
104
+ @bindings_by_id[id] = {binding: b, file: path, row: tp.lineno-1}
105
+ @bindings[path] ||= {}
106
+ @bindings[path][tp.lineno-1] ||= {}
107
+ @bindings[path][tp.lineno-1][id] = b
108
+ if path =~ dir_regex
106
109
  @connections.each do |connection|
107
110
  connection.send_msg(
108
111
  'op' => 'hit_auto_watch',
109
- 'file' => tp.path,
112
+ 'file' => path,
110
113
  'line' => tp.lineno-1,
111
114
  'status' => ['done']
112
115
  )
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nrepl-lazuli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
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-06-13 00:00:00.000000000 Z
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bencode
@@ -38,7 +38,8 @@ files:
38
38
  homepage: https://gitlab.com/clj-editors/nrepl-lazuli
39
39
  licenses:
40
40
  - MIT
41
- metadata: {}
41
+ metadata:
42
+ source_code_uri: https://gitlab.com/clj-editors/nrepl-lazuli
42
43
  post_install_message:
43
44
  rdoc_options: []
44
45
  require_paths: