syntax_tree 3.6.0 → 3.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/Gemfile.lock +1 -1
- data/lib/syntax_tree/cli.rb +3 -10
- data/lib/syntax_tree/language_server.rb +20 -14
- data/lib/syntax_tree/node.rb +21 -7
- data/lib/syntax_tree/parser.rb +27 -18
- data/lib/syntax_tree/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2feb5b8df043a9d8c8a75e6cf16f42ef1b4f84877d64ad7fe91725e4f1c4f013
|
4
|
+
data.tar.gz: e1eca9750c08fca80ada1bc3d7831a996dc01fd9f8651cd4f1d6b8c9decff0ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3e061694d3ae39053ee7b6a9ff41e1230cf714e23d037da307c720fccebd2f674505c15f74eb515e4b6b45050e665792039b8f897f8594ac7fbadc0142e4d6e
|
7
|
+
data.tar.gz: c81f87007866892f47afaa41cfe053c9af44126641fad5605e5130356791ee76fcf9bbc95082cb63bc64e4daf90051de3faeb40ec5a672d1717a7858bd830165
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [3.6.2] - 2022-10-04
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- [#165](https://github.com/ruby-syntax-tree/syntax_tree/pull/165) - Conditionals (`if`/`unless`), loops (`for`/`while`/`until`) and lambdas all had issues when comments immediately succeeded the declaration of the node where the comment could potentially be dropped. That has now been fixed.
|
14
|
+
- [#166](https://github.com/ruby-syntax-tree/syntax_tree/pull/166) - Blocks can now be formatted even if they are the top node of the tree. Previously they were looking to their parent for some additional metadata, so we now handle the case where the parent is nil.
|
15
|
+
|
16
|
+
## [3.6.1] - 2022-09-28
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- [#161](https://github.com/ruby-syntax-tree/syntax_tree/pull/161) - Previously, we were checking if STDIN was a TTY to determine if there was content to be read. Instead, we now check if no filenames were passed, and in that case we attempt to read from STDIN. This should fix errors users were experiencing in non-TTY environments like CI.
|
21
|
+
- [#162](https://github.com/ruby-syntax-tree/syntax_tree/pull/162) - Parse errors shouldn't crash the language server anymore.
|
22
|
+
|
9
23
|
## [3.6.0] - 2022-09-19
|
10
24
|
|
11
25
|
### Added
|
@@ -350,7 +364,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
350
364
|
|
351
365
|
- 🎉 Initial release! 🎉
|
352
366
|
|
353
|
-
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.
|
367
|
+
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.2...HEAD
|
368
|
+
[3.6.2]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.1...v3.6.2
|
369
|
+
[3.6.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.6.0...v3.6.1
|
354
370
|
[3.6.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.5.0...v3.6.0
|
355
371
|
[3.5.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.4.0...v3.5.0
|
356
372
|
[3.4.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v3.3.0...v3.4.0
|
data/Gemfile.lock
CHANGED
data/lib/syntax_tree/cli.rb
CHANGED
@@ -423,19 +423,12 @@ module SyntaxTree
|
|
423
423
|
return 1
|
424
424
|
end
|
425
425
|
|
426
|
-
# If we're not reading from stdin and the user didn't supply any
|
427
|
-
# filepaths to be read, then we exit with the usage message.
|
428
|
-
if $stdin.tty? && arguments.empty? && options.scripts.empty?
|
429
|
-
warn(HELP)
|
430
|
-
return 1
|
431
|
-
end
|
432
|
-
|
433
426
|
# We're going to build up a queue of items to process.
|
434
427
|
queue = Queue.new
|
435
428
|
|
436
|
-
# If
|
437
|
-
#
|
438
|
-
if
|
429
|
+
# If there are any arguments or scripts, then we'll add those to the
|
430
|
+
# queue. Otherwise we'll read the content off STDIN.
|
431
|
+
if arguments.any? || options.scripts.any?
|
439
432
|
arguments.each do |pattern|
|
440
433
|
Dir
|
441
434
|
.glob(pattern)
|
@@ -56,10 +56,10 @@ module SyntaxTree
|
|
56
56
|
store.delete(uri)
|
57
57
|
in { method: "textDocument/formatting", id:, params: { textDocument: { uri: } } }
|
58
58
|
contents = store[uri]
|
59
|
-
write(id: id, result: contents ?
|
59
|
+
write(id: id, result: contents ? format(contents, uri.split(".").last) : nil)
|
60
60
|
in { method: "textDocument/inlayHint", id:, params: { textDocument: { uri: } } }
|
61
61
|
contents = store[uri]
|
62
|
-
write(id: id, result: contents ? inlay_hints(
|
62
|
+
write(id: id, result: contents ? inlay_hints(contents) : nil)
|
63
63
|
in { method: "syntaxTree/visualizing", id:, params: { textDocument: { uri: } } }
|
64
64
|
write(id: id, result: PP.pp(SyntaxTree.parse(store[uri]), +""))
|
65
65
|
in { method: %r{\$/.+} }
|
@@ -89,19 +89,25 @@ module SyntaxTree
|
|
89
89
|
def format(source, extension)
|
90
90
|
text = SyntaxTree::HANDLERS[".#{extension}"].format(source, print_width)
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
[
|
93
|
+
{
|
94
|
+
range: {
|
95
|
+
start: {
|
96
|
+
line: 0,
|
97
|
+
character: 0
|
98
|
+
},
|
99
|
+
end: {
|
100
|
+
line: source.lines.size + 1,
|
101
|
+
character: 0
|
102
|
+
}
|
97
103
|
},
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
104
|
+
newText: text
|
105
|
+
}
|
106
|
+
]
|
107
|
+
rescue Parser::ParseError
|
108
|
+
# If there is a parse error, then we're not going to return any formatting
|
109
|
+
# changes for this source.
|
110
|
+
nil
|
105
111
|
end
|
106
112
|
|
107
113
|
def inlay_hints(source)
|
data/lib/syntax_tree/node.rb
CHANGED
@@ -1955,11 +1955,12 @@ module SyntaxTree
|
|
1955
1955
|
# If the receiver of this block a Command or CommandCall node, then there
|
1956
1956
|
# are no parentheses around the arguments to that command, so we need to
|
1957
1957
|
# break the block.
|
1958
|
-
|
1959
|
-
|
1958
|
+
case q.parent
|
1959
|
+
in { call: Command | CommandCall }
|
1960
1960
|
q.break_parent
|
1961
1961
|
format_break(q, break_opening, break_closing)
|
1962
1962
|
return
|
1963
|
+
else
|
1963
1964
|
end
|
1964
1965
|
|
1965
1966
|
q.group do
|
@@ -1978,16 +1979,26 @@ module SyntaxTree
|
|
1978
1979
|
# If we hit a statements, then we're safe to use whatever since we
|
1979
1980
|
# know for certain we're going to get split over multiple lines
|
1980
1981
|
# anyway.
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1982
|
+
case parent
|
1983
|
+
in Statements | ArgParen
|
1984
|
+
break false
|
1985
|
+
in Command | CommandCall
|
1986
|
+
true
|
1987
|
+
else
|
1988
|
+
false
|
1989
|
+
end
|
1984
1990
|
end
|
1985
1991
|
end
|
1986
1992
|
|
1987
1993
|
# If we're a sibling of a control-flow keyword, then we're going to have to
|
1988
1994
|
# use the do..end bounds.
|
1989
1995
|
def forced_do_end_bounds?(q)
|
1990
|
-
|
1996
|
+
case q.parent
|
1997
|
+
in { call: Break | Next | Return | Super }
|
1998
|
+
true
|
1999
|
+
else
|
2000
|
+
false
|
2001
|
+
end
|
1991
2002
|
end
|
1992
2003
|
|
1993
2004
|
# If we're the predicate of a loop or conditional, then we're going to have
|
@@ -2314,7 +2325,8 @@ module SyntaxTree
|
|
2314
2325
|
end
|
2315
2326
|
|
2316
2327
|
def format(q)
|
2317
|
-
|
2328
|
+
case operator
|
2329
|
+
in :"::" | Op[value: "::"]
|
2318
2330
|
q.text(".")
|
2319
2331
|
else
|
2320
2332
|
operator.format(q)
|
@@ -6004,6 +6016,8 @@ module SyntaxTree
|
|
6004
6016
|
q.group(0, "->") do
|
6005
6017
|
if params.is_a?(Paren)
|
6006
6018
|
q.format(params) unless params.contents.empty?
|
6019
|
+
elsif params.empty? && params.comments.any?
|
6020
|
+
q.format(params)
|
6007
6021
|
elsif !params.empty?
|
6008
6022
|
q.group do
|
6009
6023
|
q.text("(")
|
data/lib/syntax_tree/parser.rb
CHANGED
@@ -302,8 +302,8 @@ module SyntaxTree
|
|
302
302
|
def on_BEGIN(statements)
|
303
303
|
lbrace = find_token(LBrace)
|
304
304
|
rbrace = find_token(RBrace)
|
305
|
-
start_char = find_next_statement_start(lbrace.location.end_char)
|
306
305
|
|
306
|
+
start_char = find_next_statement_start(lbrace.location.end_char)
|
307
307
|
statements.bind(
|
308
308
|
start_char,
|
309
309
|
start_char - line_counts[lbrace.location.start_line - 1].start,
|
@@ -340,8 +340,8 @@ module SyntaxTree
|
|
340
340
|
def on_END(statements)
|
341
341
|
lbrace = find_token(LBrace)
|
342
342
|
rbrace = find_token(RBrace)
|
343
|
-
start_char = find_next_statement_start(lbrace.location.end_char)
|
344
343
|
|
344
|
+
start_char = find_next_statement_start(lbrace.location.end_char)
|
345
345
|
statements.bind(
|
346
346
|
start_char,
|
347
347
|
start_char - line_counts[lbrace.location.start_line - 1].start,
|
@@ -831,8 +831,8 @@ module SyntaxTree
|
|
831
831
|
lbrace = find_token(LBrace)
|
832
832
|
rbrace = find_token(RBrace)
|
833
833
|
location = (block_var || lbrace).location
|
834
|
-
start_char = find_next_statement_start(location.end_char)
|
835
834
|
|
835
|
+
start_char = find_next_statement_start(location.end_char)
|
836
836
|
statements.bind(
|
837
837
|
start_char,
|
838
838
|
start_char - line_counts[location.start_line - 1].start,
|
@@ -1329,8 +1329,8 @@ module SyntaxTree
|
|
1329
1329
|
|
1330
1330
|
node = tokens[index]
|
1331
1331
|
ending = node.value == "end" ? tokens.delete_at(index) : node
|
1332
|
-
start_char = find_next_statement_start(keyword.location.end_char)
|
1333
1332
|
|
1333
|
+
start_char = find_next_statement_start(keyword.location.end_char)
|
1334
1334
|
statements.bind(
|
1335
1335
|
start_char,
|
1336
1336
|
start_char - line_counts[keyword.location.start_line - 1].start,
|
@@ -1355,9 +1355,10 @@ module SyntaxTree
|
|
1355
1355
|
beginning = find_token(Kw, "elsif")
|
1356
1356
|
ending = consequent || find_token(Kw, "end")
|
1357
1357
|
|
1358
|
+
start_char = find_next_statement_start(predicate.location.end_char)
|
1358
1359
|
statements.bind(
|
1359
|
-
|
1360
|
-
predicate.location.
|
1360
|
+
start_char,
|
1361
|
+
start_char - line_counts[predicate.location.start_line - 1].start,
|
1361
1362
|
ending.location.start_char,
|
1362
1363
|
ending.location.start_column
|
1363
1364
|
)
|
@@ -1598,9 +1599,12 @@ module SyntaxTree
|
|
1598
1599
|
tokens.delete(keyword)
|
1599
1600
|
end
|
1600
1601
|
|
1602
|
+
start_char =
|
1603
|
+
find_next_statement_start((keyword || collection).location.end_char)
|
1601
1604
|
statements.bind(
|
1602
|
-
|
1603
|
-
|
1605
|
+
start_char,
|
1606
|
+
start_char -
|
1607
|
+
line_counts[(keyword || collection).location.end_line - 1].start,
|
1604
1608
|
ending.location.start_char,
|
1605
1609
|
ending.location.start_column
|
1606
1610
|
)
|
@@ -1778,9 +1782,10 @@ module SyntaxTree
|
|
1778
1782
|
beginning = find_token(Kw, "if")
|
1779
1783
|
ending = consequent || find_token(Kw, "end")
|
1780
1784
|
|
1785
|
+
start_char = find_next_statement_start(predicate.location.end_char)
|
1781
1786
|
statements.bind(
|
1782
|
-
|
1783
|
-
predicate.location.
|
1787
|
+
start_char,
|
1788
|
+
start_char - line_counts[predicate.location.end_line - 1].start,
|
1784
1789
|
ending.location.start_char,
|
1785
1790
|
ending.location.start_column
|
1786
1791
|
)
|
@@ -2024,9 +2029,10 @@ module SyntaxTree
|
|
2024
2029
|
closing = find_token(Kw, "end")
|
2025
2030
|
end
|
2026
2031
|
|
2032
|
+
start_char = find_next_statement_start(opening.location.end_char)
|
2027
2033
|
statements.bind(
|
2028
|
-
|
2029
|
-
opening.location.
|
2034
|
+
start_char,
|
2035
|
+
start_char - line_counts[opening.location.end_line - 1].start,
|
2030
2036
|
closing.location.start_char,
|
2031
2037
|
closing.location.start_column
|
2032
2038
|
)
|
@@ -3456,9 +3462,10 @@ module SyntaxTree
|
|
3456
3462
|
beginning = find_token(Kw, "unless")
|
3457
3463
|
ending = consequent || find_token(Kw, "end")
|
3458
3464
|
|
3465
|
+
start_char = find_next_statement_start(predicate.location.end_char)
|
3459
3466
|
statements.bind(
|
3460
|
-
|
3461
|
-
predicate.location.
|
3467
|
+
start_char,
|
3468
|
+
start_char - line_counts[predicate.location.end_line - 1].start,
|
3462
3469
|
ending.location.start_char,
|
3463
3470
|
ending.location.start_column
|
3464
3471
|
)
|
@@ -3498,9 +3505,10 @@ module SyntaxTree
|
|
3498
3505
|
end
|
3499
3506
|
|
3500
3507
|
# Update the Statements location information
|
3508
|
+
start_char = find_next_statement_start(predicate.location.end_char)
|
3501
3509
|
statements.bind(
|
3502
|
-
|
3503
|
-
predicate.location.
|
3510
|
+
start_char,
|
3511
|
+
start_char - line_counts[predicate.location.end_line - 1].start,
|
3504
3512
|
ending.location.start_char,
|
3505
3513
|
ending.location.start_column
|
3506
3514
|
)
|
@@ -3633,9 +3641,10 @@ module SyntaxTree
|
|
3633
3641
|
end
|
3634
3642
|
|
3635
3643
|
# Update the Statements location information
|
3644
|
+
start_char = find_next_statement_start(predicate.location.end_char)
|
3636
3645
|
statements.bind(
|
3637
|
-
|
3638
|
-
predicate.location.
|
3646
|
+
start_char,
|
3647
|
+
start_char - line_counts[predicate.location.end_line - 1].start,
|
3639
3648
|
ending.location.start_char,
|
3640
3649
|
ending.location.start_column
|
3641
3650
|
)
|
data/lib/syntax_tree/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntax_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.
|
4
|
+
version: 3.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Newton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prettier_print
|