UNPKG

802 BPlain TextView Raw
1import type { ReactotronCore, Plugin } from "reactotron-core-client"
2
3export interface OpenInEditorOptions {
4 url?: string
5}
6
7const DEFAULTS: OpenInEditorOptions = {
8 url: "http://localhost:8081",
9}
10
11const openInEditor =
12 (pluginConfig: OpenInEditorOptions = {}) =>
13 () => {
14 const options = Object.assign({}, DEFAULTS, pluginConfig)
15
16 return {
17 onCommand: (command) => {
18 if (command.type !== "editor.open") return
19 const { payload } = command
20 const { file, lineNumber } = payload
21 const url = `${options.url}/open-stack-frame`
22 const body = { file, lineNumber: lineNumber || 1 }
23 const method = "POST"
24
25 fetch(url, { method, body: JSON.stringify(body) })
26 },
27 } satisfies Plugin<ReactotronCore>
28 }
29export default openInEditor