steep 0.15.0 → 0.17.0

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 +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +25 -0
  4. data/Rakefile +0 -13
  5. data/bin/setup +0 -2
  6. data/bin/smoke_runner.rb +0 -1
  7. data/exe/steep +0 -1
  8. data/lib/steep.rb +12 -1
  9. data/lib/steep/cli.rb +16 -1
  10. data/lib/steep/drivers/annotations.rb +1 -1
  11. data/lib/steep/drivers/check.rb +1 -12
  12. data/lib/steep/drivers/langserver.rb +13 -462
  13. data/lib/steep/drivers/utils/driver_helper.rb +1 -1
  14. data/lib/steep/drivers/watch.rb +97 -85
  15. data/lib/steep/drivers/worker.rb +51 -0
  16. data/lib/steep/project.rb +9 -5
  17. data/lib/steep/project/completion_provider.rb +4 -2
  18. data/lib/steep/project/file.rb +2 -1
  19. data/lib/steep/project/hover_content.rb +6 -3
  20. data/lib/steep/project/options.rb +15 -0
  21. data/lib/steep/project/target.rb +30 -20
  22. data/lib/steep/server/base_worker.rb +56 -0
  23. data/lib/steep/server/code_worker.rb +151 -0
  24. data/lib/steep/server/interaction_worker.rb +281 -0
  25. data/lib/steep/server/master.rb +196 -0
  26. data/lib/steep/server/signature_worker.rb +148 -0
  27. data/lib/steep/server/utils.rb +36 -0
  28. data/lib/steep/server/worker_process.rb +62 -0
  29. data/lib/steep/signature/validator.rb +5 -5
  30. data/lib/steep/type_construction.rb +13 -19
  31. data/lib/steep/type_inference/constant_env.rb +2 -10
  32. data/lib/steep/type_inference/context.rb +1 -0
  33. data/lib/steep/version.rb +1 -1
  34. data/steep.gemspec +7 -8
  35. metadata +22 -142
  36. data/exe/rbs +0 -3
  37. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  38. data/vendor/ruby-signature/.gitignore +0 -12
  39. data/vendor/ruby-signature/.rubocop.yml +0 -15
  40. data/vendor/ruby-signature/BSDL +0 -22
  41. data/vendor/ruby-signature/COPYING +0 -56
  42. data/vendor/ruby-signature/Gemfile +0 -6
  43. data/vendor/ruby-signature/README.md +0 -93
  44. data/vendor/ruby-signature/Rakefile +0 -67
  45. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -157
  46. data/vendor/ruby-signature/bin/console +0 -14
  47. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  48. data/vendor/ruby-signature/bin/setup +0 -10
  49. data/vendor/ruby-signature/bin/sort +0 -89
  50. data/vendor/ruby-signature/bin/test_runner.rb +0 -16
  51. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  52. data/vendor/ruby-signature/docs/sigs.md +0 -148
  53. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  54. data/vendor/ruby-signature/docs/syntax.md +0 -528
  55. data/vendor/ruby-signature/exe/rbs +0 -7
  56. data/vendor/ruby-signature/lib/rbs.rb +0 -64
  57. data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
  58. data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
  59. data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
  60. data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
  61. data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
  62. data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
  63. data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
  64. data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
  65. data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
  66. data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
  67. data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
  68. data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
  69. data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
  70. data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
  71. data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
  72. data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
  73. data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
  74. data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
  75. data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
  76. data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
  77. data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
  78. data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
  79. data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
  80. data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
  81. data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
  82. data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
  83. data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
  84. data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
  85. data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
  86. data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
  87. data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
  88. data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
  89. data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
  90. data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
  91. data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
  92. data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
  93. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
  94. data/vendor/ruby-signature/rbs.gemspec +0 -45
  95. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
  96. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
  97. data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
  98. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  99. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  100. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  101. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -44
  102. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  103. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  104. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  105. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  106. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  107. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  108. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -413
  109. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
  110. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  111. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  112. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  113. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  114. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -194
  115. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  116. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  117. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  118. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -1076
  119. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  120. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  121. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -243
  122. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  123. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
  124. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  125. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
  126. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
  127. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
  128. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
  129. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
  130. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
  131. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  132. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  133. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  134. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -429
  135. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
  136. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
  137. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  138. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  139. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -57
  140. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
  141. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  142. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  143. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1901
  144. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
  145. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  146. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
  147. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
  148. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  149. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
  150. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
  151. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  152. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
  153. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  154. data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
  155. data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
  156. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
  157. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
  158. data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
  159. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
  160. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  161. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  162. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  163. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -301
  164. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -8,7 +8,7 @@ module Steep
8
8
  raise "Cannot find a configuration at #{path}: `steep init` to scaffold" unless path.file?
9
9
 
10
10
  steep_file_path = path.absolute? ? path : Pathname.pwd + path
11
- Project.new(base_dir: steep_file_path.parent).tap do |project|
11
+ Project.new(steepfile_path: steep_file_path).tap do |project|
12
12
  Project::DSL.parse(project, path.read, filename: path.to_s)
13
13
  end
14
14
  end
@@ -15,110 +15,122 @@ module Steep
15
15
  @queue = Thread::Queue.new
16
16
  end
17
17
 
18
- def listener
19
- @listener ||= begin
20
- Steep.logger.info "Watching #{dirs.join(", ")}..."
21
- Listen.to(*dirs.map(&:to_s)) do |modified, added, removed|
22
- Steep.logger.tagged "watch" do
23
- Steep.logger.info "Received file system updates: modified=[#{modified.join(",")}], added=[#{added.join(",")}], removed=[#{removed.join(",")}]"
24
- end
25
- queue << [modified, added, removed]
26
- end
18
+ def run()
19
+ if dirs.empty?
20
+ stdout.puts "Specify directories to watch"
21
+ return 1
27
22
  end
28
- end
29
23
 
30
- def type_check_loop(project)
31
- until queue.closed?
32
- stdout.puts "🚥 Waiting for updates..."
24
+ project = load_config()
33
25
 
34
- events = []
35
- events << queue.deq
36
- until queue.empty?
37
- events << queue.deq(nonblock: true)
38
- end
26
+ loader = Project::FileLoader.new(project: project)
27
+ loader.load_sources(dirs)
28
+ loader.load_signatures()
39
29
 
40
- events.compact.each do |modified, added, removed|
41
- modified.each do |name|
42
- path = Pathname(name).relative_path_from(Pathname.pwd)
30
+ client_read, server_write = IO.pipe
31
+ server_read, client_write = IO.pipe
43
32
 
44
- project.targets.each do |target|
45
- target.update_source path, path.read if target.source_file?(path)
46
- target.update_signature path, path.read if target.signature_file?(path)
47
- end
48
- end
33
+ client_reader = LanguageServer::Protocol::Transport::Io::Reader.new(client_read)
34
+ client_writer = LanguageServer::Protocol::Transport::Io::Writer.new(client_write)
49
35
 
50
- added.each do |name|
51
- path = Pathname(name).relative_path_from(Pathname.pwd)
36
+ server_reader = LanguageServer::Protocol::Transport::Io::Reader.new(server_read)
37
+ server_writer = LanguageServer::Protocol::Transport::Io::Writer.new(server_write)
52
38
 
53
- project.targets.each do |target|
54
- target.add_source path, path.read if target.possible_source_file?(path)
55
- target.add_signature path, path.read if target.possible_signature_file?(path)
56
- end
57
- end
39
+ interaction_worker = Server::WorkerProcess.spawn_worker(:interaction, name: "interaction", steepfile: project.steepfile_path)
40
+ signature_worker = Server::WorkerProcess.spawn_worker(:signature, name: "signature", steepfile: project.steepfile_path)
41
+ code_workers = Server::WorkerProcess.spawn_code_workers(steepfile: project.steepfile_path)
58
42
 
59
- removed.each do |name|
60
- path = Pathname(name).relative_path_from(Pathname.pwd)
43
+ master = Server::Master.new(
44
+ project: project,
45
+ reader: server_reader,
46
+ writer: server_writer,
47
+ interaction_worker: interaction_worker,
48
+ signature_worker: signature_worker,
49
+ code_workers: code_workers
50
+ )
61
51
 
62
- project.targets.each do |target|
63
- target.remove_source path if target.source_file?(path)
64
- target.remove_signature path if target.signature_file?(path)
65
- end
52
+ main_thread = Thread.start do
53
+ master.start()
54
+ end
55
+ main_thread.abort_on_exception = true
56
+
57
+ client_writer.write(method: "initialize", id: 0)
58
+
59
+ Steep.logger.info "Watching #{dirs.join(", ")}..."
60
+ listener = Listen.to(*dirs.map(&:to_s)) do |modified, added, removed|
61
+ stdout.puts "🔬 Type checking updated files..."
62
+
63
+ version = Time.now.to_i
64
+ Steep.logger.tagged "watch" do
65
+ Steep.logger.info "Received file system updates: modified=[#{modified.join(",")}], added=[#{added.join(",")}], removed=[#{removed.join(",")}]"
66
+
67
+ (modified + added).each do |path|
68
+ client_writer.write(
69
+ method: "textDocument/didChange",
70
+ params: {
71
+ textDocument: {
72
+ uri: "file://#{path}",
73
+ version: version
74
+ },
75
+ contentChanges: [
76
+ {
77
+ text: Pathname(path).read
78
+ }
79
+ ]
80
+ }
81
+ )
66
82
  end
67
- end
68
83
 
69
- stdout.puts "🔬 Type checking..."
70
- type_check project
71
- print_project_result project
72
- end
73
- rescue ClosedQueueError
74
- # nop
75
- end
84
+ removed.each do |path|
85
+ client_writer.write(
86
+ method: "textDocument/didChange",
87
+ params: {
88
+ textDocument: {
89
+ uri: "file://#{path}",
90
+ version: version
91
+ },
92
+ contentChanges: [
93
+ {
94
+ text: ""
95
+ }
96
+ ]
97
+ }
98
+ )
99
+ end
100
+ end
101
+ end.tap(&:start)
76
102
 
77
- def print_project_result(project)
78
- project.targets.each do |target|
79
- Steep.logger.tagged "target=#{target.name}" do
80
- case (status = target.status)
81
- when Project::Target::SignatureSyntaxErrorStatus
82
- printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
83
- printer.print_syntax_errors(status.errors)
84
- when Project::Target::SignatureValidationErrorStatus
85
- printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
86
- printer.print_semantic_errors(status.errors)
87
- when Project::Target::TypeCheckStatus
88
- status.type_check_sources.each do |source_file|
89
- source_file.errors.each do |error|
90
- error.print_to stdout
103
+ begin
104
+ stdout.puts "👀 Watching directories, Ctrl-C to stop."
105
+ client_reader.read do |response|
106
+ case response[:method]
107
+ when "textDocument/publishDiagnostics"
108
+ uri = URI.parse(response[:params][:uri])
109
+ path = project.relative_path(Pathname(uri.path))
110
+
111
+ diagnostics = response[:params][:diagnostics]
112
+
113
+ unless diagnostics.empty?
114
+ diagnostics.each do |diagnostic|
115
+ start = diagnostic[:range][:start]
116
+ loc = "#{start[:line]+1}:#{start[:character]}"
117
+ message = diagnostic[:message].chomp.lines.join(" ")
118
+
119
+ stdout.puts "#{path}:#{loc}: #{message}"
91
120
  end
92
121
  end
93
122
  end
94
123
  end
95
- end
96
- end
97
-
98
- def run()
99
- if dirs.empty?
100
- stdout.puts "Specify directories to watch"
101
- return 1
102
- end
103
-
104
- project = load_config()
105
-
106
- loader = Project::FileLoader.new(project: project)
107
- loader.load_sources([])
108
- loader.load_signatures()
109
-
110
- type_check project
111
- print_project_result project
112
-
113
- listener.start
114
-
115
- stdout.puts "👀 Watching directories, Ctrl-C to stop."
116
- begin
117
- type_check_loop project
118
124
  rescue Interrupt
119
- # bye
125
+ stdout.puts "Shutting down workers..."
126
+ client_writer.write({ method: :shutdown, id: 10000 })
127
+ client_writer.write({ method: :exit })
128
+ client_writer.io.close()
120
129
  end
121
130
 
131
+ listener.stop
132
+ main_thread.join
133
+
122
134
  0
123
135
  end
124
136
  end
@@ -0,0 +1,51 @@
1
+ module Steep
2
+ module Drivers
3
+ class Worker
4
+ attr_reader :stdout, :stderr, :stdin
5
+
6
+ attr_accessor :steepfile_path
7
+ attr_accessor :worker_type
8
+ attr_accessor :worker_name
9
+
10
+ include Utils::DriverHelper
11
+
12
+ def initialize(stdout:, stderr:, stdin:)
13
+ @stdout = stdout
14
+ @stderr = stderr
15
+ @stdin = stdin
16
+ end
17
+
18
+ def run()
19
+ Steep.logger.tagged("#{worker_type}:#{worker_name}") do
20
+ project = load_config()
21
+
22
+ loader = Project::FileLoader.new(project: project)
23
+ loader.load_sources([])
24
+ loader.load_signatures()
25
+
26
+ reader = LanguageServer::Protocol::Transport::Io::Reader.new(stdin)
27
+ writer = LanguageServer::Protocol::Transport::Io::Writer.new(stdout)
28
+
29
+ worker = case worker_type
30
+ when :code
31
+ Server::CodeWorker.new(project: project, reader: reader, writer: writer)
32
+ when :signature
33
+ Server::SignatureWorker.new(project: project, reader: reader, writer: writer)
34
+ when :interaction
35
+ Server::InteractionWorker.new(project: project, reader: reader, writer: writer)
36
+ else
37
+ raise "Unknown worker type: #{worker_type}"
38
+ end
39
+
40
+ Steep.logger.info "Starting #{worker_type} worker..."
41
+
42
+ worker.run()
43
+ rescue Interrupt
44
+ Steep.logger.info "Shutting down by interrupt..."
45
+ end
46
+
47
+ 0
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,17 +1,21 @@
1
1
  module Steep
2
2
  class Project
3
3
  attr_reader :targets
4
- attr_reader :base_dir
4
+ attr_reader :steepfile_path
5
5
 
6
- def initialize(base_dir:)
6
+ def initialize(steepfile_path:)
7
7
  @targets = []
8
- @base_dir = base_dir
8
+ @steepfile_path = steepfile_path
9
9
 
10
- unless base_dir.absolute?
11
- raise "Project#initialize(base_dir:): base_dir should be absolute path"
10
+ unless steepfile_path.absolute?
11
+ raise "Project#initialize(steepfile_path:): steepfile_path should be absolute path"
12
12
  end
13
13
  end
14
14
 
15
+ def base_dir
16
+ steepfile_path.parent
17
+ end
18
+
15
19
  def relative_path(path)
16
20
  path.relative_path_from(base_dir)
17
21
  end
@@ -47,8 +47,10 @@ module Steep
47
47
  position = Position.new(line: line, column: column)
48
48
 
49
49
  begin
50
- Steep.measure "type_check!" do
51
- type_check!(source_text)
50
+ Steep.logger.tagged "completion_provider#run(line: #{line}, column: #{column})" do
51
+ Steep.measure "type_check!" do
52
+ type_check!(source_text)
53
+ end
52
54
  end
53
55
 
54
56
  Steep.measure "completion item collection" do
@@ -42,7 +42,7 @@ module Steep
42
42
 
43
43
  def self.type_check(source, subtyping:)
44
44
  annotations = source.annotations(block: source.node, factory: subtyping.factory, current_module: AST::Namespace.root)
45
- const_env = TypeInference::ConstantEnv.new(factory: subtyping.factory, context: nil)
45
+ const_env = TypeInference::ConstantEnv.new(factory: subtyping.factory, context: [AST::Namespace.root])
46
46
  type_env = TypeInference::TypeEnv.build(annotations: annotations,
47
47
  subtyping: subtyping,
48
48
  const_env: const_env,
@@ -96,6 +96,7 @@ module Steep
96
96
  timestamp: Time.now
97
97
  )
98
98
  rescue => exn
99
+ Steep.log_error(exn)
99
100
  @status = TypeCheckErrorStatus.new(error: exn)
100
101
  end
101
102
 
@@ -33,9 +33,12 @@ module Steep
33
33
  end
34
34
 
35
35
  def content_for(path:, line:, column:)
36
- source_file = project.targets.map {|target| target.source_files[path] }.compact[0]
36
+ target = project.targets.find {|target| target.source_file?(path) }
37
+
38
+ if target
39
+ source_file = target.source_files[path]
40
+ target.type_check(target_sources: [source_file], validate_signatures: false)
37
41
 
38
- if source_file
39
42
  case (status = source_file.status)
40
43
  when SourceFile::TypeCheckStatus
41
44
  node, *parents = status.source.find_nodes(line: line, column: column)
@@ -107,7 +110,7 @@ module Steep
107
110
  context = status.typing.context_at(line: line, column: column)
108
111
  method_context = context.method_context
109
112
 
110
- if method_context
113
+ if method_context && method_context.method
111
114
  DefinitionContent.new(
112
115
  node: node,
113
116
  method_name: method_context.name,
@@ -37,6 +37,21 @@ module Steep
37
37
  self.allow_unknown_constant_assignment = true
38
38
  self.allow_unknown_method_calls = true
39
39
  end
40
+
41
+ def error_to_report?(error)
42
+ case
43
+ when error.is_a?(Errors::FallbackAny)
44
+ !allow_fallback_any
45
+ when error.is_a?(Errors::MethodDefinitionMissing)
46
+ !allow_missing_definitions
47
+ when error.is_a?(Errors::NoMethod)
48
+ !allow_unknown_method_calls
49
+ when error.is_a?(Errors::UnknownConstantAssigned)
50
+ !allow_unknown_constant_assignment
51
+ else
52
+ true
53
+ end
54
+ end
40
55
  end
41
56
  end
42
57
  end
@@ -67,24 +67,30 @@ module Steep
67
67
  end
68
68
 
69
69
  def possible_source_file?(path)
70
- self.class.test_pattern(source_patterns, path) &&
71
- !self.class.test_pattern(ignore_patterns, path)
70
+ self.class.test_pattern(source_patterns, path, ext: ".rb") &&
71
+ !self.class.test_pattern(ignore_patterns, path, ext: ".rb")
72
72
  end
73
73
 
74
74
  def possible_signature_file?(path)
75
- self.class.test_pattern(signature_patterns, path)
75
+ self.class.test_pattern(signature_patterns, path, ext: ".rbs")
76
76
  end
77
77
 
78
- def self.test_pattern(patterns, path)
78
+ def self.test_pattern(patterns, path, ext:)
79
79
  patterns.any? do |pattern|
80
80
  p = pattern.end_with?(File::Separator) ? pattern : pattern + File::Separator
81
- path.to_s.start_with?(p) || File.fnmatch(pattern, path.to_s)
81
+ (path.to_s.start_with?(p) && path.extname == ext) || File.fnmatch(pattern, path.to_s)
82
82
  end
83
83
  end
84
84
 
85
- def type_check
86
- load_signatures do |env, check, timestamp|
87
- run_type_check(env, check, timestamp)
85
+ def type_check(target_sources: source_files.values, validate_signatures: true)
86
+ Steep.logger.tagged "target#type_check(target_sources: [#{target_sources.map(&:path).join(", ")}], validate_signatures: #{validate_signatures})" do
87
+ Steep.measure "load signature and type check" do
88
+ load_signatures(validate: validate_signatures) do |env, check, timestamp|
89
+ Steep.measure "type checking #{target_sources.size} files" do
90
+ run_type_check(env, check, timestamp, target_sources: target_sources)
91
+ end
92
+ end
93
+ end
88
94
  end
89
95
  end
90
96
 
@@ -100,7 +106,7 @@ module Steep
100
106
  end
101
107
  end
102
108
 
103
- def load_signatures
109
+ def load_signatures(validate:)
104
110
  timestamp = case status
105
111
  when TypeCheckStatus
106
112
  status.timestamp
@@ -133,16 +139,20 @@ module Steep
133
139
  factory = AST::Types::Factory.new(builder: definition_builder)
134
140
  check = Subtyping::Check.new(factory: factory)
135
141
 
136
- validator = Signature::Validator.new(checker: check)
137
- validator.validate()
138
-
139
- if validator.no_error?
140
- yield env, check, Time.now
142
+ if validate
143
+ validator = Signature::Validator.new(checker: check)
144
+ validator.validate()
145
+
146
+ if validator.no_error?
147
+ yield env, check, Time.now
148
+ else
149
+ @status = SignatureValidationErrorStatus.new(
150
+ errors: validator.each_error.to_a,
151
+ timestamp: Time.now
152
+ )
153
+ end
141
154
  else
142
- @status = SignatureValidationErrorStatus.new(
143
- errors: validator.each_error.to_a,
144
- timestamp: Time.now
145
- )
155
+ yield env, check, Time.now
146
156
  end
147
157
  end
148
158
 
@@ -160,10 +170,10 @@ module Steep
160
170
  end
161
171
  end
162
172
 
163
- def run_type_check(env, check, timestamp)
173
+ def run_type_check(env, check, timestamp, target_sources: source_files.values)
164
174
  type_check_sources = []
165
175
 
166
- source_files.each_value do |file|
176
+ target_sources.each do |file|
167
177
  if file.type_check(check, timestamp)
168
178
  type_check_sources << file
169
179
  end