@@ -22,6 +22,9 @@ func SpawnInspector(platform platforms.Platform, addr string) context.CancelFunc
2222 mux .HandleFunc ("/static/" , func (w http.ResponseWriter , r * http.Request ) {
2323 handleStatic (w , r )
2424 })
25+ mux .HandleFunc ("/isolate/name/" , func (w http.ResponseWriter , r * http.Request ) {
26+ handleInspectPageByName (tmpl , platform , platformName , version , w , r )
27+ })
2528 mux .HandleFunc ("/isolate/" , func (w http.ResponseWriter , r * http.Request ) {
2629 handleInspectPage (tmpl , platform , platformName , version , w , r )
2730 })
@@ -77,6 +80,7 @@ func loadTemplates() *template.Template {
7780 "hash" : hash ,
7881 "fmtLine" : fmtLine ,
7982 "formatAwait" : formatAwait ,
83+ "isSpawn" : isSpawn ,
8084 }).ParseFS (content , "templates/*.html" ),
8185 )
8286}
@@ -313,6 +317,83 @@ func handleInspectPage(
313317 writeHTML (tmpl , w , "inspect" , data )
314318}
315319
320+ func handleInspectPageByName (
321+ tmpl * template.Template ,
322+ platform platforms.Platform ,
323+ platformName string ,
324+ version string ,
325+ w http.ResponseWriter ,
326+ r * http.Request ,
327+ ) {
328+ name := strings .TrimPrefix (r .URL .Path , "/isolate/name/" )
329+
330+ if name == "" {
331+ writeHTMLError (
332+ tmpl ,
333+ w ,
334+ platformName ,
335+ version ,
336+ http .StatusBadRequest ,
337+ "invalid isolate name" ,
338+ )
339+ return
340+ }
341+
342+ isolate , err := platform .InspectorGetByName (name )
343+ if err != nil {
344+ status := http .StatusInternalServerError
345+
346+ var notExistErr * platforms.PlatformIsolateDoesNotExistError
347+ if errors .As (err , & notExistErr ) {
348+ status = http .StatusNotFound
349+ }
350+
351+ writeHTMLError (tmpl , w , platformName , version , status , err .Error ())
352+ return
353+ }
354+
355+ traces , err := platform .InspectorTraces (isolate .ID )
356+ if err != nil {
357+ writeHTMLError (
358+ tmpl ,
359+ w ,
360+ platformName ,
361+ version ,
362+ http .StatusInternalServerError ,
363+ err .Error (),
364+ )
365+ return
366+ }
367+
368+ dark := dark (r )
369+ hasSource := isolate .Source != ""
370+
371+ var sourceHTML template.HTML
372+ if hasSource {
373+ sourceHTML = syntaxHighlightCodeHTML (
374+ isolate .Source ,
375+ isolate .Lang ,
376+ isolate .Line ,
377+ dark ,
378+ )
379+ }
380+
381+ data := inspectPageData {
382+ navData : navData {
383+ Title : "Inspect #" + strconv .FormatUint (uint64 (isolate .ID ), 10 ),
384+ Version : version ,
385+ Platform : platformName ,
386+ },
387+ Isolate : isolate ,
388+ Variables : formatContext (isolate .Context ),
389+ Traces : formatTraces (traces , isolate .Lang , dark ),
390+ SourceHTML : sourceHTML ,
391+ HasSource : hasSource ,
392+ }
393+
394+ writeHTML (tmpl , w , "inspect" , data )
395+ }
396+
316397func handleVariablesFragment (
317398 tmpl * template.Template ,
318399 platform platforms.Platform ,
0 commit comments