1
1
import 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
+ }
3
12
4
13
export function configureRustErrors ( {
5
14
enableFeatureGate,
@@ -8,7 +17,7 @@ export function configureRustErrors({
8
17
selectText,
9
18
addImport,
10
19
reExecuteWithBacktrace,
11
- } ) {
20
+ } : ConfigureRustErrorsArgs ) {
12
21
Prism . languages . rust_errors = {
13
22
'warning' : {
14
23
pattern : / ^ w a r n i n g ( \[ E \d + \] ) ? : .* $ / m,
@@ -89,8 +98,10 @@ export function configureRustErrors({
89
98
}
90
99
env . tag = 'a' ;
91
100
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
+ }
94
105
}
95
106
if ( env . type === 'import-suggestion' ) {
96
107
env . tag = 'a' ;
@@ -142,7 +153,9 @@ export function configureRustErrors({
142
153
const { line, col } = link . dataset ;
143
154
link . onclick = e => {
144
155
e . preventDefault ( ) ;
145
- gotoPosition ( line , col ) ;
156
+ if ( line && col ) {
157
+ gotoPosition ( line , col ) ;
158
+ }
146
159
} ;
147
160
}
148
161
} ) ;
@@ -163,8 +176,10 @@ export function configureRustErrors({
163
176
if ( link instanceof HTMLAnchorElement ) {
164
177
link . onclick = e => {
165
178
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
+ }
168
183
} ;
169
184
}
170
185
} ) ;
0 commit comments