Skip to content

Comments

[ty] Swap detail and description fields for CompletionItemLabelDetails#20466

Merged
BurntSushi merged 1 commit intomainfrom
ag/fix-weird-type-rendering
Sep 18, 2025
Merged

[ty] Swap detail and description fields for CompletionItemLabelDetails#20466
BurntSushi merged 1 commit intomainfrom
ag/fix-weird-type-rendering

Conversation

@BurntSushi
Copy link
Member

@BurntSushi BurntSushi commented Sep 18, 2025

This seems to be more consistent with how other LSPs work (like
rust-analyzer), and also I think is more consistent with how
CompletionItem.detail is itself rendered. Namely, in VS Code, it
is right-aligned. And it's also where we put the type signature.
But CompletionItemLabelDetails.detail is left-aligned where as
CompletionItemLabelDetails.description is right-aligned. So let's
swap them such that type signatures go in the latter and not the
former.

Fixes astral-sh/ty#1200

@BurntSushi
Copy link
Member Author

Demo:

2025-09-18T08.26.54-04.00.mp4

@github-actions
Copy link
Contributor

github-actions bot commented Sep 18, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@MichaReiser
Copy link
Member

MichaReiser commented Sep 18, 2025

Thanks for looking into this.

It now seems unfortunate that the module name comes directly (without any space) after the completion text which seems expected acording to the LSP specification

/**
 * Additional details for a completion item label.
 *
 * @since 3.17.0
 */
export interface [CompletionItemLabelDetails](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemLabelDetails) {

	/**
	 * An optional string which is rendered less prominently directly after
	 * {@link CompletionItem.label label}, without any spacing. Should be
	 * used for function signatures or type annotations.
	 */
	detail?: string;

	/**
	 * An optional string which is rendered less prominently after
	 * {@link CompletionItemLabelDetails.detail}. Should be used for fully qualified
	 * names or file path.
	 */
	description?: string;
}

I think we should at least insert a space at the front of detail if we want to use that field.

Or we keep using detail for the type but change the syntax to : {type}, similar to what we show in inlay hints. Wdyt?

Edit: I only just now saw your detailed write-up on the issue. I think what you did makes sense. I'm only wondering if we should introduce a space to make this look less squeezed together

Edit2: It seems that r-a solves this visual issue by using (use <module name>) for the left aligned content which helps a bit.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 18, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

…etails`

This seems to be more consistent with how other LSPs work (like
`rust-analyzer`), and also I think is more consistent with how
`CompletionItem.detail` is itself rendered. Namely, in VS Code, it
is right-aligned. And it's also where we put the type signature.
But `CompletionItemLabelDetails.detail` is left-aligned where as
`CompletionItemLabelDetails.description` is right-aligned. So let's
swap them such that type signatures go in the latter and not the
former.

This also adds a space before the module name and contextualizes
it with `(import <name>)` to help aide the end user in figuring out
selecting the completion will do.

Fixes #1200
@BurntSushi BurntSushi force-pushed the ag/fix-weird-type-rendering branch from 265b038 to 421b24a Compare September 18, 2025 12:48
@BurntSushi
Copy link
Member Author

Yeah and r-a inserts a leading space too.

I added the leading space and added (import <name>), which I think also helps (similar r-a's (use <name>)).

Demo:

2025-09-18T08.47.29-04.00.mp4

@MichaReiser MichaReiser added bug Something isn't working server Related to the LSP server labels Sep 18, 2025
Copy link
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@BurntSushi BurntSushi merged commit 1ebbe73 into main Sep 18, 2025
40 checks passed
@BurntSushi BurntSushi deleted the ag/fix-weird-type-rendering branch September 18, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working server Related to the LSP server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Types are weirdly attached to symbols in auto-completions

3 participants