Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export class MarkdownHoverParticipant implements IEditorHoverParticipant<Markdow
) { }

public createLoadingMessage(anchor: HoverAnchor): MarkdownHover | null {
return new MarkdownHover(this, anchor.range, [new MarkdownString().appendText(nls.localize('modesContentHover.loading', "Loading..."))], false, 2000);
// Use ordinal 0 so the loading placeholder appears in the same position
// as the eventual content (language server descriptions use ordinal ~0),
// avoiding a visual jump when the real content replaces it.
return new MarkdownHover(this, anchor.range, [new MarkdownString().appendText(nls.localize('modesContentHover.loading', "Loading..."))], false, 0);
}

public computeSync(anchor: HoverAnchor, lineDecorations: IModelDecoration[]): MarkdownHover[] {
Expand Down
23 changes: 23 additions & 0 deletions src/vs/editor/contrib/hover/test/browser/contentHover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
*--------------------------------------------------------------------------------------------*/

import assert from 'assert';
import { compareBy, numberComparator } from '../../../../../base/common/arrays.js';
import { MarkdownString } from '../../../../../base/common/htmlContent.js';
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
import { Position } from '../../../../common/core/position.js';
import { Range } from '../../../../common/core/range.js';
import { RenderedContentHover } from '../../browser/contentHoverRendered.js';
import { MarkdownHover } from '../../browser/markdownHoverParticipant.js';
import { IHoverPart } from '../../browser/hoverTypes.js';
import { TestCodeEditorInstantiationOptions, withTestCodeEditor } from '../../../../test/browser/testCodeEditor.js';

Expand Down Expand Up @@ -51,4 +54,24 @@ suite('Content Hover', () => {
);
});
});

test('issue #320604: Loading message ordinal 0 sorts above action buttons at ordinal 1', () => {
const anchor = new Range(1, 1, 1, 10);
const owner = <MarkdownHover['owner']>{};

const loading = new MarkdownHover(owner, anchor, [new MarkdownString().appendText('Loading...')], false, 0);
const runScript = new MarkdownHover(owner, anchor, [new MarkdownString().appendText('Run Script')], false, 1);
const debugScript = new MarkdownHover(owner, anchor, [new MarkdownString().appendText('Debug Script')], false, 1);

// Parts arrive with buttons before loading (simulating fast npm provider, slow description)
const parts = [runScript, debugScript, loading];
parts.sort(compareBy(hover => hover.ordinal, numberComparator));

assert.strictEqual(parts[0], loading, 'Loading (ordinal 0) should sort before buttons (ordinal 1)');
// Both buttons have ordinal 1; only assert they appear after loading
assert.strictEqual(parts.length, 3);
assert.ok(parts[1] === runScript || parts[1] === debugScript);
assert.ok(parts[2] === runScript || parts[2] === debugScript);
assert.notStrictEqual(parts[1], parts[2]);
});
});