input: Allow configuring the completion popover max width#2369
Open
narma wants to merge 2 commits into
Open
Conversation
The `MAX_MENU_WIDTH` constant in the LSP completion popover was hardcoded at 320 px and there was no public way to override it from outside the crate. That caps the popover at a width that comfortably fits English identifiers but truncates longer LSP labels (e.g. database table identifiers such as `tbl_verification_tracking`). This change: - Renames `MAX_MENU_WIDTH` to `DEFAULT_MAX_MENU_WIDTH` (still `pub(crate)`) and keeps the same 320 px default — no behavior change for existing callers. - Stores `max_width: Pixels` on `CompletionMenu` and threads it through `CompletionMenu::new`, the items column, the documentation panel, and the side-by-side vs vertical layout overflow check. - Adds `InputState::completion_menu_max_width(width)` (builder) and `InputState::set_completion_menu_max_width(width, window, cx)` (runtime setter) so embedders can widen the popover. The runtime setter also forwards into an already-open popover. 🤖 Generated by AI (Claude), reviewed and tested by a human.
Member
|
This is not a good API, but I don't know is there have a better choice. |
Author
|
@huacnlee good point — agreed the two Instead of a dedicated builder + runtime setter on pub struct CompletionMenuOptions {
pub max_width: Pixels, // default 320 px
}
pub struct Lsp {
pub completion_provider: ...,
pub code_action_providers: ...,
pub completion_menu: CompletionMenuOptions,
...
}Usage from the embedder side: let mut state = InputState::new(window, cx).code_editor("sql");
state.lsp.completion_menu.max_width = px(480.);What this buys us:
Net diff vs the previous revision: +31 / −60 lines. Happy to iterate further if you'd prefer a different shape (e.g. keeping it on |
Replace the standalone `InputState::completion_menu_max_width` builder
and `set_completion_menu_max_width` runtime setter with a single
`CompletionMenuOptions` struct exposed as a public field on `Lsp`, in
line with the existing `Lsp::completion_provider` / `code_action_providers`
pattern.
- Add `pub struct CompletionMenuOptions { pub max_width: Pixels }` in
`lsp/completions.rs` (default 320 px), re-exported via `pub use lsp::*`.
- Add `pub completion_menu: CompletionMenuOptions` to `Lsp`.
- Drop the dedicated field, builder and runtime setter on `InputState`,
and drop the duplicated `max_width` storage + `set_max_width` method on
`CompletionMenu`. The popover reads the value from
`self.editor.read(cx).lsp.completion_menu.max_width` on render, so
runtime updates work through normal entity update flow.
Usage:
let mut state = InputState::new(window, cx).code_editor("sql");
state.lsp.completion_menu.max_width = px(480.);
Future per-popover options (height, padding, doc panel toggles) can be
added as fields on `CompletionMenuOptions` without growing the
`InputState` API surface.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ca0e645 to
34a11ba
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The LSP completion popover width is currently capped at a hardcoded
MAX_MENU_WIDTHof 320 px, and there's no public API to override it from outside the crate. That's fine for most identifiers, but it truncates longer LSP labels — e.g. database table identifiers liketbl_verification_trackingthat show up in completions for editors hosting SQL/MongoDB/etc. clients.This PR keeps the default at 320 px (no visual change for existing callers) and adds a way to widen the popover per editor:
MAX_MENU_WIDTHtoDEFAULT_MAX_MENU_WIDTH(stillpub(crate)).max_width: PixelsonCompletionMenuand threads it throughCompletionMenu::new, the items column, the documentation panel, and the side-by-side vs vertical layout overflow check.InputState:completion_menu_max_width(width: Pixels) -> Self— builder.set_completion_menu_max_width(width, window, cx)— runtime setter that also forwards into an already-open popover.Usage:
AI Assistance
🤖 The patch was drafted by Claude and reviewed/tested by a human; it follows the existing builder-method pattern used for
placeholder,searchable,folding, etc.Test plan
cargo check -p gpui-componentcargo clippy -p gpui-component -- -D warningsrustfmton the three touched files