@@ -18,6 +18,7 @@ import { InlineCompletionService } from '../../../codewhisperer/service/inlineCo
18
18
import * as EditorContext from '../../../codewhisperer/util/editorContext'
19
19
import { RecommendationHandler } from '../../../codewhisperer/service/recommendationHandler'
20
20
import { isInlineCompletionEnabled } from '../../../codewhisperer/util/commonUtil'
21
+ import { ClassifierTrigger } from '../../../codewhisperer/service/classifierTrigger'
21
22
22
23
const performance = globalThis . performance ?? require ( 'perf_hooks' ) . performance
23
24
@@ -67,19 +68,6 @@ describe('keyStrokeHandler', function () {
67
68
assert . ok ( ! startTimerSpy . called )
68
69
} )
69
70
70
- it ( 'Should not call invokeAutomatedTrigger when changed text matches active recommendation prefix' , async function ( ) {
71
- const mockEditor = createMockTextEditor ( )
72
- const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
73
- mockEditor . document ,
74
- new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 1 ) ) ,
75
- 'd'
76
- )
77
- RecommendationHandler . instance . startPos = new vscode . Position ( 1 , 0 )
78
- RecommendationHandler . instance . recommendations = [ { content : 'def two_sum(nums, target):\n for i in nums' } ]
79
- await KeyStrokeHandler . instance . processKeyStroke ( mockEvent , mockEditor , mockClient , config )
80
- assert . ok ( ! invokeSpy . called )
81
- } )
82
-
83
71
it ( 'Should not call invokeAutomatedTrigger when changed text across multiple lines' , async function ( ) {
84
72
const mockEditor = createMockTextEditor ( )
85
73
const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
@@ -200,8 +188,8 @@ describe('keyStrokeHandler', function () {
200
188
assert . ok ( ! startTimerSpy . called )
201
189
} )
202
190
203
- it ( 'Should start idle trigger timer when inputing non-special characters' , async function ( ) {
204
- const mockEditor = createMockTextEditor ( 'function addTwo' , 'test.js ' , 'javascript ' )
191
+ it ( 'Should start idle trigger timer when inputing non-special characters for non-classifier language ' , async function ( ) {
192
+ const mockEditor = createMockTextEditor ( 'def addTwo' , 'test.rb ' , 'ruby ' )
205
193
const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
206
194
mockEditor . document ,
207
195
new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 1 ) ) ,
@@ -210,6 +198,30 @@ describe('keyStrokeHandler', function () {
210
198
await KeyStrokeHandler . instance . processKeyStroke ( mockEvent , mockEditor , mockClient , config )
211
199
assert . ok ( startTimerSpy . called )
212
200
} )
201
+
202
+ it ( 'Should not call invokeAutomatedTrigger for non-special characters for classifier language if classifier says no' , async function ( ) {
203
+ const mockEditor = createMockTextEditor ( 'function addTwo' , 'test.js' , 'javascript' )
204
+ const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
205
+ mockEditor . document ,
206
+ new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 1 ) ) ,
207
+ 'a'
208
+ )
209
+ sinon . stub ( ClassifierTrigger . instance , 'shouldTriggerFromClassifier' ) . returns ( false )
210
+ await KeyStrokeHandler . instance . processKeyStroke ( mockEvent , mockEditor , mockClient , config )
211
+ assert . ok ( ! invokeSpy . called )
212
+ } )
213
+
214
+ it ( 'Should call invokeAutomatedTrigger for non-special characters for classifier language if classifier says yes' , async function ( ) {
215
+ const mockEditor = createMockTextEditor ( 'function addTwo' , 'test.js' , 'javascript' )
216
+ const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
217
+ mockEditor . document ,
218
+ new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 1 ) ) ,
219
+ 'a'
220
+ )
221
+ sinon . stub ( ClassifierTrigger . instance , 'shouldTriggerFromClassifier' ) . returns ( true )
222
+ await KeyStrokeHandler . instance . processKeyStroke ( mockEvent , mockEditor , mockClient , config )
223
+ assert . ok ( invokeSpy . called )
224
+ } )
213
225
} )
214
226
215
227
describe ( 'invokeAutomatedTrigger' , function ( ) {
@@ -228,8 +240,13 @@ describe('keyStrokeHandler', function () {
228
240
it ( 'should call getPaginatedRecommendation when inline completion is enabled' , async function ( ) {
229
241
const mockEditor = createMockTextEditor ( )
230
242
const keyStrokeHandler = new KeyStrokeHandler ( )
243
+ const mockEvent : vscode . TextDocumentChangeEvent = createTextDocumentChangeEvent (
244
+ mockEditor . document ,
245
+ new vscode . Range ( new vscode . Position ( 0 , 0 ) , new vscode . Position ( 0 , 1 ) ) ,
246
+ ' '
247
+ )
231
248
const getRecommendationsStub = sinon . stub ( InlineCompletionService . instance , 'getPaginatedRecommendation' )
232
- await keyStrokeHandler . invokeAutomatedTrigger ( 'Enter' , mockEditor , mockClient , config )
249
+ await keyStrokeHandler . invokeAutomatedTrigger ( 'Enter' , mockEditor , mockClient , config , mockEvent )
233
250
assert . strictEqual ( getRecommendationsStub . called , isInlineCompletionEnabled ( ) )
234
251
} )
235
252
} )
0 commit comments