@@ -8,7 +8,7 @@ import * as vscode from 'vscode'
8
8
import * as sinon from 'sinon'
9
9
import {
10
10
ReferenceInlineProvider ,
11
- CodeWhispererSessionState ,
11
+ session ,
12
12
AuthUtil ,
13
13
DefaultCodeWhispererClient ,
14
14
RecommendationsList ,
@@ -55,7 +55,6 @@ describe('recommendationHandler', function () {
55
55
} )
56
56
57
57
it ( 'should assign correct recommendations given input' , async function ( ) {
58
- const session = CodeWhispererSessionState . instance . getSession ( )
59
58
assert . strictEqual ( CodeWhispererCodeCoverageTracker . instances . size , 0 )
60
59
assert . strictEqual (
61
60
CodeWhispererCodeCoverageTracker . getTracker ( mockEditor . document . languageId ) ?. serviceInvocationCount ,
@@ -75,7 +74,7 @@ describe('recommendationHandler', function () {
75
74
}
76
75
const handler = new RecommendationHandler ( )
77
76
sinon . stub ( handler , 'getServerResponse' ) . resolves ( mockServerResult )
78
- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' , false )
77
+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' , false )
79
78
const actual = session . recommendations
80
79
const expected : RecommendationsList = [ { content : "print('Hello World!')" } , { content : '' } ]
81
80
assert . deepStrictEqual ( actual , expected )
@@ -86,7 +85,6 @@ describe('recommendationHandler', function () {
86
85
} )
87
86
88
87
it ( 'should assign request id correctly' , async function ( ) {
89
- const session = CodeWhispererSessionState . instance . getSession ( )
90
88
const mockServerResult = {
91
89
recommendations : [ { content : "print('Hello World!')" } , { content : '' } ] ,
92
90
$response : {
@@ -101,7 +99,7 @@ describe('recommendationHandler', function () {
101
99
const handler = new RecommendationHandler ( )
102
100
sinon . stub ( handler , 'getServerResponse' ) . resolves ( mockServerResult )
103
101
sinon . stub ( handler , 'isCancellationRequested' ) . returns ( false )
104
- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' , false )
102
+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' , false )
105
103
assert . strictEqual ( handler . requestId , 'test_request' )
106
104
assert . strictEqual ( session . sessionId , 'test_request' )
107
105
assert . strictEqual ( session . triggerType , 'AutoTrigger' )
@@ -130,10 +128,9 @@ describe('recommendationHandler', function () {
130
128
strategy : 'empty' ,
131
129
} )
132
130
sinon . stub ( performance , 'now' ) . returns ( 0.0 )
133
- const session = CodeWhispererSessionState . instance . getSession ( )
134
131
session . startPos = new vscode . Position ( 1 , 0 )
135
132
session . startCursorOffset = 2
136
- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' )
133
+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' )
137
134
const assertTelemetry = assertTelemetryCurried ( 'codewhisperer_serviceInvocation' )
138
135
assertTelemetry ( {
139
136
codewhispererRequestId : 'test_request' ,
@@ -170,11 +167,10 @@ describe('recommendationHandler', function () {
170
167
const handler = new RecommendationHandler ( )
171
168
sinon . stub ( handler , 'getServerResponse' ) . resolves ( mockServerResult )
172
169
sinon . stub ( performance , 'now' ) . returns ( 0.0 )
173
- const session = CodeWhispererSessionState . instance . getSession ( )
174
170
session . startPos = new vscode . Position ( 1 , 0 )
175
171
session . requestIdList = [ 'test_request_empty' ]
176
172
session . startCursorOffset = 2
177
- await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , session , 'Enter' )
173
+ await handler . getRecommendations ( mockClient , mockEditor , 'AutoTrigger' , config , 'Enter' )
178
174
const assertTelemetry = assertTelemetryCurried ( 'codewhisperer_userDecision' )
179
175
assertTelemetry ( {
180
176
codewhispererRequestId : 'test_request_empty' ,
@@ -196,7 +192,6 @@ describe('recommendationHandler', function () {
196
192
sinon . restore ( )
197
193
} )
198
194
it ( 'should return true if any response is not empty' , function ( ) {
199
- const session = CodeWhispererSessionState . instance . getSession ( )
200
195
const handler = new RecommendationHandler ( )
201
196
session . recommendations = [
202
197
{
@@ -209,14 +204,12 @@ describe('recommendationHandler', function () {
209
204
} )
210
205
211
206
it ( 'should return false if response is empty' , function ( ) {
212
- const session = CodeWhispererSessionState . instance . getSession ( )
213
207
const handler = new RecommendationHandler ( )
214
208
session . recommendations = [ ]
215
209
assert . ok ( ! handler . isValidResponse ( ) )
216
210
} )
217
211
218
212
it ( 'should return false if all response has no string length' , function ( ) {
219
- const session = CodeWhispererSessionState . instance . getSession ( )
220
213
const handler = new RecommendationHandler ( )
221
214
session . recommendations = [ { content : '' } , { content : '' } ]
222
215
assert . ok ( ! handler . isValidResponse ( ) )
@@ -229,7 +222,6 @@ describe('recommendationHandler', function () {
229
222
} )
230
223
231
224
it ( 'should set the completion type to block given a multi-line suggestion' , function ( ) {
232
- const session = CodeWhispererSessionState . instance . getSession ( )
233
225
session . setCompletionType ( 0 , { content : 'test\n\n \t\r\nanother test' } )
234
226
assert . strictEqual ( session . getCompletionType ( 0 ) , 'Block' )
235
227
@@ -241,7 +233,6 @@ describe('recommendationHandler', function () {
241
233
} )
242
234
243
235
it ( 'should set the completion type to line given a single-line suggestion' , function ( ) {
244
- const session = CodeWhispererSessionState . instance . getSession ( )
245
236
session . setCompletionType ( 0 , { content : 'test' } )
246
237
assert . strictEqual ( session . getCompletionType ( 0 ) , 'Line' )
247
238
@@ -250,7 +241,6 @@ describe('recommendationHandler', function () {
250
241
} )
251
242
252
243
it ( 'should set the completion type to line given a multi-line completion but only one-lien of non-blank sequence' , function ( ) {
253
- const session = CodeWhispererSessionState . instance . getSession ( )
254
244
session . setCompletionType ( 0 , { content : 'test\n\t' } )
255
245
assert . strictEqual ( session . getCompletionType ( 0 ) , 'Line' )
256
246
@@ -267,7 +257,6 @@ describe('recommendationHandler', function () {
267
257
268
258
describe ( 'on event change' , async function ( ) {
269
259
beforeEach ( function ( ) {
270
- const session = CodeWhispererSessionState . instance . getSession ( )
271
260
const fakeReferences = [
272
261
{
273
262
message : '' ,
@@ -285,14 +274,12 @@ describe('recommendationHandler', function () {
285
274
} )
286
275
287
276
it ( 'should remove inline reference onEditorChange' , async function ( ) {
288
- const session = CodeWhispererSessionState . instance . getSession ( )
289
277
session . sessionId = 'aSessionId'
290
278
RecommendationHandler . instance . requestId = 'aRequestId'
291
279
await RecommendationHandler . instance . onEditorChange ( )
292
280
assert . strictEqual ( ReferenceInlineProvider . instance . refs . length , 0 )
293
281
} )
294
282
it ( 'should remove inline reference onFocusChange' , async function ( ) {
295
- const session = CodeWhispererSessionState . instance . getSession ( )
296
283
session . sessionId = 'aSessionId'
297
284
RecommendationHandler . instance . requestId = 'aRequestId'
298
285
await RecommendationHandler . instance . onFocusChange ( )
0 commit comments