steep-activesupport-4 1.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.gitmodules +0 -0
  4. data/CHANGELOG.md +1032 -0
  5. data/LICENSE +21 -0
  6. data/README.md +260 -0
  7. data/Rakefile +227 -0
  8. data/Steepfile +68 -0
  9. data/bin/console +14 -0
  10. data/bin/generate-diagnostics-docs.rb +112 -0
  11. data/bin/mem_graph.rb +67 -0
  12. data/bin/mem_prof.rb +102 -0
  13. data/bin/output_rebaseline.rb +34 -0
  14. data/bin/output_test.rb +60 -0
  15. data/bin/rbs +20 -0
  16. data/bin/rbs-inline +19 -0
  17. data/bin/setup +9 -0
  18. data/bin/stackprof_test.rb +19 -0
  19. data/bin/steep +19 -0
  20. data/bin/steep-check.rb +251 -0
  21. data/bin/steep-prof +16 -0
  22. data/doc/narrowing.md +195 -0
  23. data/doc/shape.md +194 -0
  24. data/exe/steep +18 -0
  25. data/guides/README.md +5 -0
  26. data/guides/src/gem-rbs-collection/gem-rbs-collection.md +126 -0
  27. data/guides/src/getting-started/getting-started.md +163 -0
  28. data/guides/src/nil-optional/nil-optional.md +195 -0
  29. data/lib/steep/annotation_parser.rb +199 -0
  30. data/lib/steep/ast/annotation/collection.rb +172 -0
  31. data/lib/steep/ast/annotation.rb +137 -0
  32. data/lib/steep/ast/builtin.rb +104 -0
  33. data/lib/steep/ast/ignore.rb +148 -0
  34. data/lib/steep/ast/node/type_application.rb +88 -0
  35. data/lib/steep/ast/node/type_assertion.rb +81 -0
  36. data/lib/steep/ast/types/any.rb +35 -0
  37. data/lib/steep/ast/types/boolean.rb +45 -0
  38. data/lib/steep/ast/types/bot.rb +35 -0
  39. data/lib/steep/ast/types/class.rb +43 -0
  40. data/lib/steep/ast/types/factory.rb +557 -0
  41. data/lib/steep/ast/types/helper.rb +40 -0
  42. data/lib/steep/ast/types/instance.rb +42 -0
  43. data/lib/steep/ast/types/intersection.rb +93 -0
  44. data/lib/steep/ast/types/literal.rb +59 -0
  45. data/lib/steep/ast/types/logic.rb +84 -0
  46. data/lib/steep/ast/types/name.rb +128 -0
  47. data/lib/steep/ast/types/nil.rb +41 -0
  48. data/lib/steep/ast/types/proc.rb +117 -0
  49. data/lib/steep/ast/types/record.rb +79 -0
  50. data/lib/steep/ast/types/self.rb +43 -0
  51. data/lib/steep/ast/types/shared_instance.rb +11 -0
  52. data/lib/steep/ast/types/top.rb +35 -0
  53. data/lib/steep/ast/types/tuple.rb +60 -0
  54. data/lib/steep/ast/types/union.rb +97 -0
  55. data/lib/steep/ast/types/var.rb +65 -0
  56. data/lib/steep/ast/types/void.rb +35 -0
  57. data/lib/steep/cli.rb +401 -0
  58. data/lib/steep/diagnostic/deprecated/else_on_exhaustive_case.rb +20 -0
  59. data/lib/steep/diagnostic/deprecated/unknown_constant_assigned.rb +28 -0
  60. data/lib/steep/diagnostic/helper.rb +18 -0
  61. data/lib/steep/diagnostic/lsp_formatter.rb +78 -0
  62. data/lib/steep/diagnostic/result_printer2.rb +48 -0
  63. data/lib/steep/diagnostic/ruby.rb +1221 -0
  64. data/lib/steep/diagnostic/signature.rb +570 -0
  65. data/lib/steep/drivers/annotations.rb +52 -0
  66. data/lib/steep/drivers/check.rb +339 -0
  67. data/lib/steep/drivers/checkfile.rb +210 -0
  68. data/lib/steep/drivers/diagnostic_printer.rb +105 -0
  69. data/lib/steep/drivers/init.rb +66 -0
  70. data/lib/steep/drivers/langserver.rb +56 -0
  71. data/lib/steep/drivers/print_project.rb +113 -0
  72. data/lib/steep/drivers/stats.rb +203 -0
  73. data/lib/steep/drivers/utils/driver_helper.rb +143 -0
  74. data/lib/steep/drivers/utils/jobs_option.rb +26 -0
  75. data/lib/steep/drivers/vendor.rb +27 -0
  76. data/lib/steep/drivers/watch.rb +194 -0
  77. data/lib/steep/drivers/worker.rb +58 -0
  78. data/lib/steep/equatable.rb +23 -0
  79. data/lib/steep/expectations.rb +228 -0
  80. data/lib/steep/index/rbs_index.rb +350 -0
  81. data/lib/steep/index/signature_symbol_provider.rb +185 -0
  82. data/lib/steep/index/source_index.rb +167 -0
  83. data/lib/steep/interface/block.rb +103 -0
  84. data/lib/steep/interface/builder.rb +843 -0
  85. data/lib/steep/interface/function.rb +1090 -0
  86. data/lib/steep/interface/method_type.rb +330 -0
  87. data/lib/steep/interface/shape.rb +239 -0
  88. data/lib/steep/interface/substitution.rb +159 -0
  89. data/lib/steep/interface/type_param.rb +115 -0
  90. data/lib/steep/located_value.rb +20 -0
  91. data/lib/steep/method_name.rb +42 -0
  92. data/lib/steep/module_helper.rb +24 -0
  93. data/lib/steep/node_helper.rb +273 -0
  94. data/lib/steep/path_helper.rb +30 -0
  95. data/lib/steep/project/dsl.rb +268 -0
  96. data/lib/steep/project/group.rb +31 -0
  97. data/lib/steep/project/options.rb +63 -0
  98. data/lib/steep/project/pattern.rb +59 -0
  99. data/lib/steep/project/target.rb +92 -0
  100. data/lib/steep/project.rb +78 -0
  101. data/lib/steep/rake_task.rb +132 -0
  102. data/lib/steep/range_extension.rb +29 -0
  103. data/lib/steep/server/base_worker.rb +97 -0
  104. data/lib/steep/server/change_buffer.rb +73 -0
  105. data/lib/steep/server/custom_methods.rb +77 -0
  106. data/lib/steep/server/delay_queue.rb +45 -0
  107. data/lib/steep/server/interaction_worker.rb +492 -0
  108. data/lib/steep/server/lsp_formatter.rb +455 -0
  109. data/lib/steep/server/master.rb +912 -0
  110. data/lib/steep/server/target_group_files.rb +205 -0
  111. data/lib/steep/server/type_check_controller.rb +366 -0
  112. data/lib/steep/server/type_check_worker.rb +303 -0
  113. data/lib/steep/server/work_done_progress.rb +64 -0
  114. data/lib/steep/server/worker_process.rb +176 -0
  115. data/lib/steep/services/completion_provider.rb +802 -0
  116. data/lib/steep/services/content_change.rb +61 -0
  117. data/lib/steep/services/file_loader.rb +74 -0
  118. data/lib/steep/services/goto_service.rb +441 -0
  119. data/lib/steep/services/hover_provider/rbs.rb +88 -0
  120. data/lib/steep/services/hover_provider/ruby.rb +221 -0
  121. data/lib/steep/services/hover_provider/singleton_methods.rb +20 -0
  122. data/lib/steep/services/path_assignment.rb +46 -0
  123. data/lib/steep/services/signature_help_provider.rb +202 -0
  124. data/lib/steep/services/signature_service.rb +428 -0
  125. data/lib/steep/services/stats_calculator.rb +68 -0
  126. data/lib/steep/services/type_check_service.rb +394 -0
  127. data/lib/steep/services/type_name_completion.rb +236 -0
  128. data/lib/steep/signature/validator.rb +651 -0
  129. data/lib/steep/source/ignore_ranges.rb +69 -0
  130. data/lib/steep/source.rb +691 -0
  131. data/lib/steep/subtyping/cache.rb +30 -0
  132. data/lib/steep/subtyping/check.rb +1113 -0
  133. data/lib/steep/subtyping/constraints.rb +341 -0
  134. data/lib/steep/subtyping/relation.rb +101 -0
  135. data/lib/steep/subtyping/result.rb +324 -0
  136. data/lib/steep/subtyping/variable_variance.rb +89 -0
  137. data/lib/steep/test.rb +9 -0
  138. data/lib/steep/thread_waiter.rb +43 -0
  139. data/lib/steep/type_construction.rb +5183 -0
  140. data/lib/steep/type_inference/block_params.rb +416 -0
  141. data/lib/steep/type_inference/case_when.rb +303 -0
  142. data/lib/steep/type_inference/constant_env.rb +56 -0
  143. data/lib/steep/type_inference/context.rb +195 -0
  144. data/lib/steep/type_inference/logic_type_interpreter.rb +613 -0
  145. data/lib/steep/type_inference/method_call.rb +193 -0
  146. data/lib/steep/type_inference/method_params.rb +531 -0
  147. data/lib/steep/type_inference/multiple_assignment.rb +194 -0
  148. data/lib/steep/type_inference/send_args.rb +712 -0
  149. data/lib/steep/type_inference/type_env.rb +341 -0
  150. data/lib/steep/type_inference/type_env_builder.rb +138 -0
  151. data/lib/steep/typing.rb +321 -0
  152. data/lib/steep/version.rb +3 -0
  153. data/lib/steep.rb +369 -0
  154. data/manual/annotations.md +181 -0
  155. data/manual/ignore.md +20 -0
  156. data/manual/ruby-diagnostics.md +1879 -0
  157. data/sample/Steepfile +22 -0
  158. data/sample/lib/conference.rb +49 -0
  159. data/sample/lib/length.rb +35 -0
  160. data/sample/sig/conference.rbs +42 -0
  161. data/sample/sig/generics.rbs +15 -0
  162. data/sample/sig/length.rbs +34 -0
  163. data/steep-activesupport-4.gemspec +55 -0
  164. metadata +437 -0
@@ -0,0 +1,268 @@
1
+ module Steep
2
+ class Project
3
+ class DSL
4
+ module LibraryOptions
5
+ attr_reader :stdlib_root
6
+ attr_reader :core_root
7
+ attr_reader :collection_config_path
8
+
9
+ def stdlib_path(core_root:, stdlib_root:)
10
+ @core_root = Pathname(core_root)
11
+ @stdlib_root = Pathname(stdlib_root)
12
+ end
13
+
14
+ def repo_path(*paths)
15
+ @library_configured = true
16
+ repo_paths.push(*paths.map {|s| Pathname(s) })
17
+ end
18
+
19
+ def collection_config(path)
20
+ @library_configured = true
21
+ @collection_config_path = project.absolute_path(path)
22
+ end
23
+
24
+ def disable_collection
25
+ @library_configured = true
26
+ @collection_config_path = false
27
+ end
28
+
29
+ def library(*args)
30
+ @library_configured = true
31
+ libraries.push(*args)
32
+ end
33
+
34
+ def repo_paths
35
+ @repo_paths ||= []
36
+ end
37
+
38
+ def libraries
39
+ @libraries ||= []
40
+ end
41
+
42
+ def library_configured?
43
+ @library_configured
44
+ end
45
+
46
+ def to_library_options
47
+ config_path =
48
+ case collection_config_path
49
+ when Pathname
50
+ collection_config_path
51
+ when nil
52
+ default = project.absolute_path(RBS::Collection::Config::PATH)
53
+ if default.file?
54
+ default
55
+ end
56
+ when false
57
+ nil
58
+ end
59
+
60
+ Options.new.tap do |options|
61
+ options.libraries.push(*libraries)
62
+ options.paths = Options::PathOptions.new(
63
+ core_root: core_root,
64
+ stdlib_root: stdlib_root,
65
+ repo_paths: repo_paths
66
+ )
67
+ options.collection_config_path = config_path
68
+ end
69
+ end
70
+ end
71
+
72
+ module WithPattern
73
+ def check(*args)
74
+ sources.concat(args)
75
+ end
76
+
77
+ def ignore(*args)
78
+ ignored_sources.concat(args)
79
+ end
80
+
81
+ def signature(*args)
82
+ signatures.concat(args)
83
+ end
84
+
85
+ def ignore_signature(*args)
86
+ ignored_signatures.concat(args)
87
+ end
88
+
89
+ def sources
90
+ @sources ||= []
91
+ end
92
+
93
+ def ignored_sources
94
+ @ignored_sources ||= []
95
+ end
96
+
97
+ def signatures
98
+ @signatures ||= []
99
+ end
100
+
101
+ def ignored_signatures
102
+ @ignored_signatures ||= []
103
+ end
104
+
105
+ def source_pattern
106
+ Pattern.new(patterns: sources, ignores: ignored_sources, ext: ".rb")
107
+ end
108
+
109
+ def signature_pattern
110
+ Pattern.new(patterns: signatures, ignores: ignored_signatures, ext: ".rbs")
111
+ end
112
+ end
113
+
114
+ class TargetDSL
115
+ include LibraryOptions
116
+ include WithPattern
117
+
118
+ attr_reader :name
119
+ attr_reader :project
120
+ attr_reader :unreferenced
121
+ attr_reader :groups
122
+ attr_reader :implicitly_returns_nil
123
+
124
+ def initialize(name, project:)
125
+ @name = name
126
+ @core_root = nil
127
+ @stdlib_root = nil
128
+ @project = project
129
+ @collection_config_path = collection_config_path
130
+ @unreferenced = false
131
+ @implicitly_returns_nil = false
132
+ @groups = []
133
+ end
134
+
135
+ def initialize_copy(other)
136
+ @name = other.name
137
+ @libraries = other.libraries.dup
138
+ @sources = other.sources.dup
139
+ @signatures = other.signatures.dup
140
+ @ignored_sources = other.ignored_sources.dup
141
+ @ignored_signatures = other.ignored_signatures.dup
142
+ @repo_paths = other.repo_paths.dup
143
+ @core_root = other.core_root
144
+ @stdlib_root = other.stdlib_root
145
+ @code_diagnostics_config = other.code_diagnostics_config.dup
146
+ @project = other.project
147
+ @collection_config_path = other.collection_config_path
148
+ @unreferenced = other.unreferenced
149
+ @implicitly_returns_nil = other.implicitly_returns_nil
150
+ @groups = other.groups.dup
151
+ end
152
+
153
+ def unreferenced!(value = true)
154
+ @unreferenced = value
155
+ end
156
+
157
+ def implicitly_returns_nil!(value = true)
158
+ @implicitly_returns_nil = value
159
+ end
160
+
161
+ def configure_code_diagnostics(hash = nil)
162
+ if hash
163
+ code_diagnostics_config.merge!(hash)
164
+ end
165
+
166
+ yield code_diagnostics_config if block_given?
167
+ end
168
+
169
+ def code_diagnostics_config
170
+ @code_diagnostics_config ||= Diagnostic::Ruby.default.dup
171
+ end
172
+
173
+ def group(name, &block)
174
+ name = name.to_str.to_sym unless Symbol === name
175
+ group = GroupDSL.new(name, self)
176
+
177
+ Steep.logger.tagged "group=#{name}" do
178
+ group.instance_exec(&block) if block
179
+ end
180
+
181
+ groups << group
182
+ end
183
+ end
184
+
185
+ class GroupDSL
186
+ include WithPattern
187
+
188
+ attr_reader :name
189
+
190
+ attr_reader :target
191
+
192
+ attr_reader :code_diagnostics_config
193
+
194
+ def initialize(name, target)
195
+ @name = name
196
+ @target = target
197
+ end
198
+
199
+ def configure_code_diagnostics(config = nil)
200
+ if block_given?
201
+ if code_diagnostics_config
202
+ if config
203
+ code_diagnostics_config.merge!(config)
204
+ end
205
+ else
206
+ @code_diagnostics_config = (config || target.code_diagnostics_config).dup
207
+ end
208
+
209
+ yield (code_diagnostics_config || raise)
210
+ else
211
+ @code_diagnostics_config = config&.dup
212
+ end
213
+ end
214
+ end
215
+
216
+ include LibraryOptions
217
+
218
+ attr_reader :project
219
+
220
+ def initialize(project:)
221
+ @project = project
222
+ end
223
+
224
+ def self.parse(project, code, filename: "Steepfile")
225
+ Steep.logger.tagged filename do
226
+ dsl = self.new(project: project)
227
+ dsl.instance_eval(code, filename)
228
+ project.global_options = dsl.to_library_options
229
+ end
230
+ end
231
+
232
+ def self.eval(project, &block)
233
+ Steep.logger.tagged "DSL.eval" do
234
+ dsl = self.new(project: project)
235
+ dsl.instance_exec(&block)
236
+ project.global_options = dsl.to_library_options
237
+ end
238
+ end
239
+
240
+ def target(name, &block)
241
+ name = name.to_str.to_sym unless Symbol === name
242
+ dsl = TargetDSL.new(name, project: project)
243
+
244
+ Steep.logger.tagged "target=#{name}" do
245
+ dsl.instance_eval(&block) if block
246
+ end
247
+
248
+ target = Project::Target.new(
249
+ name: dsl.name,
250
+ source_pattern: dsl.source_pattern,
251
+ signature_pattern: dsl.signature_pattern,
252
+ options: dsl.library_configured? ? dsl.to_library_options : nil,
253
+ code_diagnostics_config: dsl.code_diagnostics_config,
254
+ project: project,
255
+ unreferenced: dsl.unreferenced,
256
+ implicitly_returns_nil: dsl.implicitly_returns_nil
257
+ )
258
+
259
+ dsl.groups.each do
260
+ group = Group.new(target, _1.name, _1.source_pattern, _1.signature_pattern, _1.code_diagnostics_config || target.code_diagnostics_config)
261
+ target.groups << group
262
+ end
263
+
264
+ project.targets << target
265
+ end
266
+ end
267
+ end
268
+ end
@@ -0,0 +1,31 @@
1
+ module Steep
2
+ class Project
3
+ class Group
4
+ attr_reader :name
5
+ attr_reader :source_pattern
6
+ attr_reader :signature_pattern
7
+ attr_reader :target
8
+ attr_reader :code_diagnostics_config
9
+
10
+ def initialize(target, name, source_pattern, signature_pattern, code_diagnostics_config)
11
+ @target = target
12
+ @name = name
13
+ @source_pattern = source_pattern
14
+ @signature_pattern = signature_pattern
15
+ @code_diagnostics_config = code_diagnostics_config
16
+ end
17
+
18
+ def project
19
+ target.project
20
+ end
21
+
22
+ def possible_source_file?(path)
23
+ source_pattern =~ path
24
+ end
25
+
26
+ def possible_signature_file?(path)
27
+ signature_pattern =~ path
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,63 @@
1
+ module Steep
2
+ class Project
3
+ class Options
4
+ PathOptions = _ = Struct.new(:core_root, :stdlib_root, :repo_paths, keyword_init: true) do
5
+ # @implements PathOptions
6
+
7
+ def customized_stdlib?
8
+ stdlib_root != nil
9
+ end
10
+
11
+ def customized_core?
12
+ core_root != nil
13
+ end
14
+ end
15
+
16
+ attr_reader :libraries
17
+ attr_accessor :paths
18
+ attr_accessor :collection_config_path
19
+
20
+ def initialize
21
+ @paths = PathOptions.new(repo_paths: [])
22
+ @libraries = []
23
+ end
24
+
25
+ def collection_lock_path
26
+ if collection_config_path
27
+ RBS::Collection::Config.to_lockfile_path(collection_config_path)
28
+ end
29
+ end
30
+
31
+ def load_collection_lock(force: false)
32
+ @collection_lock = nil if force
33
+ @collection_lock ||=
34
+ if collection_config_path && collection_lock_path
35
+ case
36
+ when !collection_config_path.file?
37
+ collection_config_path
38
+ when !collection_lock_path.file?
39
+ collection_lock_path
40
+ else
41
+ begin
42
+ content = YAML.load_file(collection_lock_path)
43
+ lock_file = RBS::Collection::Config::Lockfile.from_lockfile(lockfile_path: collection_lock_path, data: content)
44
+ lock_file.check_rbs_availability!
45
+ lock_file
46
+ rescue YAML::SyntaxError, RBS::Collection::Config::CollectionNotAvailable => exn
47
+ exn
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def collection_lock
54
+ case config = load_collection_lock()
55
+ when RBS::Collection::Config::Lockfile
56
+ config
57
+ else
58
+ nil
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,59 @@
1
+ module Steep
2
+ class Project
3
+ class Pattern
4
+ attr_reader :patterns
5
+ attr_reader :ignores
6
+ attr_reader :prefixes
7
+ attr_reader :ignore_prefixes
8
+ attr_reader :ext
9
+
10
+ def initialize(patterns:, ignores: [], ext:)
11
+ @patterns = patterns
12
+ @ignores = ignores
13
+ @ext = ext
14
+
15
+ @prefixes = patterns.map do |pat|
16
+ if pat == "." || pat == "./"
17
+ ""
18
+ else
19
+ pat.delete_prefix("./").delete_suffix(File::Separator) << File::Separator
20
+ end
21
+ end
22
+ @ignore_prefixes = ignores.map do |pat|
23
+ if pat == "." || pat == "./"
24
+ ""
25
+ else
26
+ pat.delete_prefix("./").delete_suffix(File::Separator) << File::Separator
27
+ end
28
+ end
29
+ end
30
+
31
+ def =~(path)
32
+ unless path.is_a?(Pathname)
33
+ path = Pathname(path.to_s)
34
+ end
35
+
36
+ match?(path) && !ignore?(path)
37
+ end
38
+
39
+ def match?(path)
40
+ test_string(path, patterns, prefixes)
41
+ end
42
+
43
+ def ignore?(path)
44
+ test_string(path, ignores, ignore_prefixes)
45
+ end
46
+
47
+ def test_string(path, patterns, prefixes)
48
+ string = path.to_s
49
+
50
+ patterns.any? {|pat| File.fnmatch(pat, string, File::FNM_PATHNAME) } ||
51
+ prefixes.any? {|prefix| File.fnmatch("#{prefix}**/*#{ext}", string, File::FNM_PATHNAME) }
52
+ end
53
+
54
+ def empty?
55
+ patterns.empty?
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,92 @@
1
+ module Steep
2
+ class Project
3
+ class Target
4
+ attr_reader :name
5
+ attr_reader :target_options
6
+
7
+ attr_reader :source_pattern
8
+ attr_reader :signature_pattern
9
+ attr_reader :code_diagnostics_config
10
+ attr_reader :project
11
+ attr_reader :unreferenced
12
+ attr_reader :groups
13
+ attr_reader :implicitly_returns_nil
14
+
15
+ def initialize(name:, options:, source_pattern:, signature_pattern:, code_diagnostics_config:, project:, unreferenced:, implicitly_returns_nil:)
16
+ @name = name
17
+ @target_options = options
18
+ @source_pattern = source_pattern
19
+ @signature_pattern = signature_pattern
20
+ @code_diagnostics_config = code_diagnostics_config
21
+ @project = project
22
+ @unreferenced = unreferenced
23
+ @groups = []
24
+ @implicitly_returns_nil = implicitly_returns_nil
25
+ end
26
+
27
+ def options
28
+ target_options || project.global_options
29
+ end
30
+
31
+ def possible_source_file?(path)
32
+ if target = groups.find { _1.possible_source_file?(path) }
33
+ return target
34
+ end
35
+
36
+ if source_pattern =~ path
37
+ return self
38
+ end
39
+
40
+ nil
41
+ end
42
+
43
+ def possible_signature_file?(path)
44
+ if target = groups.find { _1.possible_signature_file?(path) }
45
+ return target
46
+ end
47
+
48
+ if signature_pattern =~ path
49
+ return self
50
+ end
51
+
52
+ nil
53
+ end
54
+
55
+ def new_env_loader()
56
+ Target.construct_env_loader(options: options, project: project)
57
+ end
58
+
59
+ def self.construct_env_loader(options:, project:)
60
+ repo = RBS::Repository.new(no_stdlib: options.paths.customized_stdlib?)
61
+
62
+ if options.paths.stdlib_root
63
+ repo.add(project.absolute_path(options.paths.stdlib_root))
64
+ end
65
+
66
+ options.paths.repo_paths.each do |path|
67
+ repo.add(project.absolute_path(path))
68
+ end
69
+
70
+ core_root_path =
71
+ if options.paths.customized_core?
72
+ if options.paths.core_root
73
+ project.absolute_path(options.paths.core_root)
74
+ end
75
+ else
76
+ RBS::EnvironmentLoader::DEFAULT_CORE_ROOT
77
+ end
78
+
79
+ loader = RBS::EnvironmentLoader.new(core_root: core_root_path, repository: repo)
80
+
81
+ options.libraries.each do |lib|
82
+ name, version = lib.split(/:/, 2)
83
+ name or raise
84
+ loader.add(library: name, version: version)
85
+ end
86
+ loader.add_collection(options.collection_lock) if options.collection_lock
87
+
88
+ loader
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,78 @@
1
+ module Steep
2
+ class Project
3
+ attr_reader :targets
4
+ attr_reader :steepfile_path
5
+ attr_reader :base_dir
6
+ attr_accessor :global_options
7
+
8
+ def initialize(steepfile_path:, base_dir: nil)
9
+ @targets = []
10
+ @steepfile_path = steepfile_path
11
+ @base_dir = if base_dir
12
+ base_dir
13
+ elsif steepfile_path
14
+ steepfile_path.parent
15
+ else
16
+ raise ArgumentError, "Project#initialize(base_dir:): neither base_dir nor steepfile_path given"
17
+ end
18
+
19
+ if steepfile_path and !steepfile_path.absolute?
20
+ raise ArgumentError, "Project#initialize(steepfile_path:): steepfile_path should be absolute path"
21
+ end
22
+ end
23
+
24
+ def relative_path(path)
25
+ path.relative_path_from(base_dir)
26
+ rescue ArgumentError
27
+ path
28
+ end
29
+
30
+ def absolute_path(path)
31
+ (base_dir + path).cleanpath
32
+ end
33
+
34
+ def group_for_source_path(path)
35
+ path = relative_path(path)
36
+ targets.each do |target|
37
+ ret = target.possible_source_file?(path)
38
+ return ret if ret
39
+ end
40
+ nil
41
+ end
42
+
43
+ def group_for_path(path)
44
+ group_for_source_path(path) || group_for_signature_path(path)
45
+ end
46
+
47
+ def group_for_signature_path(path)
48
+ relative = relative_path(path)
49
+ targets.each do
50
+ ret = _1.possible_signature_file?(relative)
51
+ return ret if ret
52
+ end
53
+ nil
54
+ end
55
+
56
+ def target_for_source_path(path)
57
+ case group = group_for_source_path(path)
58
+ when Target
59
+ group
60
+ when Group
61
+ group.target
62
+ end
63
+ end
64
+
65
+ def target_for_signature_path(path)
66
+ case group = group_for_signature_path(path)
67
+ when Target
68
+ group
69
+ when Group
70
+ group.target
71
+ end
72
+ end
73
+
74
+ def target_for_path(path)
75
+ target_for_source_path(path) || target_for_signature_path(path)
76
+ end
77
+ end
78
+ end