Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 630e6ae

Browse files
authored
Merge pull request #31 from Microsoft/stream
Streaming support for #5
2 parents b400cdb + f86c1d0 commit 630e6ae

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

src/logParser/jsonLogParser.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { LspItem, MsgKind } from '@/logParser/rawLogParser'
2+
3+
const HEADER_LENGTH = 21
4+
5+
const idToRequests = {}
6+
7+
export function parseJSONLog(log: string): LspItem {
8+
const item = JSON.parse(log.slice(HEADER_LENGTH))
9+
10+
if (item.message.id && item.type.startsWith('send')) {
11+
idToRequests[item.message.id] = item
12+
}
13+
14+
return {
15+
msg: item.message.method,
16+
msgId: item.message.id,
17+
msgKind: convertMsgType(item.type) as MsgKind,
18+
msgType: item.message.method
19+
? item.message.method
20+
: idToRequests[item.message.id].message.method,
21+
msgLatency: item.type === 'receive-response'
22+
? `${item.timestamp - idToRequests[item.message.id].timestamp}ms`
23+
: null,
24+
arg: item.message,
25+
time: new Date(item.timestamp).toLocaleTimeString(),
26+
}
27+
}
28+
29+
function convertMsgType(msgType: string) {
30+
return msgType.startsWith('receive') ? msgType.replace('receive', 'recv') : msgType
31+
}

src/logParser/rawLogParser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export interface LspItem {
1111
msg: string
1212
msgKind: MsgKind
1313
msgType: string
14-
msgId: string
15-
msgLatency: string
14+
msgId?: string
15+
msgLatency?: string
1616
arg: any
1717
}
1818

src/store/store.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue'
22
import Vuex from 'vuex'
33
import { parseLSPLog, LspItem, MsgKind } from '@/logParser/rawLogParser'
4+
import { parseJSONLog } from '@/logParser/jsonLogParser';
45

56
Vue.use(Vuex)
67

@@ -36,6 +37,11 @@ export interface State {
3637
showUsage: boolean
3738
}
3839

40+
const emptyLog = {
41+
name: 'stream',
42+
items: []
43+
}
44+
3945
const sampleLogItems: LspItem[] = require('./sample.log.json')
4046
const sampleLog = {
4147
name: 'sample.log',
@@ -49,7 +55,7 @@ const sampleCSSLog = {
4955
}
5056

5157
const defaultState: State = {
52-
logs: [sampleLog, sampleCSSLog],
58+
logs: [emptyLog, sampleLog, sampleCSSLog],
5359
activeLogIndex: 0,
5460

5561
nameQuery: '',
@@ -63,7 +69,7 @@ const defaultState: State = {
6369
showUsage: false
6470
}
6571

66-
export default new Vuex.Store({
72+
const store = new Vuex.Store({
6773
state: defaultState,
6874
mutations: {
6975
updateActiveLog(state, i) {
@@ -75,6 +81,10 @@ export default new Vuex.Store({
7581
name
7682
})
7783
},
84+
appendLog(state, logItem: string) {
85+
const activeLog = state.logs[state.activeLogIndex]
86+
activeLog.items.push(parseJSONLog(logItem))
87+
},
7888
search(state, { nameQuery, paramQuery }) {
7989
state.nameQuery = nameQuery
8090
state.paramQuery = paramQuery
@@ -212,3 +222,15 @@ function itemMatchesKindFilter(item: LspItem, filter: KindFilter) {
212222
}
213223
return item.msgKind === filter
214224
}
225+
226+
(window as any).appendLog = (log) => {
227+
store.commit('appendLog', log)
228+
}
229+
230+
window.addEventListener('message', ev => {
231+
store.commit('appendLog', ev.data)
232+
const el = document.querySelector('.msg:last-child')
233+
el.scrollIntoView({ block: 'start', behavior: 'smooth' })
234+
})
235+
236+
export default store

0 commit comments

Comments
 (0)