Skip to content

Commit 69f86ad

Browse files
committed
rename widget: lots of traces to identify why rename widget doesn't appear sometimes
1 parent 3ee2bef commit 69f86ad

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/vs/editor/contrib/rename/browser/rename.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class RenameController implements IEditorContribution {
315315
}
316316

317317
cancelRenameInput(): void {
318-
this._renameInputField.cancelInput(true);
318+
this._renameInputField.cancelInput(true, 'cancelRenameInput command');
319319
}
320320

321321
focusNextRenameSuggestion(): void {

src/vs/editor/contrib/rename/browser/renameInputField.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { NewSymbolName, NewSymbolNameTag, ProviderResult } from 'vs/editor/commo
2525
import { localize } from 'vs/nls';
2626
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
2727
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
28+
import { ILogService } from 'vs/platform/log/common/log';
2829
import { defaultListStyles } from 'vs/platform/theme/browser/defaultStyles';
2930
import {
3031
editorWidgetBackground,
@@ -72,6 +73,7 @@ export class RenameInputField implements IContentWidget {
7273
@IThemeService private readonly _themeService: IThemeService,
7374
@IKeybindingService private readonly _keybindingService: IKeybindingService,
7475
@IContextKeyService contextKeyService: IContextKeyService,
76+
@ILogService private readonly _logService: ILogService,
7577
) {
7678
this._visibleContextKey = CONTEXT_RENAME_INPUT_VISIBLE.bindTo(contextKeyService);
7779
this._focusedContextKey = CONTEXT_RENAME_INPUT_FOCUSED.bindTo(contextKeyService);
@@ -206,9 +208,10 @@ export class RenameInputField implements IContentWidget {
206208
}
207209

208210
afterRender(position: ContentWidgetPositionPreference | null): void {
211+
this._trace('invoking afterRender, position: ', position ? 'not null' : 'null');
209212
if (position === null) {
210213
// cancel rename when input widget isn't rendered anymore
211-
this.cancelInput(true);
214+
this.cancelInput(true, 'afterRender (because position is null)');
212215
return;
213216
}
214217

@@ -241,10 +244,12 @@ export class RenameInputField implements IContentWidget {
241244
private _currentCancelInput?: (focusEditor: boolean) => void;
242245

243246
acceptInput(wantsPreview: boolean): void {
247+
this._trace(`invoking acceptInput`);
244248
this._currentAcceptInput?.(wantsPreview);
245249
}
246250

247-
cancelInput(focusEditor: boolean): void {
251+
cancelInput(focusEditor: boolean, caller: string): void {
252+
this._trace(`invoking cancelInput, caller: ${caller}, _currentCancelInput: ${this._currentAcceptInput ? 'not undefined' : 'undefined'}`);
248253
this._currentCancelInput?.(focusEditor);
249254
}
250255

@@ -280,6 +285,7 @@ export class RenameInputField implements IContentWidget {
280285
return new Promise<RenameInputFieldResult | boolean>(resolve => {
281286

282287
this._currentCancelInput = (focusEditor) => {
288+
this._trace('invoking _currentCancelInput');
283289
this._currentAcceptInput = undefined;
284290
this._currentCancelInput = undefined;
285291
this._candidatesView?.clearCandidates();
@@ -288,12 +294,13 @@ export class RenameInputField implements IContentWidget {
288294
};
289295

290296
this._currentAcceptInput = (wantsPreview) => {
297+
this._trace('invoking _currentAcceptInput');
291298
assertType(this._input !== undefined);
292299
assertType(this._candidatesView !== undefined);
293300

294301
const candidateName = this._candidatesView.focusedCandidate;
295302
if ((candidateName === undefined && this._input.value === value) || this._input.value.trim().length === 0) {
296-
this.cancelInput(true);
303+
this.cancelInput(true, '_currentAcceptInput (because candidateName is undefined or input.value is empty)');
297304
return;
298305
}
299306

@@ -307,9 +314,9 @@ export class RenameInputField implements IContentWidget {
307314
});
308315
};
309316

310-
disposeOnDone.add(cts.token.onCancellationRequested(() => this.cancelInput(true)));
317+
disposeOnDone.add(cts.token.onCancellationRequested(() => this.cancelInput(true, 'cts.token.onCancellationRequested')));
311318
if (!_sticky) {
312-
disposeOnDone.add(this._editor.onDidBlurEditorWidget(() => this.cancelInput(!this._domNode?.ownerDocument.hasFocus())));
319+
disposeOnDone.add(this._editor.onDidBlurEditorWidget(() => this.cancelInput(!this._domNode?.ownerDocument.hasFocus(), 'editor.onDidBlurEditorWidget')));
313320
}
314321

315322
this._show();
@@ -321,6 +328,7 @@ export class RenameInputField implements IContentWidget {
321328
}
322329

323330
private _show(): void {
331+
this._trace('invoking _show');
324332
this._editor.revealLineInCenterIfOutsideViewport(this._position!.lineNumber, ScrollType.Smooth);
325333
this._visible = true;
326334
this._visibleContextKey.set(true);
@@ -335,9 +343,13 @@ export class RenameInputField implements IContentWidget {
335343
}
336344

337345
private async _updateRenameCandidates(candidates: ProviderResult<NewSymbolName[]>[], currentName: string, token: CancellationToken) {
346+
const trace = (...args: any[]) => this._trace('_updateRenameCandidates', ...args);
347+
348+
trace('start');
338349
const namesListResults = await raceCancellation(Promise.allSettled(candidates), token);
339350

340351
if (namesListResults === undefined) {
352+
trace('returning early - received updateRenameCandidates results - undefined');
341353
return;
342354
}
343355

@@ -346,27 +358,39 @@ export class RenameInputField implements IContentWidget {
346358
? namesListResult.value
347359
: []
348360
);
361+
trace(`received updateRenameCandidates results - total (unfiltered) ${newNames.length} candidates.`);
349362

350363
// deduplicate and filter out the current value
351364
const distinctNames = arrays.distinct(newNames, v => v.newSymbolName);
365+
trace(`distinct candidates - ${distinctNames.length} candidates.`);
366+
352367
const validDistinctNames = distinctNames.filter(({ newSymbolName }) => newSymbolName.trim().length > 0 && newSymbolName !== this._input?.value && newSymbolName !== currentName);
368+
trace(`valid distinct candidates - ${newNames.length} candidates.`);
353369

354370
if (validDistinctNames.length < 1) {
371+
trace('returning early - no valid distinct candidates');
355372
return;
356373
}
357374

358375
// show the candidates
376+
trace('setting candidates');
359377
this._candidatesView!.setCandidates(validDistinctNames);
360378

361379
// ask editor to re-layout given that the widget is now of a different size after rendering rename candidates
380+
trace('asking editor to re-layout');
362381
this._editor.layoutContentWidget(this);
363382
}
364383

365384
private _hide(): void {
385+
this._trace('invoked _hide');
366386
this._visible = false;
367387
this._visibleContextKey.reset();
368388
this._editor.layoutContentWidget(this);
369389
}
390+
391+
private _trace(...args: any[]) {
392+
this._logService.trace('RenameInputField', ...args);
393+
}
370394
}
371395

372396
export class CandidatesView {

0 commit comments

Comments
 (0)