@@ -20,6 +20,7 @@ import { RecommendationHandler } from '../../../codewhisperer/service/recommenda
20
20
import { isInlineCompletionEnabled } from '../../../codewhisperer/util/commonUtil'
21
21
import { ClassifierTrigger } from '../../../codewhisperer/service/classifierTrigger'
22
22
import { CodeWhispererUserGroupSettings } from '../../../codewhisperer/util/userGroupUtil'
23
+ import * as CodeWhispererConstants from '../../../codewhisperer/models/constants'
23
24
24
25
const performance = globalThis . performance ?? require ( 'perf_hooks' ) . performance
25
26
@@ -213,6 +214,62 @@ describe('keyStrokeHandler', function () {
213
214
await KeyStrokeHandler . instance . processKeyStroke ( mockEvent , mockEditor , mockClient , config )
214
215
assert . ok ( invokeSpy . called )
215
216
} )
217
+
218
+ it ( 'Should skip invoking if there is immediate right context on the same line and not a single } for the user group' , async function ( ) {
219
+ const casesForSuppressTokenFilling = [
220
+ {
221
+ rightContext : 'add' ,
222
+ shouldInvoke : false ,
223
+ } ,
224
+ {
225
+ rightContext : '}' ,
226
+ shouldInvoke : true ,
227
+ } ,
228
+ {
229
+ rightContext : '} ' ,
230
+ shouldInvoke : true ,
231
+ } ,
232
+ {
233
+ rightContext : ' add' ,
234
+ shouldInvoke : true ,
235
+ } ,
236
+ {
237
+ rightContext : ' ' ,
238
+ shouldInvoke : true ,
239
+ } ,
240
+ {
241
+ rightContext : '\naddTwo' ,
242
+ shouldInvoke : true ,
243
+ } ,
244
+ ]
245
+ casesForSuppressTokenFilling . forEach ( async ( { rightContext, shouldInvoke } ) => {
246
+ await testIfRightContextShouldInvoke (
247
+ rightContext ,
248
+ shouldInvoke ,
249
+ CodeWhispererConstants . UserGroup . RightContext
250
+ )
251
+ } )
252
+ } )
253
+
254
+ it ( 'Should not skip invoking based on right context for control group' , async function ( ) {
255
+ await testIfRightContextShouldInvoke ( 'add' , true , CodeWhispererConstants . UserGroup . Control )
256
+ } )
257
+
258
+ async function testIfRightContextShouldInvoke (
259
+ rightContext : string ,
260
+ shouldTrigger : boolean ,
261
+ userGroup : CodeWhispererConstants . UserGroup
262
+ ) {
263
+ const mockEditor = createMockTextEditor ( rightContext , 'test.js' , 'javascript' , 1 , 1 )
264
+ const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
265
+ mockEditor . document ,
266
+ new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 1 ) ) ,
267
+ '{'
268
+ )
269
+ CodeWhispererUserGroupSettings . instance . userGroup = userGroup
270
+ await KeyStrokeHandler . instance . processKeyStroke ( mockEvent , mockEditor , mockClient , config )
271
+ assert . strictEqual ( invokeSpy . called , shouldTrigger )
272
+ }
216
273
} )
217
274
218
275
describe ( 'invokeAutomatedTrigger' , function ( ) {
0 commit comments