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:
parent
9e7afe870a
commit
ba743a1bd9
4 changed files with 77 additions and 0 deletions
|
@ -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>,
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue