@@ -51,16 +51,21 @@ def minitest_plugin_init(_options)
5151
5252 #: (singleton(Minitest::Test) test_class, String method_name) -> void
5353 def prerecord ( test_class , method_name )
54- uri = uri_from_test_class ( test_class , method_name )
55- return unless uri
54+ file_path , line = test_class . instance_method ( method_name ) . source_location
55+ return unless file_path
56+ return if file_path . start_with? ( "(eval at " )
5657
57- LspReporter . instance . start_test ( id : "#{ test_class . name } ##{ method_name } " , uri : uri )
58+ uri = URI ::Generic . from_path ( path : File . expand_path ( file_path ) )
59+ LspReporter . instance . start_test ( id : "#{ test_class . name } ##{ method_name } " , uri : uri , line : ( line || 1 ) - 1 )
5860 end
5961
6062 #: (Minitest::Result result) -> void
6163 def record ( result )
6264 id = "#{ result . klass } ##{ result . name } "
63- uri = uri_from_result ( result )
65+ file_path , _line = result . source_location
66+ return unless file_path
67+
68+ uri = URI ::Generic . from_path ( path : File . expand_path ( file_path ) )
6469
6570 if result . error?
6671 message = result . failures . first . message
@@ -79,26 +84,6 @@ def record(result)
7984 def report
8085 LspReporter . instance . shutdown
8186 end
82-
83- private
84-
85- #: (Minitest::Result result) -> URI::Generic
86- def uri_from_result ( result )
87- file = result . source_location [ 0 ]
88- absolute_path = File . expand_path ( file , Dir . pwd )
89- URI ::Generic . from_path ( path : absolute_path )
90- end
91-
92- #: (singleton(Minitest::Test) test_class, String method_name) -> URI::Generic?
93- def uri_from_test_class ( test_class , method_name )
94- file , _line = test_class . instance_method ( method_name ) . source_location
95- return unless file
96-
97- return if file . start_with? ( "(eval at " ) # test is dynamically defined
98-
99- absolute_path = File . expand_path ( file , Dir . pwd )
100- URI ::Generic . from_path ( path : absolute_path )
101- end
10287 end
10388end
10489
0 commit comments