@@ -129,7 +129,7 @@ describe('CursorUpdateManager', () => {
129129 assert . ok ( stopSpy . called )
130130 } )
131131
132- it ( 'should send cursor update requests at intervals' , async ( ) => {
132+ it ( 'should send cursor update requests at intervals' , ( ) => {
133133 // Setup test data
134134 const position = new vscode . Position ( 1 , 2 )
135135 const uri = 'file:///test.ts'
@@ -150,24 +150,26 @@ describe('CursorUpdateManager', () => {
150150 }
151151 sinon . stub ( cursorUpdateManager as any , 'createCancellationTokenSource' ) . returns ( mockCancellationTokenSource )
152152
153- // Mock the provideInlineCompletionItems method
153+ // Mock the provideInlineCompletionItems method with a proper stub
154154 const provideStub = sinon . stub ( ) . resolves ( [ ] )
155155 ; ( cursorUpdateManager as any ) . inlineCompletionProvider = {
156156 provideInlineCompletionItems : provideStub ,
157157 }
158158
159- // Start the manager
160- await cursorUpdateManager . start ( )
159+ // Start the manager - we're not awaiting this since we're just setting up the test
160+ cursorUpdateManager . start ( )
161161
162162 // Reset the sendRequestStub to clear the call from start()
163163 sendRequestStub . resetHistory ( )
164164
165+ // Make sure lastSentPosition is different from lastPosition to trigger an update
166+ ; ( cursorUpdateManager as any ) . lastSentPosition = new vscode . Position ( 0 , 0 )
167+
165168 // Manually call the interval function
166- await ( cursorUpdateManager as any ) . sendCursorUpdate ( )
169+ ; ( cursorUpdateManager as any ) . sendCursorUpdate ( )
167170
168171 // Verify the provider was called
169- assert . ok ( provideStub . called , 'provideInlineCompletionItems should have been called' )
170- assert . strictEqual ( provideStub . callCount , 1 )
172+ assert . strictEqual ( provideStub . called , true , 'provideInlineCompletionItems should have been called' )
171173 } )
172174
173175 it ( 'should not send cursor update if a regular request was made recently' , async ( ) => {
@@ -203,4 +205,63 @@ describe('CursorUpdateManager', () => {
203205 // Verify no request was sent
204206 assert . strictEqual ( sendRequestStub . called , false )
205207 } )
208+
209+ it . only ( 'should not send cursor update if position has not changed since last update' , async ( ) => {
210+ // Setup test data
211+ const position = new vscode . Position ( 1 , 2 )
212+ const uri = 'file:///test.ts'
213+ cursorUpdateManager . updatePosition ( position , uri )
214+
215+ // Mock the active editor
216+ const mockEditor = {
217+ document : {
218+ uri : { toString : ( ) => uri } ,
219+ } ,
220+ }
221+ sinon . stub ( vscode . window , 'activeTextEditor' ) . get ( ( ) => mockEditor as any )
222+
223+ // Create a mock cancellation token source
224+ const mockCancellationTokenSource = {
225+ token : { } as vscode . CancellationToken ,
226+ dispose : sinon . stub ( ) ,
227+ }
228+ sinon . stub ( cursorUpdateManager as any , 'createCancellationTokenSource' ) . returns ( mockCancellationTokenSource )
229+
230+ // Mock the provideInlineCompletionItems method
231+ const provideStub = sinon . stub ( ) . resolves ( [ ] )
232+ ; ( cursorUpdateManager as any ) . inlineCompletionProvider = {
233+ provideInlineCompletionItems : provideStub ,
234+ }
235+
236+ // Start the manager
237+ await cursorUpdateManager . start ( )
238+
239+ // Set lastSentPosition to undefined to ensure first update is sent
240+ ; ( cursorUpdateManager as any ) . lastSentPosition = undefined
241+
242+ // First call to sendCursorUpdate - should send update
243+ await ( cursorUpdateManager as any ) . sendCursorUpdate ( )
244+
245+ // Verify the provider was called once
246+ assert . strictEqual ( provideStub . callCount , 1 , 'First update should be sent' )
247+
248+ // Reset the stub to clear the call history
249+ provideStub . resetHistory ( )
250+
251+ // Second call to sendCursorUpdate without changing position - should NOT send update
252+ await ( cursorUpdateManager as any ) . sendCursorUpdate ( )
253+
254+ // Verify the provider was NOT called again
255+ assert . strictEqual ( provideStub . callCount , 0 , 'No update should be sent when position has not changed' )
256+
257+ // Now change the position
258+ const newPosition = new vscode . Position ( 1 , 3 )
259+ cursorUpdateManager . updatePosition ( newPosition , uri )
260+
261+ // Third call to sendCursorUpdate with changed position - should send update
262+ await ( cursorUpdateManager as any ) . sendCursorUpdate ( )
263+
264+ // Verify the provider was called again
265+ assert . strictEqual ( provideStub . callCount , 1 , 'Update should be sent when position has changed' )
266+ } )
206267} )
0 commit comments