rstfilter 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 493aaf26c129bbac2f2e56a62a59575e0805be44d4c48e2707da454cd51d2972
4
- data.tar.gz: 164cbf3204c18b09c8dca6cb78c9059f13e49cd255c77fa793721479b337237a
3
+ metadata.gz: 7748145a8ee9d8b7d736f9aa80f640f34559033cf62d46cc862dde7d20a670b2
4
+ data.tar.gz: 77c94519079d2df1ad8dcbc9d5421536b5b40f92e30bee805b9e2007ea65f818
5
5
  SHA512:
6
- metadata.gz: 0ff94c098b3f781a767c0887b30b8b24ebb58e909930ee70865d666f920d1ff50e9de7ed47a0072bd667d39da285682ef83591d81078c6f1d5cca63cc2b07a5c
7
- data.tar.gz: 62b140c8dfde2082e39a132403f34d81b89a34c4993e814a3e847fed949ff5bf78e64125e3e7770268c4ee1d47d326252dbe25a9469a46cbb5a667bc360362e9
6
+ metadata.gz: 50bb4bbecccddec785a08aedff8a1bffcf11a9d02541e11998677e8d5b7e7979467393d33615e2776fde1c7f0468e8f3cb4ec3fafd3a2200ef1225654867e0b7
7
+ data.tar.gz: 1e020aa1db7a99c7ad82eb1c0c941b87c935bf0f603d63bba24c0173ad045232b27981e530367369a0fe8befe7dab81f017736ded1ab78d6790294660bbde1a0
@@ -198,7 +198,9 @@ module RstFilter
198
198
  ensure
199
199
  begin
200
200
  Process.kill(:KILL, io.pid)
201
- rescue Errno::ESRCH
201
+ rescue Errno::ESRCH, Errno::ECHILD
202
+ else
203
+ Process.waitpid(io.pid)
202
204
  end
203
205
  end
204
206
 
@@ -4,6 +4,9 @@ require_relative '../rewriter'
4
4
  require_relative '../exec'
5
5
 
6
6
  module RstFilter
7
+ class CancelRequest < StandardError
8
+ end
9
+
7
10
  class LSP
8
11
  def initialize input: $stdin, output: $stdout, err: $stderr, indent: 50
9
12
  @input = input
@@ -13,7 +16,7 @@ module RstFilter
13
16
  @records = {} # {filename => [record, line_record, src]}
14
17
  @server_request_id = 0
15
18
  @exit_status = 1
16
- @running = {} # id for cancel
19
+ @running = {} # {filename => Thread}
17
20
  end
18
21
 
19
22
  def self.reload
@@ -238,7 +241,7 @@ module RstFilter
238
241
  send_notice 'rstfilter/start', {
239
242
  uri: filename,
240
243
  }
241
- Thread.new do
244
+ @running[filename] = Thread.new do
242
245
  filter = RstFilter::Exec.new
243
246
  filter.optparse! ['--pp', '-eruby']
244
247
  records, src, _comments = filter.record_records(filename)
@@ -249,11 +252,25 @@ module RstFilter
249
252
  send_notice 'rstfilter/output', output: "# Output for #{filename}\n\n#{filter.output}"
250
253
  end
251
254
  send_request 'workspace/inlayHint/refresh'
255
+ rescue CancelRequest
256
+ # canceled
257
+ rescue SyntaxError => e
258
+ send_notice 'rstfilter/output', output: "SyntaxError on #{filename}:\n#{e.inspect}"
259
+ send_notice 'rstfilter/done'
260
+ rescue Exception => e
261
+ send_notice 'rstfilter/output', output: "Error on #{filename}:\n#{e.inspect}\n#{e.backtrace.join("\n")}#{filter.output}"
262
+ send_notice 'rstfilter/done'
263
+ ensure
264
+ @running[filename] = nil
252
265
  end
253
266
  end
254
267
 
255
268
  def clear_record filename
256
269
  @records[filename] = nil
270
+ if th = @running[filename]
271
+ @running[filename] = nil
272
+ th.raise CancelRequest
273
+ end
257
274
  end
258
275
 
259
276
  def uri2filename uri
@@ -280,7 +297,7 @@ module RstFilter
280
297
  filename = uri2filename req.dig(:params, :textDocument, :uri)
281
298
  clear_record filename
282
299
  when '$/cancelRequest'
283
- # TODO: cancel
300
+ # ignore
284
301
  when 'exit'
285
302
  exit(@exit_code)
286
303
  else
@@ -151,15 +151,11 @@ module RstFilter
151
151
  end
152
152
 
153
153
  def rewrite src, filename
154
- begin
155
- prev_v, $VERBOSE = $VERBOSE, false
156
- ast = RubyVM::AbstractSyntaxTree.parse(src)
157
- $VERBOSE = prev_v
158
- last_lineno = ast.last_lineno
159
- rescue SyntaxError => e
160
- err e.inspect
161
- exit 1
162
- end
154
+ # check syntax
155
+ prev_v, $VERBOSE = $VERBOSE, false
156
+ ast = RubyVM::AbstractSyntaxTree.parse(src)
157
+ $VERBOSE = prev_v
158
+ last_lineno = ast.last_lineno
163
159
 
164
160
  # rewrite
165
161
  src = src.lines[0..last_lineno].join # remove __END__ and later
@@ -1,3 +1,3 @@
1
1
  module RstFilter
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rstfilter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Sasada