Add per-language settings show_completions_on_input and show_completion_documentation (#21722)

Release Notes:

- Added `show_completions_on_input` and `show_completion_documentation`
per-language settings. These settings were available before, but were
not configurable per-language.
This commit is contained in:
Michael Sloan 2024-12-09 11:53:50 -07:00 committed by GitHub
parent b7edf31170
commit a5355e92e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 44 additions and 29 deletions

View file

@ -1006,12 +1006,14 @@ struct CompletionsMenu {
scroll_handle: UniformListScrollHandle, scroll_handle: UniformListScrollHandle,
resolve_completions: bool, resolve_completions: bool,
aside_was_displayed: Cell<bool>, aside_was_displayed: Cell<bool>,
show_completion_documentation: bool,
} }
impl CompletionsMenu { impl CompletionsMenu {
fn new( fn new(
id: CompletionId, id: CompletionId,
sort_completions: bool, sort_completions: bool,
show_completion_documentation: bool,
initial_position: Anchor, initial_position: Anchor,
buffer: Model<Buffer>, buffer: Model<Buffer>,
completions: Box<[Completion]>, completions: Box<[Completion]>,
@ -1040,6 +1042,7 @@ impl CompletionsMenu {
scroll_handle: UniformListScrollHandle::new(), scroll_handle: UniformListScrollHandle::new(),
resolve_completions: true, resolve_completions: true,
aside_was_displayed: Cell::new(aside_was_displayed), aside_was_displayed: Cell::new(aside_was_displayed),
show_completion_documentation: show_completion_documentation,
} }
} }
@ -1094,6 +1097,7 @@ impl CompletionsMenu {
scroll_handle: UniformListScrollHandle::new(), scroll_handle: UniformListScrollHandle::new(),
resolve_completions: false, resolve_completions: false,
aside_was_displayed: Cell::new(false), aside_was_displayed: Cell::new(false),
show_completion_documentation: false,
} }
} }
@ -1192,9 +1196,7 @@ impl CompletionsMenu {
workspace: Option<WeakView<Workspace>>, workspace: Option<WeakView<Workspace>>,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> AnyElement { ) -> AnyElement {
let settings = EditorSettings::get_global(cx); let show_completion_documentation = self.show_completion_documentation;
let show_completion_documentation = settings.show_completion_documentation;
let widest_completion_ix = self let widest_completion_ix = self
.matches .matches
.iter() .iter()
@ -4459,6 +4461,11 @@ impl Editor {
} else { } else {
return; return;
}; };
let show_completion_documentation = buffer
.read(cx)
.snapshot()
.settings_at(buffer_position, cx)
.show_completion_documentation;
let query = Self::completion_query(&self.buffer.read(cx).read(cx), position); let query = Self::completion_query(&self.buffer.read(cx).read(cx), position);
@ -4496,6 +4503,7 @@ impl Editor {
let mut menu = CompletionsMenu::new( let mut menu = CompletionsMenu::new(
id, id,
sort_completions, sort_completions,
show_completion_documentation,
position, position,
buffer.clone(), buffer.clone(),
completions.into(), completions.into(),
@ -14174,10 +14182,6 @@ impl CompletionProvider for Model<Project> {
trigger_in_words: bool, trigger_in_words: bool,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> bool { ) -> bool {
if !EditorSettings::get_global(cx).show_completions_on_input {
return false;
}
let mut chars = text.chars(); let mut chars = text.chars();
let char = if let Some(char) = chars.next() { let char = if let Some(char) = chars.next() {
char char
@ -14189,10 +14193,11 @@ impl CompletionProvider for Model<Project> {
} }
let buffer = buffer.read(cx); let buffer = buffer.read(cx);
let classifier = buffer let snapshot = buffer.snapshot();
.snapshot() if !snapshot.settings_at(position, cx).show_completions_on_input {
.char_classifier_at(position) return false;
.for_completion(true); }
let classifier = snapshot.char_classifier_at(position).for_completion(true);
if trigger_in_words && classifier.is_word(char) { if trigger_in_words && classifier.is_word(char) {
return true; return true;
} }

View file

@ -10,8 +10,6 @@ pub struct EditorSettings {
pub cursor_shape: Option<CursorShape>, pub cursor_shape: Option<CursorShape>,
pub current_line_highlight: CurrentLineHighlight, pub current_line_highlight: CurrentLineHighlight,
pub hover_popover_enabled: bool, pub hover_popover_enabled: bool,
pub show_completions_on_input: bool,
pub show_completion_documentation: bool,
pub toolbar: Toolbar, pub toolbar: Toolbar,
pub scrollbar: Scrollbar, pub scrollbar: Scrollbar,
pub gutter: Gutter, pub gutter: Gutter,
@ -193,16 +191,6 @@ pub struct EditorSettingsContent {
/// Default: true /// Default: true
pub hover_popover_enabled: Option<bool>, pub hover_popover_enabled: Option<bool>,
/// Whether to pop the completions menu while typing in an editor without
/// explicitly requesting it.
///
/// Default: true
pub show_completions_on_input: Option<bool>,
/// Whether to display inline and alongside documentation for items in the
/// completions menu.
///
/// Default: true
pub show_completion_documentation: Option<bool>,
/// Toolbar related settings /// Toolbar related settings
pub toolbar: Option<ToolbarContent>, pub toolbar: Option<ToolbarContent>,
/// Scrollbar related settings /// Scrollbar related settings

View file

@ -8376,12 +8376,8 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
handle_resolve_completion_request(&mut cx, None).await; handle_resolve_completion_request(&mut cx, None).await;
apply_additional_edits.await.unwrap(); apply_additional_edits.await.unwrap();
cx.update(|cx| { update_test_language_settings(&mut cx, |settings| {
cx.update_global::<SettingsStore, _>(|settings, cx| { settings.defaults.show_completions_on_input = Some(false);
settings.update_user_settings::<EditorSettings>(cx, |settings| {
settings.show_completions_on_input = Some(false);
});
})
}); });
cx.set_state("editorˇ"); cx.set_state("editorˇ");
cx.simulate_keystroke("."); cx.simulate_keystroke(".");

View file

@ -138,6 +138,12 @@ pub struct LanguageSettings {
pub linked_edits: bool, pub linked_edits: bool,
/// Task configuration for this language. /// Task configuration for this language.
pub tasks: LanguageTaskConfig, pub tasks: LanguageTaskConfig,
/// Whether to pop the completions menu while typing in an editor without
/// explicitly requesting it.
pub show_completions_on_input: bool,
/// Whether to display inline and alongside documentation for items in the
/// completions menu.
pub show_completion_documentation: bool,
} }
impl LanguageSettings { impl LanguageSettings {
@ -382,6 +388,16 @@ pub struct LanguageSettingsContent {
/// ///
/// Default: {} /// Default: {}
pub tasks: Option<LanguageTaskConfig>, pub tasks: Option<LanguageTaskConfig>,
/// Whether to pop the completions menu while typing in an editor without
/// explicitly requesting it.
///
/// Default: true
pub show_completions_on_input: Option<bool>,
/// Whether to display inline and alongside documentation for items in the
/// completions menu.
///
/// Default: true
pub show_completion_documentation: Option<bool>,
} }
/// The contents of the inline completion settings. /// The contents of the inline completion settings.
@ -1186,6 +1202,14 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent
src.extend_comment_on_newline, src.extend_comment_on_newline,
); );
merge(&mut settings.inlay_hints, src.inlay_hints); merge(&mut settings.inlay_hints, src.inlay_hints);
merge(
&mut settings.show_completions_on_input,
src.show_completions_on_input,
);
merge(
&mut settings.show_completion_documentation,
src.show_completion_documentation,
);
} }
/// Allows to enable/disable formatting with Prettier /// Allows to enable/disable formatting with Prettier

View file

@ -56,6 +56,8 @@ You can customize a wide range of settings for each language, including:
- [`hard_tabs`](./configuring-zed.md#hard-tabs): Use tabs instead of spaces for indentation - [`hard_tabs`](./configuring-zed.md#hard-tabs): Use tabs instead of spaces for indentation
- [`preferred_line_length`](./configuring-zed.md#preferred-line-length): The recommended maximum line length - [`preferred_line_length`](./configuring-zed.md#preferred-line-length): The recommended maximum line length
- [`soft_wrap`](./configuring-zed.md#soft-wrap): How to wrap long lines of code - [`soft_wrap`](./configuring-zed.md#soft-wrap): How to wrap long lines of code
- [`show_completions_on_input`](./configuring-zed.md#show-completions-on-input): Whether or not to show completions as you type
- [`show_completion_documentation`](./configuring-zed.md#show-completion-documentation): Whether to display inline and alongside documentation for items in the completions menu
These settings allow you to maintain specific coding styles across different languages and projects. These settings allow you to maintain specific coding styles across different languages and projects.