syntax_tree 4.2.0 → 5.0.0
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/.gitattributes +1 -0
- data/.github/workflows/main.yml +2 -0
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +39 -1
- data/Gemfile.lock +4 -4
- data/README.md +111 -12
- data/lib/syntax_tree/cli.rb +61 -28
- data/lib/syntax_tree/formatter.rb +56 -20
- data/lib/syntax_tree/language_server/inlay_hints.rb +4 -6
- data/lib/syntax_tree/language_server.rb +64 -17
- data/lib/syntax_tree/node.rb +3119 -1409
- data/lib/syntax_tree/parser.rb +118 -92
- data/lib/syntax_tree/pattern.rb +179 -64
- data/lib/syntax_tree/plugin/single_quotes.rb +5 -1
- data/lib/syntax_tree/plugin/trailing_comma.rb +5 -1
- data/lib/syntax_tree/rake/task.rb +1 -1
- data/lib/syntax_tree/version.rb +1 -1
- data/lib/syntax_tree/visitor/environment.rb +7 -4
- data/lib/syntax_tree/visitor/field_visitor.rb +23 -117
- data/lib/syntax_tree/visitor/mutation_visitor.rb +924 -0
- data/lib/syntax_tree/visitor/with_environment.rb +0 -8
- data/lib/syntax_tree/visitor.rb +12 -48
- data/lib/syntax_tree.rb +14 -2
- data/syntax_tree.gemspec +1 -1
- metadata +6 -4
@@ -13,6 +13,50 @@ module SyntaxTree
|
|
13
13
|
# stree lsp
|
14
14
|
#
|
15
15
|
class LanguageServer
|
16
|
+
# This is a small module that effectively mirrors pattern matching. We're
|
17
|
+
# using it so that we can support truffleruby without having to ignore the
|
18
|
+
# language server.
|
19
|
+
module Request
|
20
|
+
# Represents a hash pattern.
|
21
|
+
class Shape
|
22
|
+
attr_reader :values
|
23
|
+
|
24
|
+
def initialize(values)
|
25
|
+
@values = values
|
26
|
+
end
|
27
|
+
|
28
|
+
def ===(other)
|
29
|
+
values.all? do |key, value|
|
30
|
+
value == :any ? other.key?(key) : value === other[key]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Represents an array pattern.
|
36
|
+
class Tuple
|
37
|
+
attr_reader :values
|
38
|
+
|
39
|
+
def initialize(values)
|
40
|
+
@values = values
|
41
|
+
end
|
42
|
+
|
43
|
+
def ===(other)
|
44
|
+
values.each_with_index.all? { |value, index| value === other[index] }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.[](value)
|
49
|
+
case value
|
50
|
+
when Array
|
51
|
+
Tuple.new(value.map { |child| self[child] })
|
52
|
+
when Hash
|
53
|
+
Shape.new(value.transform_values { |child| self[child] })
|
54
|
+
else
|
55
|
+
value
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
16
60
|
attr_reader :input, :output, :print_width
|
17
61
|
|
18
62
|
def initialize(
|
@@ -39,30 +83,33 @@ module SyntaxTree
|
|
39
83
|
|
40
84
|
# stree-ignore
|
41
85
|
case request
|
42
|
-
|
86
|
+
when Request[method: "initialize", id: :any]
|
43
87
|
store.clear
|
44
|
-
write(id: id, result: { capabilities: capabilities })
|
45
|
-
|
88
|
+
write(id: request[:id], result: { capabilities: capabilities })
|
89
|
+
when Request[method: "initialized"]
|
46
90
|
# ignored
|
47
|
-
|
91
|
+
when Request[method: "shutdown"] # tolerate missing ID to be a good citizen
|
48
92
|
store.clear
|
49
93
|
write(id: request[:id], result: {})
|
50
94
|
return
|
51
|
-
|
52
|
-
store[uri] = text
|
53
|
-
|
54
|
-
store[uri] = text
|
55
|
-
|
56
|
-
store.delete(uri)
|
57
|
-
|
95
|
+
when Request[method: "textDocument/didChange", params: { textDocument: { uri: :any }, contentChanges: [{ text: :any }] }]
|
96
|
+
store[request.dig(:params, :textDocument, :uri)] = request.dig(:params, :contentChanges, 0, :text)
|
97
|
+
when Request[method: "textDocument/didOpen", params: { textDocument: { uri: :any, text: :any } }]
|
98
|
+
store[request.dig(:params, :textDocument, :uri)] = request.dig(:params, :textDocument, :text)
|
99
|
+
when Request[method: "textDocument/didClose", params: { textDocument: { uri: :any } }]
|
100
|
+
store.delete(request.dig(:params, :textDocument, :uri))
|
101
|
+
when Request[method: "textDocument/formatting", id: :any, params: { textDocument: { uri: :any } }]
|
102
|
+
uri = request.dig(:params, :textDocument, :uri)
|
58
103
|
contents = store[uri]
|
59
|
-
write(id: id, result: contents ? format(contents, uri.split(".").last) : nil)
|
60
|
-
|
104
|
+
write(id: request[:id], result: contents ? format(contents, uri.split(".").last) : nil)
|
105
|
+
when Request[method: "textDocument/inlayHint", id: :any, params: { textDocument: { uri: :any } }]
|
106
|
+
uri = request.dig(:params, :textDocument, :uri)
|
61
107
|
contents = store[uri]
|
62
|
-
write(id: id, result: contents ? inlay_hints(contents) : nil)
|
63
|
-
|
64
|
-
|
65
|
-
|
108
|
+
write(id: request[:id], result: contents ? inlay_hints(contents) : nil)
|
109
|
+
when Request[method: "syntaxTree/visualizing", id: :any, params: { textDocument: { uri: :any } }]
|
110
|
+
uri = request.dig(:params, :textDocument, :uri)
|
111
|
+
write(id: request[:id], result: PP.pp(SyntaxTree.parse(store[uri]), +""))
|
112
|
+
when Request[method: %r{\$/.+}]
|
66
113
|
# ignored
|
67
114
|
else
|
68
115
|
raise ArgumentError, "Unhandled: #{request}"
|