Add setting to disable inline completions in language scopes (#20508)

This adds a setting to disable inline completions in language scopes to,
for example, disable them in comments or strings.

This setting can be made per language.

Examples:

```json
{
  "languages": {
    "Go": {
      "inline_completions_disabled_in": ["comment", "string"]
    }
  }
}
```

```json
{
  "inline_completions_disabled_in": ["comment"]
}
```

Closes #9133

Release Notes:

- Added language setting to disable inline comments in certain scopes.
Example: `{"languages": {"Go": {"inline_completions_disabled_in":
["comment", "string"]}}}`

Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
Thorsten Ball 2024-11-11 18:09:05 +01:00 committed by GitHub
parent 9e7afe870a
commit ba743a1bd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 77 additions and 0 deletions

View file

@ -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<String>,
/// 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<bool>,
/// Controls whether inline completions are shown in the given language
/// scopes.
///
/// Example: ["string", "comment"]
///
/// Default: []
#[serde(default)]
pub inline_completions_disabled_in: Option<Vec<String>>,
/// Whether to show tabs and spaces in the editor.
#[serde(default)]
pub show_whitespaces: Option<ShowWhitespaceSetting>,
@ -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,