From f86c1d04c39ea84c625421d3f380ecde9b8adfdb Mon Sep 17 00:00:00 2001 From: Pine Wu Date: Mon, 20 Aug 2018 00:46:53 -0700 Subject: [PATCH] More JSON log parsing --- src/logParser/jsonLogParser.ts | 15 +++++++++++++-- src/store/store.ts | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) 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