diff --git a/src/logParser/jsonLogParser.ts b/src/logParser/jsonLogParser.ts index 91769eb..c08ffbb 100644 --- a/src/logParser/jsonLogParser.ts +++ b/src/logParser/jsonLogParser.ts @@ -2,16 +2,27 @@ import { LspItem, MsgKind } from '@/logParser/rawLogParser' const HEADER_LENGTH = 21 +const idToRequests = {} + export function parseJSONLog(log: string): LspItem { const item = JSON.parse(log.slice(HEADER_LENGTH)) + if (item.message.id && item.type.startsWith('send')) { + idToRequests[item.message.id] = item + } + return { msg: item.message.method, msgId: item.message.id, msgKind: convertMsgType(item.type) as MsgKind, - msgType: convertMsgType(item.type), + msgType: item.message.method + ? item.message.method + : idToRequests[item.message.id].message.method, + msgLatency: item.type === 'receive-response' + ? `${item.timestamp - idToRequests[item.message.id].timestamp}ms` + : null, arg: item.message, - time: item.timestamp + time: new Date(item.timestamp).toLocaleTimeString(), } } diff --git a/src/store/store.ts b/src/store/store.ts index 1270660..89e7dc2 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -227,4 +227,10 @@ function itemMatchesKindFilter(item: LspItem, filter: KindFilter) { store.commit('appendLog', log) } +window.addEventListener('message', ev => { + store.commit('appendLog', ev.data) + const el = document.querySelector('.msg:last-child') + el.scrollIntoView({ block: 'start', behavior: 'smooth' }) +}) + export default store