@@ -48,6 +48,10 @@ export function configureRustErrors({
4848 'backtrace-enable' : / R u n w i t h ` R U S T _ B A C K T R A C E = 1 ` e n v i r o n m e n t v a r i a b l e t o d i s p l a y a b a c k t r a c e / i,
4949 } ;
5050
51+ Prism . languages . rust_mir = { // eslint-disable-line @typescript-eslint/camelcase
52+ 'mir-source' : / s r c \/ .* .r s : \d + : \d + : \d + : \d + / ,
53+ }
54+
5155 Prism . hooks . add ( 'wrap' , env => {
5256 if ( env . type === 'error-explanation' ) {
5357 const errorMatch = / E \d + / . exec ( env . content ) ;
@@ -104,6 +108,16 @@ export function configureRustErrors({
104108 env . attributes [ 'data-line' ] = line ;
105109 env . attributes [ 'data-col' ] = '1' ;
106110 }
111+ if ( env . type === 'mir-source' ) {
112+ const lineMatch = / ( \d + ) : ( \d + ) : ( \d + ) : ( \d + ) / . exec ( env . content ) ;
113+ const [ _ , startLine , startCol , endLine , endCol ] = lineMatch ;
114+ env . tag = 'a' ;
115+ env . attributes . href = '#' ;
116+ env . attributes [ 'data-start-line' ] = startLine ;
117+ env . attributes [ 'data-start-col' ] = startCol ;
118+ env . attributes [ 'data-end-line' ] = endLine ;
119+ env . attributes [ 'data-end-col' ] = endCol ;
120+ }
107121 } ) ;
108122
109123 Prism . hooks . add ( 'after-highlight' , env => {
@@ -141,5 +155,14 @@ export function configureRustErrors({
141155 reExecuteWithBacktrace ( ) ;
142156 } ;
143157 } ) ;
158+
159+ const mirSourceLinks = env . element . querySelectorAll ( '.mir-source' ) ;
160+ Array . from ( mirSourceLinks ) . forEach ( ( link : HTMLAnchorElement ) => {
161+ const { startLine, startCol } = link . dataset ;
162+ link . onclick = e => {
163+ e . preventDefault ( ) ;
164+ gotoPosition ( startLine , startCol ) ;
165+ } ;
166+ } ) ;
144167 } ) ;
145168}
0 commit comments