Supermaven (#10788)

Adds a supermaven provider for completions. There are various other
refactors amidst this branch, primarily to make copilot no longer a
dependency of project as well as show LSP Logs for global LSPs like
copilot properly.

This feature is not enabled by default. We're going to seek to refine it
in the coming weeks.

Release Notes:

- N/A

---------

Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Nathan Sobo <nathan@zed.dev>
Co-authored-by: Max <max@zed.dev>
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Kyle Kelley 2024-05-03 12:50:42 -07:00 committed by GitHub
parent 610968815c
commit 6563330239
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 2242 additions and 827 deletions

View file

@ -51,8 +51,8 @@ pub fn all_language_settings<'a>(
/// The settings for all languages.
#[derive(Debug, Clone)]
pub struct AllLanguageSettings {
/// The settings for GitHub Copilot.
pub copilot: CopilotSettings,
/// The inline completion settings.
pub inline_completions: InlineCompletionSettings,
defaults: LanguageSettings,
languages: HashMap<Arc<str>, LanguageSettings>,
pub(crate) file_types: HashMap<Arc<str>, Vec<String>>,
@ -101,9 +101,9 @@ pub struct LanguageSettings {
/// - `"!<language_server_id>"` - A language server ID prefixed with a `!` will be disabled.
/// - `"..."` - A placeholder to refer to the **rest** of the registered language servers for this language.
pub language_servers: Vec<Arc<str>>,
/// Controls whether Copilot provides suggestion immediately (true)
/// or waits for a `copilot::Toggle` (false).
pub show_copilot_suggestions: bool,
/// Controls whether inline completions are shown immediately (true)
/// or manually by triggering `editor::ShowInlineCompletion` (false).
pub show_inline_completions: bool,
/// 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.
@ -165,12 +165,23 @@ impl LanguageSettings {
}
}
/// The settings for [GitHub Copilot](https://github.com/features/copilot).
/// The provider that supplies inline completions.
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum InlineCompletionProvider {
None,
#[default]
Copilot,
Supermaven,
}
/// The settings for inline completions, such as [GitHub Copilot](https://github.com/features/copilot)
/// or [Supermaven](https://supermaven.com).
#[derive(Clone, Debug, Default)]
pub struct CopilotSettings {
/// Whether Copilot is enabled.
pub feature_enabled: bool,
/// A list of globs representing files that Copilot should be disabled for.
pub struct InlineCompletionSettings {
/// The provider that supplies inline completions.
pub provider: InlineCompletionProvider,
/// A list of globs representing files that inline completions should be disabled for.
pub disabled_globs: Vec<GlobMatcher>,
}
@ -180,9 +191,9 @@ pub struct AllLanguageSettingsContent {
/// The settings for enabling/disabling features.
#[serde(default)]
pub features: Option<FeaturesContent>,
/// The settings for GitHub Copilot.
#[serde(default)]
pub copilot: Option<CopilotSettingsContent>,
/// The inline completion settings.
#[serde(default, alias = "copilot")]
pub inline_completions: Option<InlineCompletionSettingsContent>,
/// The default language settings.
#[serde(flatten)]
pub defaults: LanguageSettingsContent,
@ -277,12 +288,12 @@ pub struct LanguageSettingsContent {
/// Default: ["..."]
#[serde(default)]
pub language_servers: Option<Vec<Arc<str>>>,
/// Controls whether Copilot provides suggestion immediately (true)
/// or waits for a `copilot::Toggle` (false).
/// Controls whether inline completions are shown immediately (true)
/// or manually by triggering `editor::ShowInlineCompletion` (false).
///
/// Default: true
#[serde(default)]
pub show_copilot_suggestions: Option<bool>,
#[serde(default, alias = "show_copilot_suggestions")]
pub show_inline_completions: Option<bool>,
/// Whether to show tabs and spaces in the editor.
#[serde(default)]
pub show_whitespaces: Option<ShowWhitespaceSetting>,
@ -314,10 +325,10 @@ pub struct LanguageSettingsContent {
pub code_actions_on_format: Option<HashMap<String, bool>>,
}
/// The contents of the GitHub Copilot settings.
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)]
pub struct CopilotSettingsContent {
/// A list of globs representing files that Copilot should be disabled for.
/// The contents of the inline completion settings.
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct InlineCompletionSettingsContent {
/// A list of globs representing files that inline completions should be disabled for.
#[serde(default)]
pub disabled_globs: Option<Vec<String>>,
}
@ -328,6 +339,8 @@ pub struct CopilotSettingsContent {
pub struct FeaturesContent {
/// Whether the GitHub Copilot feature is enabled.
pub copilot: Option<bool>,
/// Determines which inline completion provider to use.
pub inline_completion_provider: Option<InlineCompletionProvider>,
}
/// Controls the soft-wrapping behavior in the editor.
@ -475,29 +488,29 @@ impl AllLanguageSettings {
&self.defaults
}
/// Returns whether GitHub Copilot is enabled for the given path.
pub fn copilot_enabled_for_path(&self, path: &Path) -> bool {
/// Returns whether inline completions are enabled for the given path.
pub fn inline_completions_enabled_for_path(&self, path: &Path) -> bool {
!self
.copilot
.inline_completions
.disabled_globs
.iter()
.any(|glob| glob.is_match(path))
}
/// Returns whether GitHub Copilot is enabled for the given language and path.
pub fn copilot_enabled(&self, language: Option<&Arc<Language>>, path: Option<&Path>) -> bool {
if !self.copilot.feature_enabled {
return false;
}
/// Returns whether inline completions are enabled for the given language and path.
pub fn inline_completions_enabled(
&self,
language: Option<&Arc<Language>>,
path: Option<&Path>,
) -> bool {
if let Some(path) = path {
if !self.copilot_enabled_for_path(path) {
if !self.inline_completions_enabled_for_path(path) {
return false;
}
}
self.language(language.map(|l| l.name()).as_deref())
.show_copilot_suggestions
.show_inline_completions
}
}
@ -551,13 +564,13 @@ impl settings::Settings for AllLanguageSettings {
languages.insert(language_name.clone(), language_settings);
}
let mut copilot_enabled = default_value
let mut copilot_enabled = default_value.features.as_ref().and_then(|f| f.copilot);
let mut inline_completion_provider = default_value
.features
.as_ref()
.and_then(|f| f.copilot)
.ok_or_else(Self::missing_default)?;
let mut copilot_globs = default_value
.copilot
.and_then(|f| f.inline_completion_provider);
let mut completion_globs = default_value
.inline_completions
.as_ref()
.and_then(|c| c.disabled_globs.as_ref())
.ok_or_else(Self::missing_default)?;
@ -565,14 +578,21 @@ impl settings::Settings for AllLanguageSettings {
let mut file_types: HashMap<Arc<str>, Vec<String>> = HashMap::default();
for user_settings in sources.customizations() {
if let Some(copilot) = user_settings.features.as_ref().and_then(|f| f.copilot) {
copilot_enabled = copilot;
copilot_enabled = Some(copilot);
}
if let Some(provider) = user_settings
.features
.as_ref()
.and_then(|f| f.inline_completion_provider)
{
inline_completion_provider = Some(provider);
}
if let Some(globs) = user_settings
.copilot
.inline_completions
.as_ref()
.and_then(|f| f.disabled_globs.as_ref())
{
copilot_globs = globs;
completion_globs = globs;
}
// A user's global settings override the default global settings and
@ -601,9 +621,15 @@ impl settings::Settings for AllLanguageSettings {
}
Ok(Self {
copilot: CopilotSettings {
feature_enabled: copilot_enabled,
disabled_globs: copilot_globs
inline_completions: InlineCompletionSettings {
provider: if let Some(provider) = inline_completion_provider {
provider
} else if copilot_enabled.unwrap_or(true) {
InlineCompletionProvider::Copilot
} else {
InlineCompletionProvider::None
},
disabled_globs: completion_globs
.iter()
.filter_map(|g| Some(globset::Glob::new(g).ok()?.compile_matcher()))
.collect(),
@ -714,8 +740,8 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent
);
merge(&mut settings.language_servers, src.language_servers.clone());
merge(
&mut settings.show_copilot_suggestions,
src.show_copilot_suggestions,
&mut settings.show_inline_completions,
src.show_inline_completions,
);
merge(&mut settings.show_whitespaces, src.show_whitespaces);
merge(