Skip to content

Fix: .editorconfig is now reloaded on :config-reload #13443

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ impl Application {
Ok(())
}

/// Refreshes configuration for the editor.
/// Current list of configurations updated:
/// - `config.toml`
/// - `languages.toml`
/// - `.editorconfig`
/// - `{theme}.toml`
fn refresh_config(&mut self) {
let mut refresh_config = || -> Result<(), Error> {
let default_config = Config::load_default()
Expand All @@ -414,6 +420,8 @@ impl Application {
.reconfigure(default_config.editor.clone().into())?;
// Store new config
self.config.store(Arc::new(default_config));
// Runs after updating the config so all documents have access to new values
self.refresh_editor_config()?;
Ok(())
};

Expand All @@ -427,6 +435,15 @@ impl Application {
}
}

/// Force all documents to redetect .editorconfig settings
fn refresh_editor_config(&mut self) -> Result<(), Error> {
for document in self.editor.documents.values_mut() {
document.detect_editor_config();
document.detect_indent_and_line_ending();
}
Ok(())
}

/// Load the theme set in configuration
fn load_configured_theme(editor: &mut Editor, config: &Config) {
let true_color = config.editor.true_color || crate::true_color();
Expand Down
3 changes: 2 additions & 1 deletion helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,8 @@ impl Document {
}
}

pub(crate) fn detect_editor_config(&mut self) {
pub fn detect_editor_config(&mut self) {
self.editor_config = EditorConfig::default();
if self.config.load().editor_config {
if let Some(path) = self.path.as_ref() {
self.editor_config = EditorConfig::find(path);
Expand Down