11import Prism from 'prismjs' ;
2- import { makePosition } from './types' ;
2+ import { Channel , makePosition , Position } from './types' ;
3+
4+ interface ConfigureRustErrorsArgs {
5+ enableFeatureGate : ( feature : string ) => void ;
6+ getChannel : ( ) => Channel ;
7+ gotoPosition : ( line : string | number , column : string | number ) => void ;
8+ selectText : ( start : Position , end : Position ) => void ;
9+ addImport : ( code : string ) => void ;
10+ reExecuteWithBacktrace : ( ) => void ;
11+ }
312
413export function configureRustErrors ( {
514 enableFeatureGate,
@@ -8,7 +17,7 @@ export function configureRustErrors({
817 selectText,
918 addImport,
1019 reExecuteWithBacktrace,
11- } ) {
20+ } : ConfigureRustErrorsArgs ) {
1221 Prism . languages . rust_errors = {
1322 'warning' : {
1423 pattern : / ^ w a r n i n g ( \[ E \d + \] ) ? : .* $ / m,
@@ -89,8 +98,10 @@ export function configureRustErrors({
8998 }
9099 env . tag = 'a' ;
91100 env . attributes . href = '#' ;
92- env . attributes [ 'data-line' ] = line ;
93- env . attributes [ 'data-col' ] = col ;
101+ if ( line && col ) {
102+ env . attributes [ 'data-line' ] = line ;
103+ env . attributes [ 'data-col' ] = col ;
104+ }
94105 }
95106 if ( env . type === 'import-suggestion' ) {
96107 env . tag = 'a' ;
@@ -142,7 +153,9 @@ export function configureRustErrors({
142153 const { line, col } = link . dataset ;
143154 link . onclick = e => {
144155 e . preventDefault ( ) ;
145- gotoPosition ( line , col ) ;
156+ if ( line && col ) {
157+ gotoPosition ( line , col ) ;
158+ }
146159 } ;
147160 }
148161 } ) ;
@@ -163,8 +176,10 @@ export function configureRustErrors({
163176 if ( link instanceof HTMLAnchorElement ) {
164177 link . onclick = e => {
165178 e . preventDefault ( ) ;
166- enableFeatureGate ( link . dataset . featureGate ) ;
167- gotoPosition ( 1 , 1 ) ;
179+ if ( link . dataset . featureGate ) {
180+ enableFeatureGate ( link . dataset . featureGate ) ;
181+ gotoPosition ( 1 , 1 ) ;
182+ }
168183 } ;
169184 }
170185 } ) ;
0 commit comments