diff --git a/assets/settings/default.json b/assets/settings/default.json index 9bde6e9c78..ee08ce562d 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -193,6 +193,9 @@ // Controls whether inline completions are shown immediately (true) // or manually by triggering `editor::ShowInlineCompletion` (false). "show_inline_completions": true, + // Controls whether inline completions are shown in a given language scope. + // Example: ["string", "comment"] + "inline_completions_disabled_in": [], // Whether to show tabs and spaces in the editor. // This setting can take three values: // diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index ea3c1ee7a6..8ccfc1b6a3 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2510,6 +2510,10 @@ impl Editor { return false; } + if self.inline_completions_disabled_in_scope(buffer, buffer_position, cx) { + return false; + } + if let Some(provider) = self.inline_completion_provider() { if let Some(show_inline_completions) = self.show_inline_completions_override { show_inline_completions @@ -2521,6 +2525,27 @@ impl Editor { } } + fn inline_completions_disabled_in_scope( + &self, + buffer: &Model, + buffer_position: language::Anchor, + cx: &AppContext, + ) -> bool { + let snapshot = buffer.read(cx).snapshot(); + let settings = snapshot.settings_at(buffer_position, cx); + + let Some(scope) = snapshot.language_scope_at(buffer_position) else { + return false; + }; + + scope.override_name().map_or(false, |scope_name| { + settings + .inline_completions_disabled_in + .iter() + .any(|s| s == scope_name) + }) + } + pub fn set_use_modal_editing(&mut self, to: bool) { self.use_modal_editing = to; } diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index 4df44d730c..a3ac40b714 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -112,6 +112,9 @@ pub struct LanguageSettings { /// Controls whether inline completions are shown immediately (true) /// or manually by triggering `editor::ShowInlineCompletion` (false). pub show_inline_completions: bool, + /// Controls whether inline completions are shown in the given language + /// scopes. + pub inline_completions_disabled_in: Vec, /// Whether to show tabs and spaces in the editor. pub show_whitespaces: ShowWhitespaceSetting, /// Whether to start a new line with a comment when a previous line is a comment as well. @@ -318,6 +321,14 @@ pub struct LanguageSettingsContent { /// Default: true #[serde(default)] pub show_inline_completions: Option, + /// Controls whether inline completions are shown in the given language + /// scopes. + /// + /// Example: ["string", "comment"] + /// + /// Default: [] + #[serde(default)] + pub inline_completions_disabled_in: Option>, /// Whether to show tabs and spaces in the editor. #[serde(default)] pub show_whitespaces: Option, @@ -1164,6 +1175,10 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent &mut settings.show_inline_completions, src.show_inline_completions, ); + merge( + &mut settings.inline_completions_disabled_in, + src.inline_completions_disabled_in.clone(), + ); merge(&mut settings.show_whitespaces, src.show_whitespaces); merge( &mut settings.extend_comment_on_newline, diff --git a/docs/src/configuring-zed.md b/docs/src/configuring-zed.md index d123f2deac..456d691707 100644 --- a/docs/src/configuring-zed.md +++ b/docs/src/configuring-zed.md @@ -359,6 +359,40 @@ There are two options to choose from: List of `string` values +## Inline Completions Disabled in + +- Description: A list of language scopes in which inline completions should be disabled. +- Setting: `inline_completions_disabled_in` +- Default: `[]` + +**Options** + +List of `string` values + +1. Don't show inline completions in comments: + +```json +"disabled_in": ["comment"] +``` + +2. Don't show inline completions in strings and comments: + +```json +"disabled_in": ["comment", "string"] +``` + +3. Only in Go, don't show inline completions in strings and comments: + +```json +{ + "languages": { + "Go": { + "inline_completions_disabled_in": ["comment", "string"] + } + } +} +``` + ## Current Line Highlight - Description: How to highlight the current line in the editor.