Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add editorconfig support #16349

Closed
wants to merge 12 commits into from
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ ctor = "0.2.6"
dashmap = "6.0"
derive_more = "0.99.17"
dirs = "4.0"
ec4rs = "1.1"
emojis = "0.6.1"
env_logger = "0.11"
exec = "0.3.1"
Expand Down
6 changes: 2 additions & 4 deletions crates/assistant/src/assistant_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ use gpui::{
Transformation, UpdateGlobal, View, VisualContext, WeakView, WindowContext,
};
use indexed_docs::IndexedDocsStore;
use language::{
language_settings::SoftWrap, Capability, LanguageRegistry, LspAdapterDelegate, Point, ToOffset,
};
use language::{Capability, LanguageRegistry, LspAdapterDelegate, Point, ToOffset};
use language_model::{
provider::cloud::PROVIDER_ID, LanguageModelProvider, LanguageModelProviderId,
LanguageModelRegistry, Role,
Expand All @@ -58,7 +56,7 @@ use project::lsp_store::LocalLspAdapterDelegate;
use project::{Project, Worktree};
use search::{buffer_search::DivRegistrar, BufferSearchBar};
use serde::{Deserialize, Serialize};
use settings::{update_settings_file, Settings};
use settings::{update_settings_file, Settings, SoftWrap};
use smol::stream::StreamExt;
use std::{
borrow::Cow,
Expand Down
6 changes: 3 additions & 3 deletions crates/assistant/src/inline_assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ impl InlineAssistant {

enum DeletedLines {}
let mut editor = Editor::for_multibuffer(multi_buffer, None, true, cx);
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::None, cx);
editor.set_soft_wrap_mode(settings::SoftWrap::None, cx);
editor.set_show_wrap_guides(false, cx);
editor.set_show_gutter(false, cx);
editor.scroll_manager.set_forbid_vertical_scroll(true);
Expand Down Expand Up @@ -1616,7 +1616,7 @@ impl PromptEditor {
false,
cx,
);
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx);
editor.set_soft_wrap_mode(settings::SoftWrap::EditorWidth, cx);
// Since the prompt editors for all inline assistants are linked,
// always show the cursor (even when it isn't focused) because
// typing in one will make what you typed appear in all of them.
Expand Down Expand Up @@ -1677,7 +1677,7 @@ impl PromptEditor {
let focus = self.editor.focus_handle(cx).contains_focused(cx);
self.editor = cx.new_view(|cx| {
let mut editor = Editor::auto_height(Self::MAX_LINES as usize, cx);
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx);
editor.set_soft_wrap_mode(settings::SoftWrap::EditorWidth, cx);
editor.set_placeholder_text("Add a prompt…", cx);
editor.set_text(prompt, cx);
if focus {
Expand Down
4 changes: 2 additions & 2 deletions crates/assistant/src/prompt_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use heed::{
types::{SerdeBincode, SerdeJson, Str},
Database, RoTxn,
};
use language::{language_settings::SoftWrap, Buffer, LanguageRegistry};
use language::{Buffer, LanguageRegistry};
use language_model::{
LanguageModelRegistry, LanguageModelRequest, LanguageModelRequestMessage, Role,
};
Expand All @@ -26,7 +26,7 @@ use picker::{Picker, PickerDelegate};
use release_channel::ReleaseChannel;
use rope::Rope;
use serde::{Deserialize, Serialize};
use settings::Settings;
use settings::{Settings, SoftWrap};
use std::{
cmp::Reverse,
future::Future,
Expand Down
2 changes: 1 addition & 1 deletion crates/assistant/src/terminal_inline_assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ impl PromptEditor {
false,
cx,
);
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx);
editor.set_soft_wrap_mode(settings::SoftWrap::EditorWidth, cx);
editor.set_placeholder_text("Add a prompt…", cx);
editor
});
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async fn test_sharing_an_ssh_remote_project(
let file = buffer_b.read(cx).file();
assert_eq!(
all_language_settings(file, cx)
.language(Some(&("Rust".into())))
.language(None, Some(&("Rust".into())), cx)
.language_servers,
["override-rust-analyzer".into()]
)
Expand Down
5 changes: 2 additions & 3 deletions crates/collab_ui/src/chat_panel/message_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ use gpui::{
Render, Task, TextStyle, View, ViewContext, WeakView,
};
use language::{
language_settings::SoftWrap, Anchor, Buffer, BufferSnapshot, CodeLabel, LanguageRegistry,
LanguageServerId, ToOffset,
Anchor, Buffer, BufferSnapshot, CodeLabel, LanguageRegistry, LanguageServerId, ToOffset,
};
use parking_lot::RwLock;
use project::{search::SearchQuery, Completion};
use settings::Settings;
use settings::{Settings, SoftWrap};
use std::{ops::Range, sync::Arc, sync::LazyLock, time::Duration};
use theme::ThemeSettings;
use ui::{prelude::*, TextSize};
Expand Down
6 changes: 5 additions & 1 deletion crates/copilot/src/copilot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,11 @@ mod tests {
unimplemented!()
}

fn file_name<'a>(&'a self, _: &'a AppContext) -> &'a std::ffi::OsStr {
fn file_name(&self, _: &AppContext) -> &std::ffi::OsStr {
unimplemented!()
}

fn abs_path_in_worktree(&self, _: &AppContext) -> Result<PathBuf> {
unimplemented!()
}

Expand Down
4 changes: 2 additions & 2 deletions crates/copilot/src/copilot_completion_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl InlineCompletionProvider for CopilotCompletionProvider {
let file = buffer.file();
let language = buffer.language_at(cursor_position);
let settings = all_language_settings(file, cx);
settings.inline_completions_enabled(language.as_ref(), file.map(|f| f.path().as_ref()))
settings.inline_completions_enabled(language.as_ref(), file, cx)
}

fn refresh(
Expand Down Expand Up @@ -209,7 +209,7 @@ impl InlineCompletionProvider for CopilotCompletionProvider {
) {
let settings = AllLanguageSettings::get_global(cx);

let copilot_enabled = settings.inline_completions_enabled(None, None);
let copilot_enabled = settings.inline_completions_enabled(None, None, cx);

if !copilot_enabled {
return;
Expand Down
38 changes: 18 additions & 20 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub use inline_completion_provider::*;
pub use items::MAX_TAB_TITLE_LEN;
use itertools::Itertools;
use language::{
language_settings::{self, all_language_settings, InlayHintSettings},
language_settings::{all_language_settings, InlayHintSettings},
markdown, point_from_lsp, AutoindentMode, BracketPair, Buffer, Capability, CharKind, CodeLabel,
CursorShape, Diagnostic, Documentation, IndentKind, IndentSize, Language, OffsetRangeExt,
Point, Selection, SelectionGoal, TransactionId,
Expand Down Expand Up @@ -414,7 +414,7 @@ impl Default for EditorStyle {

pub fn make_inlay_hints_style(cx: &WindowContext) -> HighlightStyle {
let show_background = all_language_settings(None, cx)
.language(None)
.language(None, None, cx)
.inlay_hints
.show_background;

Expand Down Expand Up @@ -531,7 +531,7 @@ pub struct Editor {
select_larger_syntax_node_stack: Vec<Box<[Selection<usize>]>>,
ime_transaction: Option<TransactionId>,
active_diagnostics: Option<ActiveDiagnosticGroup>,
soft_wrap_mode_override: Option<language_settings::SoftWrap>,
soft_wrap_mode_override: Option<settings::SoftWrap>,
project: Option<Model<Project>>,
completion_provider: Option<Box<dyn CompletionProvider>>,
collaboration_hub: Option<Box<dyn CollaborationHub>>,
Expand Down Expand Up @@ -1804,8 +1804,8 @@ impl Editor {

let blink_manager = cx.new_model(|cx| BlinkManager::new(CURSOR_BLINK_INTERVAL, cx));

let soft_wrap_mode_override = matches!(mode, EditorMode::SingleLine { .. })
.then(|| language_settings::SoftWrap::PreferLine);
let soft_wrap_mode_override =
matches!(mode, EditorMode::SingleLine { .. }).then(|| settings::SoftWrap::PreferLine);

let mut project_subscriptions = Vec::new();
if mode == EditorMode::Full {
Expand Down Expand Up @@ -10784,23 +10784,17 @@ impl Editor {
let settings = self.buffer.read(cx).settings_at(0, cx);
let mode = self.soft_wrap_mode_override.unwrap_or(settings.soft_wrap);
match mode {
language_settings::SoftWrap::None => SoftWrap::None,
language_settings::SoftWrap::PreferLine => SoftWrap::PreferLine,
language_settings::SoftWrap::EditorWidth => SoftWrap::EditorWidth,
language_settings::SoftWrap::PreferredLineLength => {
settings::SoftWrap::None => SoftWrap::None,
settings::SoftWrap::PreferLine => SoftWrap::PreferLine,
settings::SoftWrap::EditorWidth => SoftWrap::EditorWidth,
settings::SoftWrap::PreferredLineLength => {
SoftWrap::Column(settings.preferred_line_length)
}
language_settings::SoftWrap::Bounded => {
SoftWrap::Bounded(settings.preferred_line_length)
}
settings::SoftWrap::Bounded => SoftWrap::Bounded(settings.preferred_line_length),
}
}

pub fn set_soft_wrap_mode(
&mut self,
mode: language_settings::SoftWrap,
cx: &mut ViewContext<Self>,
) {
pub fn set_soft_wrap_mode(&mut self, mode: settings::SoftWrap, cx: &mut ViewContext<Self>) {
self.soft_wrap_mode_override = Some(mode);
cx.notify();
}
Expand Down Expand Up @@ -10833,9 +10827,9 @@ impl Editor {
self.soft_wrap_mode_override.take();
} else {
let soft_wrap = match self.soft_wrap_mode(cx) {
SoftWrap::None | SoftWrap::PreferLine => language_settings::SoftWrap::EditorWidth,
SoftWrap::None | SoftWrap::PreferLine => settings::SoftWrap::EditorWidth,
SoftWrap::EditorWidth | SoftWrap::Column(_) | SoftWrap::Bounded(_) => {
language_settings::SoftWrap::PreferLine
settings::SoftWrap::PreferLine
}
};
self.soft_wrap_mode_override = Some(soft_wrap);
Expand Down Expand Up @@ -12679,7 +12673,11 @@ fn inlay_hint_settings(
let language = snapshot.language_at(location);
let settings = all_language_settings(file, cx);
settings
.language(language.map(|l| l.name()).as_ref())
.language(
file.and_then(|file| Some((file.worktree_id(cx), file.abs_path_in_worktree(cx).ok()?))),
language.map(|l| l.name()).as_ref(),
cx,
)
.inlay_hints
}

Expand Down
4 changes: 2 additions & 2 deletions crates/editor/src/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ use gpui::{
use indoc::indoc;
use language::{
language_settings::{
AllLanguageSettings, AllLanguageSettingsContent, LanguageSettingsContent, PrettierSettings,
self, AllLanguageSettings, AllLanguageSettingsContent, Formatter, FormatterList,
IndentGuideSettings, LanguageSettingsContent, PrettierSettings,
},
BracketPairConfig,
Capability::ReadWrite,
FakeLspAdapter, IndentGuide, LanguageConfig, LanguageConfigOverride, LanguageMatcher,
LanguageName, Override, ParsedMarkdown, Point,
};
use language_settings::{Formatter, FormatterList, IndentGuideSettings};
use multi_buffer::MultiBufferIndentGuide;
use parking_lot::Mutex;
use project::FakeFs;
Expand Down
5 changes: 2 additions & 3 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6329,7 +6329,6 @@ mod tests {
Editor, MultiBuffer,
};
use gpui::{TestAppContext, VisualTestContext};
use language::language_settings;
use log::info;
use std::num::NonZeroU32;
use ui::Context;
Expand Down Expand Up @@ -6730,7 +6729,7 @@ mod tests {
s.defaults.tab_size = NonZeroU32::new(tab_size);
s.defaults.show_whitespaces = Some(ShowWhitespaceSetting::All);
s.defaults.preferred_line_length = Some(editor_width as u32);
s.defaults.soft_wrap = Some(language_settings::SoftWrap::PreferredLineLength);
s.defaults.soft_wrap = Some(settings::SoftWrap::PreferredLineLength);
});

let actual_invisibles = collect_invisibles_from_new_editor(
Expand Down Expand Up @@ -6785,7 +6784,7 @@ mod tests {
let style = cx.update(|cx| editor.read(cx).style().unwrap().clone());
window
.update(cx, |editor, cx| {
editor.set_soft_wrap_mode(language_settings::SoftWrap::EditorWidth, cx);
editor.set_soft_wrap_mode(settings::SoftWrap::EditorWidth, cx);
editor.set_wrap_width(Some(editor_width), cx);
})
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/hunk_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ fn editor_with_deleted_text(
});

let mut editor = Editor::for_multibuffer(multi_buffer, None, true, cx);
editor.set_soft_wrap_mode(language::language_settings::SoftWrap::None, cx);
editor.set_soft_wrap_mode(settings::SoftWrap::None, cx);
editor.set_show_wrap_guides(false, cx);
editor.set_show_gutter(false, cx);
editor.scroll_manager.set_forbid_vertical_scroll(true);
Expand Down
8 changes: 6 additions & 2 deletions crates/extension/src/wasm_host/wit/since_v0_1_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,12 @@ impl ExtensionImports for WasmState {
cx.update(|cx| match category.as_str() {
"language" => {
let key = key.map(|k| LanguageName::new(&k));
let settings =
AllLanguageSettings::get(location, cx).language(key.as_ref());
let settings = AllLanguageSettings::get(location, cx).language(
location
.map(|location| (location.worktree_id, location.path.to_owned())),
key.as_ref(),
cx,
);
Ok(serde_json::to_string(&settings::LanguageSettings {
tab_size: settings.tab_size,
})?)
Expand Down
3 changes: 2 additions & 1 deletion crates/extension/src/wasm_host/wit/since_v0_2_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ impl ExtensionImports for WasmState {
"language" => {
let key = key.map(|k| LanguageName::new(&k));
let settings =
AllLanguageSettings::get(location, cx).language(key.as_ref());
// TODO kb use `location` instead of `None`
AllLanguageSettings::get(location, cx).language(None, key.as_ref(), cx);
Ok(serde_json::to_string(&settings::LanguageSettings {
tab_size: settings.tab_size,
})?)
Expand Down
14 changes: 6 additions & 8 deletions crates/inline_completion_button/src/inline_completion_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Render for InlineCompletionButton {
let status = copilot.read(cx).status();

let enabled = self.editor_enabled.unwrap_or_else(|| {
all_language_settings.inline_completions_enabled(None, None)
all_language_settings.inline_completions_enabled(None, None, cx)
});

let icon = match status {
Expand Down Expand Up @@ -292,7 +292,7 @@ impl InlineCompletionButton {
);
}

let globally_enabled = settings.inline_completions_enabled(None, None);
let globally_enabled = settings.inline_completions_enabled(None, None, cx);
menu.entry(
if globally_enabled {
"Hide Inline Completions for All Files"
Expand Down Expand Up @@ -337,10 +337,8 @@ impl InlineCompletionButton {
let file = file.as_ref();
Some(
file.map(|file| !file.is_private()).unwrap_or(true)
&& all_language_settings(file, cx).inline_completions_enabled(
language,
file.map(|file| file.path().as_ref()),
),
&& all_language_settings(file, cx)
.inline_completions_enabled(language, file, cx),
)
};
self.language = language.cloned();
Expand Down Expand Up @@ -442,7 +440,7 @@ async fn configure_disabled_globs(

fn toggle_inline_completions_globally(fs: Arc<dyn Fs>, cx: &mut AppContext) {
let show_inline_completions =
all_language_settings(None, cx).inline_completions_enabled(None, None);
all_language_settings(None, cx).inline_completions_enabled(None, None, cx);
update_settings_file::<AllLanguageSettings>(fs, cx, move |file, _| {
file.defaults.show_inline_completions = Some(!show_inline_completions)
});
Expand All @@ -466,7 +464,7 @@ fn toggle_inline_completions_for_language(
cx: &mut AppContext,
) {
let show_inline_completions =
all_language_settings(None, cx).inline_completions_enabled(Some(&language), None);
all_language_settings(None, cx).inline_completions_enabled(Some(&language), None, cx);
update_settings_file::<AllLanguageSettings>(fs, cx, move |file, _| {
file.languages
.entry(language.name())
Expand Down
Loading
Loading