syntax_tree 2.3.0 → 2.4.1
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/.github/workflows/main.yml +20 -1
- data/.rubocop.yml +80 -0
- data/CHANGELOG.md +30 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +22 -1
- data/README.md +126 -5
- data/Rakefile +27 -5
- data/config/rubocop.yml +64 -0
- data/lib/syntax_tree/cli.rb +63 -27
- data/lib/syntax_tree/formatter/single_quotes.rb +13 -0
- data/lib/syntax_tree/formatter.rb +6 -5
- data/lib/syntax_tree/language_server/inlay_hints.rb +87 -38
- data/lib/syntax_tree/language_server.rb +50 -14
- data/lib/syntax_tree/node.rb +499 -306
- data/lib/syntax_tree/parser.rb +447 -112
- data/lib/syntax_tree/plugin/single_quotes.rb +4 -0
- data/lib/syntax_tree/prettyprint.rb +28 -25
- data/lib/syntax_tree/version.rb +1 -1
- data/lib/syntax_tree/visitor/field_visitor.rb +1115 -0
- data/lib/syntax_tree/visitor/json_visitor.rb +25 -1305
- data/lib/syntax_tree/visitor/match_visitor.rb +122 -0
- data/lib/syntax_tree/visitor/pretty_print_visitor.rb +35 -1163
- data/lib/syntax_tree/visitor.rb +6 -1
- data/lib/syntax_tree.rb +19 -1
- data/syntax_tree.gemspec +21 -19
- metadata +10 -4
@@ -375,7 +375,7 @@ class PrettyPrint
|
|
375
375
|
# This argument is a noop.
|
376
376
|
# * +newline+ - Argument position expected to be here for compatibility.
|
377
377
|
# This argument is a noop.
|
378
|
-
def initialize(output,
|
378
|
+
def initialize(output, _maxwidth = nil, _newline = nil)
|
379
379
|
@output = Buffer.for(output)
|
380
380
|
@target = @output
|
381
381
|
@line_suffixes = Buffer::ArrayBuffer.new
|
@@ -397,7 +397,7 @@ class PrettyPrint
|
|
397
397
|
# They are all noop arguments.
|
398
398
|
def breakable(
|
399
399
|
separator = " ",
|
400
|
-
|
400
|
+
_width = separator.length,
|
401
401
|
indent: nil,
|
402
402
|
force: nil
|
403
403
|
)
|
@@ -410,7 +410,7 @@ class PrettyPrint
|
|
410
410
|
|
411
411
|
# Appends +separator+ to the output buffer. +width+ is a noop here for
|
412
412
|
# compatibility.
|
413
|
-
def fill_breakable(separator = " ",
|
413
|
+
def fill_breakable(separator = " ", _width = separator.length)
|
414
414
|
target << separator
|
415
415
|
end
|
416
416
|
|
@@ -419,9 +419,9 @@ class PrettyPrint
|
|
419
419
|
target.trim!
|
420
420
|
end
|
421
421
|
|
422
|
-
#
|
422
|
+
# --------------------------------------------------------------------------
|
423
423
|
# Container node builders
|
424
|
-
#
|
424
|
+
# --------------------------------------------------------------------------
|
425
425
|
|
426
426
|
# Opens a block for grouping objects to be pretty printed.
|
427
427
|
#
|
@@ -432,11 +432,11 @@ class PrettyPrint
|
|
432
432
|
# * +open_width+ - noop argument. Present for compatibility.
|
433
433
|
# * +close_width+ - noop argument. Present for compatibility.
|
434
434
|
def group(
|
435
|
-
|
435
|
+
_indent = nil,
|
436
436
|
open_object = "",
|
437
437
|
close_object = "",
|
438
|
-
|
439
|
-
|
438
|
+
_open_width = nil,
|
439
|
+
_close_width = nil
|
440
440
|
)
|
441
441
|
target << open_object
|
442
442
|
yield
|
@@ -478,14 +478,14 @@ class PrettyPrint
|
|
478
478
|
# Takes +indent+ arg, but does nothing with it.
|
479
479
|
#
|
480
480
|
# Yields to a block.
|
481
|
-
def nest(
|
481
|
+
def nest(_indent)
|
482
482
|
yield
|
483
483
|
end
|
484
484
|
|
485
485
|
# Add +object+ to the text to be output.
|
486
486
|
#
|
487
487
|
# +width+ argument is here for compatibility. It is a noop argument.
|
488
|
-
def text(object = "",
|
488
|
+
def text(object = "", _width = nil)
|
489
489
|
target << object
|
490
490
|
end
|
491
491
|
end
|
@@ -546,17 +546,17 @@ class PrettyPrint
|
|
546
546
|
last_spaces = 0
|
547
547
|
end
|
548
548
|
|
549
|
-
next_queue.each do |
|
550
|
-
case
|
549
|
+
next_queue.each do |next_part|
|
550
|
+
case next_part
|
551
551
|
when IndentPart
|
552
552
|
flush_spaces.call
|
553
553
|
add_spaces.call(2)
|
554
554
|
when StringAlignPart
|
555
555
|
flush_spaces.call
|
556
|
-
next_value +=
|
557
|
-
next_length +=
|
556
|
+
next_value += next_part.n
|
557
|
+
next_length += next_part.n.length
|
558
558
|
when NumberAlignPart
|
559
|
-
last_spaces +=
|
559
|
+
last_spaces += next_part.n
|
560
560
|
end
|
561
561
|
end
|
562
562
|
|
@@ -623,9 +623,9 @@ class PrettyPrint
|
|
623
623
|
#
|
624
624
|
def self.singleline_format(
|
625
625
|
output = "".dup,
|
626
|
-
|
627
|
-
|
628
|
-
|
626
|
+
_maxwidth = nil,
|
627
|
+
_newline = nil,
|
628
|
+
_genspace = nil
|
629
629
|
)
|
630
630
|
q = SingleLine.new(output)
|
631
631
|
yield q
|
@@ -778,16 +778,19 @@ class PrettyPrint
|
|
778
778
|
position -= buffer.trim!
|
779
779
|
when Group
|
780
780
|
if mode == MODE_FLAT && !should_remeasure
|
781
|
-
commands <<
|
782
|
-
|
781
|
+
commands << [
|
782
|
+
indent,
|
783
|
+
doc.break? ? MODE_BREAK : MODE_FLAT,
|
784
|
+
doc.contents
|
785
|
+
]
|
783
786
|
else
|
784
787
|
should_remeasure = false
|
785
788
|
next_cmd = [indent, MODE_FLAT, doc.contents]
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
+
commands << if !doc.break? &&
|
790
|
+
fits?(next_cmd, commands, maxwidth - position)
|
791
|
+
next_cmd
|
789
792
|
else
|
790
|
-
|
793
|
+
[indent, MODE_BREAK, doc.contents]
|
791
794
|
end
|
792
795
|
end
|
793
796
|
when IfBreak
|
@@ -1060,7 +1063,7 @@ class PrettyPrint
|
|
1060
1063
|
def text(object = "", width = object.length)
|
1061
1064
|
doc = target.last
|
1062
1065
|
|
1063
|
-
unless Text
|
1066
|
+
unless doc.is_a?(Text)
|
1064
1067
|
doc = Text.new
|
1065
1068
|
target << doc
|
1066
1069
|
end
|
data/lib/syntax_tree/version.rb
CHANGED