@@ -184,8 +184,8 @@ defmodule IEx.Introspection do
184184 """
185185 def source ( module ) when is_atom ( module ) do
186186 case source_location ( module ) do
187- { :ok , { file , _line } } ->
188- IO . puts ( File . read! ( file ) )
187+ { :ok , { file , line } } ->
188+ print_source ( file , line )
189189
190190 { :error , reason } ->
191191 puts_error ( "Could not show source for #{ inspect ( module ) } , #{ reason } " )
@@ -196,8 +196,8 @@ defmodule IEx.Introspection do
196196
197197 def source ( { module , function } ) when is_atom ( module ) and is_atom ( function ) do
198198 case source_location ( { module , function } ) do
199- { :ok , { file , _line } } ->
200- IO . puts ( File . read! ( file ) )
199+ { :ok , { file , line } } ->
200+ print_source ( file , line )
201201
202202 { :error , reason } ->
203203 puts_error ( "Could not show source for #{ inspect ( module ) } .#{ function } , #{ reason } " )
@@ -209,8 +209,8 @@ defmodule IEx.Introspection do
209209 def source ( { module , function , arity } )
210210 when is_atom ( module ) and is_atom ( function ) and is_integer ( arity ) do
211211 case source_location ( { module , function , arity } ) do
212- { :ok , { file , _line } } ->
213- IO . puts ( File . read! ( file ) )
212+ { :ok , { file , line } } ->
213+ print_source ( file , line )
214214
215215 { :error , reason } ->
216216 puts_error ( "Could not show source for #{ inspect ( module ) } .#{ function } /#{ arity } , #{ reason } " )
@@ -224,6 +224,10 @@ defmodule IEx.Introspection do
224224 dont_display_result ( )
225225 end
226226
227+ defp print_source ( file , line ) do
228+ IO . puts ( Path . relative_to_cwd ( file ) <> ":" <> Integer . to_string ( line ) )
229+ end
230+
227231 @ doc """
228232 Returns the source location for the given module, {module, function},
229233 or {module, function, arity}.
0 commit comments