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 +4 -4
- data/lib/rstfilter/exec.rb +3 -1
- data/lib/rstfilter/lsp/handler.rb +20 -3
- data/lib/rstfilter/rewriter.rb +5 -9
- data/lib/rstfilter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7748145a8ee9d8b7d736f9aa80f640f34559033cf62d46cc862dde7d20a670b2
|
4
|
+
data.tar.gz: 77c94519079d2df1ad8dcbc9d5421536b5b40f92e30bee805b9e2007ea65f818
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50bb4bbecccddec785a08aedff8a1bffcf11a9d02541e11998677e8d5b7e7979467393d33615e2776fde1c7f0468e8f3cb4ec3fafd3a2200ef1225654867e0b7
|
7
|
+
data.tar.gz: 1e020aa1db7a99c7ad82eb1c0c941b87c935bf0f603d63bba24c0173ad045232b27981e530367369a0fe8befe7dab81f017736ded1ab78d6790294660bbde1a0
|
data/lib/rstfilter/exec.rb
CHANGED
@@ -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 = {} #
|
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
|
-
#
|
300
|
+
# ignore
|
284
301
|
when 'exit'
|
285
302
|
exit(@exit_code)
|
286
303
|
else
|
data/lib/rstfilter/rewriter.rb
CHANGED
@@ -151,15 +151,11 @@ module RstFilter
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def rewrite src, filename
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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
|
data/lib/rstfilter/version.rb
CHANGED