Skip to content

Commit

Permalink
Log messages received by debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav committed Dec 17, 2024
1 parent 084b0df commit 5931162
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 43 deletions.
8 changes: 8 additions & 0 deletions .changeset/modern-chairs-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@solid-devtools/extension": patch
"@solid-devtools/debugger": patch
"@solid-devtools/shared": patch
"solid-devtools": patch
---

Log messages recieved.
1 change: 1 addition & 0 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function get_common_esbuild_options(is_dev: boolean, dist_dirname: string
treeShaking: !is_dev,
logLevel: is_dev ? 'debug' : 'warning',
color: true,
dropLabels: [is_dev ? 'PROD' : 'DEV'],
}
}

Expand Down
74 changes: 39 additions & 35 deletions packages/debugger/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {createEventBus, createGlobalEmitter, type GlobalEmitter} from '@solid-primitives/event-bus'
import {createStaticStore} from '@solid-primitives/static-store'
import {defer} from '@solid-primitives/utils'
import {batch, createComputed, createEffect, createMemo, createSignal} from 'solid-js'
import * as s from 'solid-js'
import {log_message} from '@solid-devtools/shared/utils'
import {createDependencyGraph, type DGraphUpdate} from '../dependency/index.ts'
import {createInspector, type InspectorUpdate, type ToggleInspectedValueData} from '../inspector/index.ts'
import {createLocator} from '../locator/index.ts'
Expand Down Expand Up @@ -69,14 +70,14 @@ const [modules, toggleModules] = createStaticStore({
})

// The debugger can be enabled by devtools or by the locator
const debuggerEnabled = createMemo(() => modules.debugger || modules.locatorKeyPressSignal())
const dgraphEnabled = createMemo(() => modules.dgraph && debuggerEnabled())
const debuggerEnabled = s.createMemo(() => modules.debugger || modules.locatorKeyPressSignal())
const dgraphEnabled = s.createMemo(() => modules.dgraph && debuggerEnabled())
// locator is enabled if debugger is enabled, and user pressed the key to activate it, or the plugin activated it
const locatorEnabled = createMemo(
const locatorEnabled = s.createMemo(
() => (modules.locatorKeyPressSignal() || modules.locator) && debuggerEnabled(),
)

createEffect(
s.createEffect(
defer(debuggerEnabled, enabled => {
hub.output.emit('DebuggerEnabled', enabled)
}),
Expand All @@ -90,7 +91,7 @@ let currentView: DevtoolsMainView = DEFAULT_MAIN_VIEW
const viewChange = createEventBus<DevtoolsMainView>()

function setView(view: DevtoolsMainView) {
batch(() => {
s.batch(() => {
// setStructureEnabled(view === DevtoolsMainView.Structure)
// setDgraphEnabled(view === DevtoolsMainView.Dgraph)
viewChange.emit((currentView = view))
Expand Down Expand Up @@ -125,12 +126,12 @@ const INITIAL_INSPECTED_STATE = {
treeWalkerOwnerId: null,
} as const satisfies Debugger.OutputChannels['InspectedState']

const [inspectedState, setInspectedState] = createSignal<
const [inspectedState, setInspectedState] = s.createSignal<
Debugger.OutputChannels['InspectedState']
>(INITIAL_INSPECTED_STATE, {equals: false})
const inspectedOwnerId = createMemo(() => inspectedState().ownerId)
const inspectedOwnerId = s.createMemo(() => inspectedState().ownerId)

createEffect(() => hub.output.emit('InspectedState', inspectedState()))
s.createEffect(() => hub.output.emit('InspectedState', inspectedState()))

function getTreeWalkerOwnerId(ownerId: NodeID | null): NodeID | null {
const owner = ownerId && getObjectById(ownerId, ObjectType.Owner)
Expand Down Expand Up @@ -161,7 +162,7 @@ function setInspectedNode(data: Debugger.InputChannels['InspectNode']): void {
})
}

createComputed(
s.createComputed(
defer(debuggerEnabled, enabled => {
if (!enabled) resetInspectedNode()
}),
Expand Down Expand Up @@ -225,36 +226,39 @@ function openInspectedNodeLocation() {
}

// send the state of the client locator mode
createEffect(
s.createEffect(
defer(modules.locatorKeyPressSignal, state => hub.output.emit('LocatorModeChange', state)),
)

hub.input.listen(e => {

DEV: {log_message('Debugger', 'Client', e)}

switch (e.name) {
case 'ResetState': {
// reset all the internal state
batch(() => {
resetInspectedNode()
currentView = DEFAULT_MAIN_VIEW
structure.resetTreeWalkerMode()
locator.setDevtoolsHighlightTarget(null)
})
break
}
case 'HighlightElementChange':
return locator.setDevtoolsHighlightTarget(e.details)
case 'InspectNode':
return setInspectedNode(e.details)
case 'InspectValue':
return inspector.toggleValueNode(e.details)
case 'OpenLocation':
return openInspectedNodeLocation()
case 'TreeViewModeChange':
return structure.setTreeWalkerMode(e.details)
case 'ViewChange':
return setView(e.details)
case 'ToggleModule':
return toggleModule(e.details)
case 'ResetState': {
// reset all the internal state
s.batch(() => {
resetInspectedNode()
currentView = DEFAULT_MAIN_VIEW
structure.resetTreeWalkerMode()
locator.setDevtoolsHighlightTarget(null)
})
break
}
case 'HighlightElementChange':
return locator.setDevtoolsHighlightTarget(e.details)
case 'InspectNode':
return setInspectedNode(e.details)
case 'InspectValue':
return inspector.toggleValueNode(e.details)
case 'OpenLocation':
return openInspectedNodeLocation()
case 'TreeViewModeChange':
return structure.setTreeWalkerMode(e.details)
case 'ViewChange':
return setView(e.details)
case 'ToggleModule':
return toggleModule(e.details)
}
})

Expand Down
5 changes: 4 additions & 1 deletion packages/extension/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ let last_disconnected_tab_data: TabData | undefined
let last_disconnected_tab_id: number | undefined

chrome.runtime.onConnect.addListener(async port => {

switch (port.name) {
case bridge.ConnectionName.Content: {
const tab_id = port.sender?.tab?.id
Expand Down Expand Up @@ -241,7 +242,9 @@ chrome.runtime.onConnect.addListener(async port => {
// "Versions" means the devtools client is present
data.onVersions(v => devtools_messanger.postPortMessage('Versions', v))

port.onDisconnect.addListener(() => content_messanger.post('DevtoolsClosed'))
port.onDisconnect.addListener(() => {
content_messanger.post('DevtoolsClosed')
})

break
}
Expand Down
10 changes: 3 additions & 7 deletions packages/extension/shared/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ File for utilities, constants and types related to the communication between the
*/

import {log} from '@solid-devtools/shared/utils'
import {log, log_message} from '@solid-devtools/shared/utils'

export const DEVTOOLS_ID_PREFIX = '[solid-devtools]_'

Expand Down Expand Up @@ -75,9 +75,7 @@ export function createPortMessanger<

if (typeof name !== 'string') return

if (LOG_MESSAGES) {
log(`${place_name_here} <- ${place_name_conn} - ${name}:`, details)
}
if (LOG_MESSAGES) {log_message(place_name_here, place_name_conn, e)}

let arr = listeners[name]
if (arr) {
Expand Down Expand Up @@ -183,9 +181,7 @@ export function makeMessageListener

if (typeof name !== 'string') return

if (LOG_MESSAGES) {
log(`${place_name} <- Window - ${name}:`, details)
}
if (LOG_MESSAGES) {log_message(place_name, 'Window', e.data)}

let arr = window_listeners[name]
if (arr) {
Expand Down
1 change: 1 addition & 0 deletions packages/main/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async function main() {
},
external: external,
define: {
...common.define,
'process.env.CLIENT_VERSION': JSON.stringify(pkg.version),
'process.env.SOLID_VERSION': JSON.stringify(solid_pkg.version),
'process.env.EXPECTED_SOLID_VERSION': JSON.stringify(pkg.peerDependencies['solid-js'].match(/\d+.\d+.\d+/)![0]),
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export function error(...args: any[]): undefined {
return
}

export function log_message(to: string, from: string, e: {name: string, details: any}) {
// eslint-disable-next-line no-console
console.log(...getLogLabel(), `${to.padEnd(20, ' ')} <- ${from.padEnd(14, ' ')} - ${e.name.padEnd(20, ' ')}:`, e.details)
}

export function formatTime(d: Date = new Date()): string {
return (
('0' + d.getHours()).slice(-2) +
Expand Down

0 comments on commit 5931162

Please sign in to comment.