1
+ <#
2
+ . SYNOPSIS
3
+ Gets LSP notification messages sent from either server to the client or vice-versa.
4
+ . DESCRIPTION
5
+ Gets LSP notification messages sent from either server to the client or vice-versa.
6
+ . EXAMPLE
7
+ C:\> Get-PsesRpcNotificationMessage $log
8
+ Gets all LSP notification messages in the specified log.
9
+ . EXAMPLE
10
+ C:\> Get-PsesRpcNotificationMessage $log -MessageName '$/cancelRequest'
11
+ Gets all LSP $/cancelRequest notification messages in the specified log.
12
+ . EXAMPLE
13
+ C:\> Get-PsesRpcNotificationMessage $log -Pattern powershell/.*
14
+ Gets all LSP powershell notification messages in the specified log.
15
+ . INPUTS
16
+ System.String or PsesLogEntry
17
+ . OUTPUTS
18
+ PsesLogEntry
19
+ #>
1
20
function Get-PsesRpcNotificationMessage {
2
21
[CmdletBinding (DefaultParameterSetName = " PsesLogEntry" )]
3
22
param (
@@ -14,6 +33,27 @@ function Get-PsesRpcNotificationMessage {
14
33
[psobject []]
15
34
$LogEntry ,
16
35
36
+ # Specifies a specific LSP notification.
37
+ [Parameter (Position = 1 )]
38
+ [ValidateSet (
39
+ " $/cancelRequest" ,
40
+ " initialized" ,
41
+ " powerShell/executionStatusChanged" ,
42
+ " textDocument/didChange" ,
43
+ " textDocument/didClose" ,
44
+ " textDocument/didOpen" ,
45
+ " textDocument/didSave" ,
46
+ " textDocument/publishDiagnostics" ,
47
+ " workspace/didChangeConfiguration" )]
48
+ [string ]
49
+ $MessageName ,
50
+
51
+ # Specifies a regular expression pattern that filters the output based on the message name
52
+ # e.g. 'cancelRequest'
53
+ [Parameter ()]
54
+ [string ]
55
+ $Pattern ,
56
+
17
57
# Specifies a filter for either client or server sourced notifications. By default both are output.
18
58
[Parameter ()]
19
59
[ValidateSet (' Client' , ' Server' )]
@@ -33,15 +73,38 @@ function Get-PsesRpcNotificationMessage {
33
73
}
34
74
35
75
foreach ($entry in $logEntries ) {
36
- if ($entry.LogMessageType -eq ' Notification' ) {
37
- if (! $Source -or ($entry.Message.Source -eq $Source )) {
38
- $entry
39
- }
76
+ if ($entry.LogMessageType -ne ' Notification' ) { continue }
77
+
78
+ if ((! $MessageName -or ($entry.Message.Name -eq $MessageName )) -and
79
+ (! $Pattern -or ($entry.Message.Name -match $Pattern )) -and
80
+ (! $Source -or ($entry.Message.Source -eq $Source ))) {
81
+
82
+ $entry
40
83
}
41
84
}
42
85
}
43
86
}
44
87
88
+ <#
89
+ . SYNOPSIS
90
+ Outputs the response time for message LSP message.
91
+ . DESCRIPTION
92
+ Outputs the response time for message LSP message. Use the MessageNamePattern to
93
+ limit the response time output to a specific message (or pattern of messages).
94
+ . EXAMPLE
95
+ C:\> Get-PsesRpcMessageResponseTime $log
96
+ Gets the response time of all LSP messages.
97
+ . EXAMPLE
98
+ C:\> Get-PsesRpcMessageResponseTime $log -MessageName textDocument/foldingRange
99
+ Gets the response time of all foldingRange LSP messages.
100
+ . EXAMPLE
101
+ C:\> Get-PsesRpcMessageResponseTime $log -Pattern 'textDocument/.*Formatting'
102
+ Gets the response time of all formatting LSP messages.
103
+ . INPUTS
104
+ System.String or PsesLogEntry
105
+ . OUTPUTS
106
+ PsesLogEntryElapsed
107
+ #>
45
108
function Get-PsesRpcMessageResponseTime {
46
109
[CmdletBinding (DefaultParameterSetName = " PsesLogEntry" )]
47
110
param (
@@ -56,7 +119,26 @@ function Get-PsesRpcMessageResponseTime {
56
119
[Parameter (Mandatory = $true , Position = 0 , ParameterSetName = " PsesLogEntry" , ValueFromPipeline = $true )]
57
120
[ValidateNotNull ()]
58
121
[psobject []]
59
- $LogEntry
122
+ $LogEntry ,
123
+
124
+ # Specifies a specific LSP message for which to get response times.
125
+ [Parameter (Position = 1 )]
126
+ [ValidateSet (
127
+ " textDocument/codeAction" ,
128
+ " textDocument/codeLens" ,
129
+ " textDocument/documentSymbol" ,
130
+ " textDocument/foldingRange" ,
131
+ " textDocument/formatting" ,
132
+ " textDocument/hover" ,
133
+ " textDocument/rangeFormatting" )]
134
+ [string ]
135
+ $MessageName ,
136
+
137
+ # Specifies a regular expression pattern that filters the output based on the message name
138
+ # e.g. 'textDocument/.*Formatting'
139
+ [Parameter ()]
140
+ [string ]
141
+ $Pattern
60
142
)
61
143
62
144
begin {
@@ -74,18 +156,29 @@ function Get-PsesRpcMessageResponseTime {
74
156
end {
75
157
# Populate $requests hashtable with request timestamps
76
158
$requests = @ {}
77
- $logEntries |
78
- Where-Object LogMessageType -match Request |
79
- Foreach-Object { $requests [$_.Message.Id ] = $_.Timestamp }
80
-
81
- $res = $logEntries |
82
- Where-Object LogMessageType -match Response |
83
- Foreach-Object {
84
- $elapsedMilliseconds = [int ]($_.Timestamp - $requests [$_.Message.Id ]).TotalMilliseconds
85
- [PsesLogEntryElapsed ]::new($_ , $elapsedMilliseconds )
86
- }
87
159
88
- $res
160
+ foreach ($entry in $logEntries ) {
161
+ if (($entry.LogMessageType -ne ' Request' ) -and ($entry.LogMessageType -ne ' Response' )) { continue }
162
+
163
+ if ((! $MessageName -or ($entry.Message.Name -eq $MessageName )) -and
164
+ (! $Pattern -or ($entry.Message.Name -match $Pattern ))) {
165
+
166
+ $key = " $ ( $entry.Message.Name ) -$ ( $entry.Message.Id ) "
167
+ if ($entry.LogMessageType -eq ' Request' ) {
168
+ $requests [$key ] = $entry
169
+ }
170
+ else {
171
+ $request = $requests [$key ]
172
+ if (! $request ) {
173
+ Write-Warning " No corresponding request for response: $ ( $entry.Message ) "
174
+ continue
175
+ }
176
+
177
+ $elapsedMilliseconds = [int ]($entry.Timestamp - $request.Timestamp ).TotalMilliseconds
178
+ [PsesLogEntryElapsed ]::new($entry , $elapsedMilliseconds )
179
+ }
180
+ }
181
+ }
89
182
}
90
183
}
91
184
0 commit comments