@@ -17,16 +17,16 @@ import {
17
17
import { RefObject , useCallback , useEffect , useRef } from "react" ;
18
18
import { Theme } from "shared" ;
19
19
import {
20
- Diagnostic ,
21
20
Severity ,
22
- Workspace ,
21
+ type Workspace ,
23
22
Position as KnotPosition ,
24
23
type Range as KnotRange ,
25
24
} from "red_knot_wasm" ;
26
25
27
26
import IStandaloneCodeEditor = editor . IStandaloneCodeEditor ;
28
27
import { FileId , ReadonlyFiles } from "../Playground" ;
29
28
import { isPythonFile } from "./Files" ;
29
+ import { Diagnostic } from "./Diagnostics" ;
30
30
31
31
type Props = {
32
32
visible : boolean ;
@@ -38,7 +38,7 @@ type Props = {
38
38
workspace : Workspace ;
39
39
onChange ( content : string ) : void ;
40
40
onMount ( editor : IStandaloneCodeEditor , monaco : Monaco ) : void ;
41
- onOpenFile ( file : FileId ) : void ;
41
+ onFileOpened ( file : FileId ) : void ;
42
42
} ;
43
43
44
44
export default function Editor ( {
@@ -51,7 +51,7 @@ export default function Editor({
51
51
workspace,
52
52
onChange,
53
53
onMount,
54
- onOpenFile ,
54
+ onFileOpened ,
55
55
} : Props ) {
56
56
const disposable = useRef < {
57
57
typeDefinition : IDisposable ;
@@ -61,14 +61,14 @@ export default function Editor({
61
61
monaco : null ,
62
62
files,
63
63
workspace,
64
- onOpenFile ,
64
+ onFileOpened ,
65
65
} ) ;
66
66
67
67
playgroundState . current = {
68
68
monaco : playgroundState . current . monaco ,
69
69
files,
70
70
workspace,
71
- onOpenFile ,
71
+ onFileOpened ,
72
72
} ;
73
73
74
74
// Update the diagnostics in the editor.
@@ -79,8 +79,8 @@ export default function Editor({
79
79
return ;
80
80
}
81
81
82
- updateMarkers ( monaco , workspace , diagnostics ) ;
83
- } , [ workspace , diagnostics ] ) ;
82
+ updateMarkers ( monaco , diagnostics ) ;
83
+ } , [ diagnostics ] ) ;
84
84
85
85
const handleChange = useCallback (
86
86
( value : string | undefined ) => {
@@ -98,7 +98,7 @@ export default function Editor({
98
98
99
99
const handleMount : OnMount = useCallback (
100
100
( editor , instance ) => {
101
- updateMarkers ( instance , workspace , diagnostics ) ;
101
+ updateMarkers ( instance , diagnostics ) ;
102
102
103
103
const server = new PlaygroundServer ( playgroundState ) ;
104
104
const typeDefinitionDisposable =
@@ -116,7 +116,7 @@ export default function Editor({
116
116
onMount ( editor , instance ) ;
117
117
} ,
118
118
119
- [ onMount , workspace , diagnostics ] ,
119
+ [ onMount , diagnostics ] ,
120
120
) ;
121
121
122
122
return (
@@ -141,11 +141,7 @@ export default function Editor({
141
141
) ;
142
142
}
143
143
144
- function updateMarkers (
145
- monaco : Monaco ,
146
- workspace : Workspace ,
147
- diagnostics : Array < Diagnostic > ,
148
- ) {
144
+ function updateMarkers ( monaco : Monaco , diagnostics : Array < Diagnostic > ) {
149
145
const editor = monaco . editor ;
150
146
const model = editor ?. getModels ( ) [ 0 ] ;
151
147
@@ -170,16 +166,16 @@ function updateMarkers(
170
166
}
171
167
} ;
172
168
173
- const range = diagnostic . toRange ( workspace ) ;
169
+ const range = diagnostic . range ;
174
170
175
171
return {
176
- code : diagnostic . id ( ) ,
172
+ code : diagnostic . id ,
177
173
startLineNumber : range ?. start ?. line ?? 0 ,
178
174
startColumn : range ?. start ?. column ?? 0 ,
179
175
endLineNumber : range ?. end ?. line ?? 0 ,
180
176
endColumn : range ?. end ?. column ?? 0 ,
181
- message : diagnostic . message ( ) ,
182
- severity : mapSeverity ( diagnostic . severity ( ) ) ,
177
+ message : diagnostic . message ,
178
+ severity : mapSeverity ( diagnostic . severity ) ,
183
179
tags : [ ] ,
184
180
} ;
185
181
} ) ,
@@ -191,7 +187,7 @@ interface PlaygroundServerProps {
191
187
workspace : Workspace ;
192
188
files : ReadonlyFiles ;
193
189
194
- onOpenFile : ( file : FileId ) => void ;
190
+ onFileOpened : ( file : FileId ) => void ;
195
191
}
196
192
197
193
class PlaygroundServer
@@ -223,26 +219,29 @@ class PlaygroundServer
223
219
new KnotPosition ( position . lineNumber , position . column ) ,
224
220
) ;
225
221
226
- const locations = links . map ( ( link ) => {
227
- const targetSelection =
228
- link . selection_range == null
229
- ? undefined
230
- : knotRangeToIRange ( link . selection_range ) ;
231
-
232
- const originSelection =
233
- link . origin_selection_range == null
234
- ? undefined
235
- : knotRangeToIRange ( link . origin_selection_range ) ;
236
-
237
- return {
238
- uri : Uri . parse ( link . path ) ,
239
- range : knotRangeToIRange ( link . full_range ) ,
240
- targetSelectionRange : targetSelection ,
241
- originSelectionRange : originSelection ,
242
- } as languages . LocationLink ;
243
- } ) ;
244
-
245
- return locations ;
222
+ return (
223
+ links
224
+ . map ( ( link ) => {
225
+ const targetSelection =
226
+ link . selection_range == null
227
+ ? undefined
228
+ : knotRangeToIRange ( link . selection_range ) ;
229
+
230
+ const originSelection =
231
+ link . origin_selection_range == null
232
+ ? undefined
233
+ : knotRangeToIRange ( link . origin_selection_range ) ;
234
+
235
+ return {
236
+ uri : Uri . parse ( link . path ) ,
237
+ range : knotRangeToIRange ( link . full_range ) ,
238
+ targetSelectionRange : targetSelection ,
239
+ originSelectionRange : originSelection ,
240
+ } as languages . LocationLink ;
241
+ } )
242
+ // Filter out vendored files because they aren't open in the editor.
243
+ . filter ( ( link ) => link . uri . scheme !== "vendored" )
244
+ ) ;
246
245
}
247
246
248
247
openCodeEditor (
@@ -284,7 +283,7 @@ class PlaygroundServer
284
283
if ( files . selected !== fileId ) {
285
284
source . setModel ( model ) ;
286
285
287
- this . props . current . onOpenFile ( fileId ) ;
286
+ this . props . current . onFileOpened ( fileId ) ;
288
287
}
289
288
290
289
if ( selectionOrPosition != null ) {
0 commit comments