Skip to content

Commit e5f3933

Browse files
committed
Merge remote-tracking branch 'upstream/master' into update-rdoc
2 parents f4ee1d9 + 4e7b1dd commit e5f3933

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1506
-498
lines changed

Gemfile.lock

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PATH
44
rbs (4.0.0.dev)
55
logger
66
rdoc (>= 6.13)
7+
prism (>= 1.3.0)
78

89
PATH
910
remote: test/assets/test-gem
@@ -37,7 +38,7 @@ GEM
3738
connection_pool (2.5.0)
3839
csv (3.3.3)
3940
dbm (1.1.0)
40-
diff-lcs (1.6.0)
41+
diff-lcs (1.6.1)
4142
digest (3.2.0)
4243
drb (2.2.1)
4344
ffi (1.17.1)
@@ -58,7 +59,7 @@ GEM
5859
listen (3.9.0)
5960
rb-fsevent (~> 0.10, >= 0.10.3)
6061
rb-inotify (~> 0.9, >= 0.9.10)
61-
logger (1.6.6)
62+
logger (1.7.0)
6263
marcel (1.0.4)
6364
memory_profiler (1.1.0)
6465
mini_portile2 (2.8.8)
@@ -69,16 +70,17 @@ GEM
6970
net-smtp (0.5.1)
7071
net-protocol
7172
nkf (0.2.0)
72-
nokogiri (1.18.5)
73+
nokogiri (1.18.7)
7374
mini_portile2 (~> 2.8.2)
7475
racc (~> 1.4)
7576
ostruct (0.6.1)
7677
parallel (1.26.3)
77-
parser (3.3.7.2)
78+
parser (3.3.7.4)
7879
ast (~> 2.4.1)
7980
racc
8081
pathname (0.4.0)
8182
power_assert (2.0.5)
83+
prism (1.4.0)
8284
pstore (0.2.0)
8385
psych (4.0.6)
8486
stringio
@@ -110,22 +112,24 @@ GEM
110112
diff-lcs (>= 1.2.0, < 2.0)
111113
rspec-support (~> 3.13.0)
112114
rspec-support (3.13.2)
113-
rubocop (1.74.0)
115+
rubocop (1.75.2)
114116
json (~> 2.3)
115117
language_server-protocol (~> 3.17.0.2)
116118
lint_roller (~> 1.1.0)
117119
parallel (~> 1.10)
118120
parser (>= 3.3.0.2)
119121
rainbow (>= 2.2.2, < 4.0)
120122
regexp_parser (>= 2.9.3, < 3.0)
121-
rubocop-ast (>= 1.38.0, < 2.0)
123+
rubocop-ast (>= 1.44.0, < 2.0)
122124
ruby-progressbar (~> 1.7)
123125
unicode-display_width (>= 2.4.0, < 4.0)
124-
rubocop-ast (1.40.0)
125-
parser (>= 3.3.1.0)
126-
rubocop-on-rbs (1.4.2)
126+
rubocop-ast (1.44.0)
127+
parser (>= 3.3.7.2)
128+
prism (~> 1.4)
129+
rubocop-on-rbs (1.5.0)
130+
lint_roller (~> 1.1)
127131
rbs (~> 3.5)
128-
rubocop (~> 1.61)
132+
rubocop (>= 1.72.1, < 2.0)
129133
zlib
130134
rubocop-rubycw (0.2.2)
131135
lint_roller (~> 1.1)
@@ -152,13 +156,13 @@ GEM
152156
strscan (>= 1.0.0)
153157
terminal-table (>= 2, < 5)
154158
uri (>= 0.12.0)
155-
stringio (3.1.5)
159+
stringio (3.1.6)
156160
strong_json (2.1.2)
157161
strscan (3.1.2)
158162
tempfile (0.3.1)
159163
terminal-table (4.0.0)
160164
unicode-display_width (>= 1.1.1, < 4)
161-
test-unit (3.6.7)
165+
test-unit (3.6.8)
162166
power_assert
163167
timeout (0.4.3)
164168
tzinfo (2.0.6)

Rakefile

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,21 @@ task :stdlib_test => :compile do
141141
end
142142

143143
task :typecheck_test => :compile do
144-
FileList["test/typecheck/*"].each do |test|
145-
Dir.chdir(test) do
146-
expectations = File.join(test, "steep_expectations.yml")
147-
if File.exist?(expectations)
148-
sh "steep check --with_expectations"
149-
else
150-
sh "steep check"
151-
end
152-
end
153-
end
144+
puts
145+
puts
146+
puts "⛔️⛔️⛔️⛔️⛔️⛔️ Skipping type check test because RBS is incompatible with Steep (#{__FILE__}:#{__LINE__})"
147+
puts
148+
puts
149+
# FileList["test/typecheck/*"].each do |test|
150+
# Dir.chdir(test) do
151+
# expectations = File.join(test, "steep_expectations.yml")
152+
# if File.exist?(expectations)
153+
# sh "steep check --with_expectations"
154+
# else
155+
# sh "steep check"
156+
# end
157+
# end
158+
# end
154159
end
155160

156161
task :raap => :compile do

Steepfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ target :lib do
99
)
1010

1111
library "pathname", "json", "logger", "monitor", "tsort", "uri", 'dbm', 'pstore', 'singleton', 'shellwords', 'fileutils', 'find', 'digest', 'prettyprint', 'yaml', "psych", "securerandom"
12+
library "prism"
1213
signature "stdlib/strscan/0/"
1314
signature "stdlib/optparse/0/"
1415
signature "stdlib/rdoc/0/"

lib/rbs.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
require "logger"
1111
require "tsort"
1212
require "strscan"
13+
require "prism"
1314

1415
require "rbs/errors"
1516
require "rbs/buffer"
@@ -24,8 +25,15 @@
2425
require "rbs/ast/members"
2526
require "rbs/ast/annotation"
2627
require "rbs/ast/visitor"
28+
require "rbs/ast/ruby/helpers/constant_helper"
29+
require "rbs/ast/ruby/helpers/location_helper"
30+
require "rbs/ast/ruby/declarations"
31+
require "rbs/source"
32+
require "rbs/inline_parser"
2733
require "rbs/environment"
2834
require "rbs/environment/use_map"
35+
require "rbs/environment/class_entry"
36+
require "rbs/environment/module_entry"
2937
require "rbs/environment_loader"
3038
require "rbs/builtin_names"
3139
require "rbs/definition"

lib/rbs/ast/ruby/declarations.rb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# frozen_string_literal: true
2+
3+
module RBS
4+
module AST
5+
module Ruby
6+
module Declarations
7+
class Base
8+
attr_reader :buffer
9+
10+
include Helpers::ConstantHelper
11+
include Helpers::LocationHelper
12+
13+
def initialize(buffer)
14+
@buffer = buffer
15+
end
16+
end
17+
18+
class ClassDecl < Base
19+
attr_reader :class_name
20+
21+
attr_reader :members
22+
23+
attr_reader :node
24+
25+
def initialize(buffer, name, node)
26+
super(buffer)
27+
@class_name = name
28+
@node = node
29+
@members = []
30+
end
31+
32+
def each_decl(&block)
33+
return enum_for(:each_decl) unless block
34+
35+
@members.each do |member|
36+
if member.is_a?(Base)
37+
yield member
38+
end
39+
end
40+
end
41+
42+
def super_class = nil
43+
44+
def type_params = []
45+
46+
def location
47+
rbs_location(node.location)
48+
end
49+
end
50+
51+
class ModuleDecl < Base
52+
attr_reader :module_name
53+
54+
attr_reader :members
55+
56+
attr_reader :node
57+
58+
def initialize(buffer, name, node)
59+
super(buffer)
60+
@module_name = name
61+
@node = node
62+
@members = []
63+
end
64+
65+
def each_decl(&block)
66+
return enum_for(:each_decl) unless block
67+
68+
@members.each do |member|
69+
if member.is_a?(Base)
70+
yield member
71+
end
72+
end
73+
end
74+
75+
def type_params = []
76+
77+
def self_types = []
78+
79+
def location
80+
rbs_location(node.location)
81+
end
82+
end
83+
end
84+
end
85+
end
86+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
module RBS
4+
module AST
5+
module Ruby
6+
module Helpers
7+
module ConstantHelper
8+
module_function
9+
10+
def constant_as_type_name(node)
11+
case node
12+
when Prism::ConstantPathNode, Prism::ConstantReadNode
13+
begin
14+
TypeName.parse(node.full_name)
15+
rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError
16+
nil
17+
end
18+
end
19+
end
20+
end
21+
end
22+
end
23+
end
24+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
module RBS
4+
module AST
5+
module Ruby
6+
module Helpers
7+
module LocationHelper
8+
def rbs_location(location)
9+
Location.new(buffer, location.start_character_offset, location.end_character_offset)
10+
end
11+
end
12+
end
13+
end
14+
end
15+
end

lib/rbs/cli.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,9 @@ def run_ast(args, options)
175175

176176
env = Environment.from_loader(loader).resolve_type_names
177177

178-
decls = env.declarations.select do |decl|
179-
loc = decl.location or raise
178+
decls = env.sources.select do |source|
180179
# @type var name: String
181-
name = loc.buffer.name
180+
name = source.buffer.name.to_s
182181

183182
patterns.empty? || patterns.any? do |pat|
184183
case pat
@@ -188,7 +187,7 @@ def run_ast(args, options)
188187
name.end_with?(pat) || File.fnmatch(pat, name, File::FNM_EXTGLOB)
189188
end
190189
end
191-
end
190+
end.flat_map { _1.declarations }
192191

193192
stdout.print JSON.generate(decls)
194193
stdout.flush
@@ -913,7 +912,7 @@ def run_parse(args, options)
913912
Buffer.new(content: file_path.read, name: file_path)
914913
end
915914
end
916-
bufs << Buffer.new(content: e_code, name: '-e') if e_code
915+
bufs << Buffer.new(content: e_code, name: Pathname('-e')) if e_code
917916

918917
bufs.each do |buf|
919918
RBS.logger.info "Parsing #{buf.name}..."

0 commit comments

Comments
 (0)