@@ -23,7 +23,7 @@ import { EditSources, TextModelEditSource } from '../../../../common/textModelEd
2323import { hasProvider , rawRename } from '../../../rename/browser/rename.js' ;
2424import { renameSymbolCommandId } from '../controller/commandIds.js' ;
2525import { InlineSuggestionItem } from './inlineSuggestionItem.js' ;
26- import { IInlineSuggestDataActionEdit } from './provideInlineCompletions.js' ;
26+ import { IInlineSuggestDataActionEdit , InlineSuggestAlternativeAction } from './provideInlineCompletions.js' ;
2727
2828enum RenameKind {
2929 no = 'no' ,
@@ -227,7 +227,7 @@ class RenameSymbolRunnable {
227227 private readonly _promise : Promise < WorkspaceEdit & Rejection > ;
228228 private _result : WorkspaceEdit & Rejection | undefined = undefined ;
229229
230- constructor ( languageFeaturesService : ILanguageFeaturesService , textModel : ITextModel , position : Position , newName : string , source : TextModelEditSource ) {
230+ constructor ( languageFeaturesService : ILanguageFeaturesService , textModel : ITextModel , position : Position , newName : string ) {
231231 this . _cancellationTokenSource = new CancellationTokenSource ( ) ;
232232 this . _promise = rawRename ( languageFeaturesService . renameProvider , textModel , position , newName , this . _cancellationTokenSource . token ) ;
233233 }
@@ -282,7 +282,7 @@ export class RenameSymbolProcessor extends Disposable {
282282 if ( self . _renameRunnable . id !== id ) {
283283 self . _renameRunnable . runnable . cancel ( ) ;
284284 self . _renameRunnable = undefined ;
285- const runnable = new RenameSymbolRunnable ( self . _languageFeaturesService , textModel , position , newName , source ) ;
285+ const runnable = new RenameSymbolRunnable ( self . _languageFeaturesService , textModel , position , newName ) ;
286286 workspaceEdit = await runnable . getWorkspaceEdit ( ) ;
287287 } else {
288288 workspaceEdit = await self . _renameRunnable . runnable . getWorkspaceEdit ( ) ;
@@ -304,19 +304,19 @@ export class RenameSymbolProcessor extends Disposable {
304304 return suggestItem ;
305305 }
306306
307- const edit = suggestItem . action . textReplacement ;
308-
309307 const start = Date . now ( ) ;
310-
308+ const edit = suggestItem . action . textReplacement ;
311309 const languageConfiguration = this . _languageConfigurationService . getLanguageConfiguration ( textModel . getLanguageId ( ) ) ;
312310
311+ // Check synchronously if a rename is possible
313312 const edits = this . _renameInferenceEngine . inferRename ( textModel , edit . range , edit . text , languageConfiguration . wordDefinition ) ;
314313 if ( edits === undefined || edits . renames . edits . length === 0 ) {
315314 return suggestItem ;
316315 }
317316
318317 const { oldName, newName, position, edits : renameEdits } = edits . renames ;
319318
319+ // Check asynchronously if a rename is possible
320320 let timedOut = false ;
321321 const check = await raceTimeout < RenameKind > ( this . checkRenamePrecondition ( suggestItem , textModel , position , oldName , newName ) , 1000 , ( ) => { timedOut = true ; } ) ;
322322 const renamePossible = check === RenameKind . yes || check === RenameKind . maybe ;
@@ -333,7 +333,16 @@ export class RenameSymbolProcessor extends Disposable {
333333 return suggestItem ;
334334 }
335335
336+ // Prepare the rename edits
336337 const id = suggestItem . identity . id ;
338+ if ( this . _renameRunnable !== undefined ) {
339+ this . _renameRunnable . runnable . cancel ( ) ;
340+ this . _renameRunnable = undefined ;
341+ }
342+ const runnable = new RenameSymbolRunnable ( this . _languageFeaturesService , textModel , position , newName ) ;
343+ this . _renameRunnable = { id, runnable } ;
344+
345+ // Create alternative action
337346 const source = EditSources . inlineCompletionAccept ( {
338347 nes : suggestItem . isInlineEdit ,
339348 requestUuid : suggestItem . requestUuid ,
@@ -345,23 +354,21 @@ export class RenameSymbolProcessor extends Disposable {
345354 title : localize ( 'rename' , "Rename" ) ,
346355 arguments : [ textModel , position , newName , source , id ] ,
347356 } ;
348- const textReplacement = renameEdits [ 0 ] ;
357+ const alternativeAction : InlineSuggestAlternativeAction = {
358+ label : localize ( 'rename' , "Rename" ) ,
359+ //icon: Codicon.replaceAll,
360+ command,
361+ count : runnable . getCount ( ) ,
362+ } ;
349363 const renameAction : IInlineSuggestDataActionEdit = {
350364 kind : 'edit' ,
351- range : textReplacement . range ,
352- insertText : textReplacement . text ,
365+ range : renameEdits [ 0 ] . range ,
366+ insertText : renameEdits [ 0 ] . text ,
353367 snippetInfo : suggestItem . snippetInfo ,
354- alternativeAction : command ,
368+ alternativeAction,
355369 uri : textModel . uri
356370 } ;
357371
358- if ( this . _renameRunnable !== undefined ) {
359- this . _renameRunnable . runnable . cancel ( ) ;
360- this . _renameRunnable = undefined ;
361- }
362- const runnable = new RenameSymbolRunnable ( this . _languageFeaturesService , textModel , position , newName , source ) ;
363- this . _renameRunnable = { id, runnable } ;
364-
365372 return InlineSuggestionItem . create ( suggestItem . withAction ( renameAction ) , textModel ) ;
366373 }
367374
0 commit comments