Add vim/emacs modeline support (#44210)
Many editors such as vim and emacs support "modelines", a comment at the beginning of the file that allows the file type to be explicitly specified along with per-file specific settings - The amount of configurations, style and settings mapping cannot be handled in one go, so this opens up a lot of potential improvements. - I left out the possiblity to have "zed" specific modelines for now, but this could be potentially interesting. - Mapping the mode or filetype to zed language names isn't obvious either. We may want to make it configurable. This is my first contribution to zed, be kind. I struggled a bit to find the right place to add those settings. I use a similar approach as done with editorconfig (merge_with_editorconfig). There might be better ways. Closes #4762 Release Notes: - Add basic emacs/vim modeline support. Supersedes #41899, changes: - limit reading to the first and last 1kb - add documentation - more variables handled - add Arc around ModelineSettings to avoid extra cloning - changed the way mode -> language mapping is done, thanks to `modeline_aliases` language config - drop vim ex: support - made "Local Variables:" handling a separate commit, so we can drop it easily - various code style improvements --------- Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
1 parent
a1f4329dee
commit
a3174dab48
57 files changed
+1509
-522
No files matched your search
@@ -2,8 +2,8 @@ use futures::channel::oneshot;
|
||||
use git2::{DiffLineType as GitDiffLineType, DiffOptions as GitOptions, Patch as GitPatch};
|
||||
use gpui::{App, AppContext as _, Context, Entity, EventEmitter, Task};
|
||||
use language::{
|
||||
Capability, Diff, DiffOptions, File, Language, LanguageName, LanguageRegistry,
|
||||
language_settings::language_settings, word_diff_ranges,
|
||||
Capability, Diff, DiffOptions, Language, LanguageName, LanguageRegistry,
|
||||
language_settings::LanguageSettings, word_diff_ranges,
|
||||
};
|
||||
use rope::Rope;
|
||||
use std::{cmp::Ordering, future::Future, iter, ops::Range, sync::Arc};
|
||||
@@ -946,7 +946,6 @@ impl BufferDiffInner<language::BufferSnapshot> {
|
||||
}
|
||||
|
||||
fn build_diff_options(
|
||||
file: Option<&Arc<dyn File>>,
|
||||
language: Option<LanguageName>,
|
||||
language_scope: Option<language::LanguageScope>,
|
||||
cx: &App,
|
||||
@@ -962,7 +961,7 @@ fn build_diff_options(
|
||||
}
|
||||
}
|
||||
|
||||
language_settings(language, file, cx)
|
||||
LanguageSettings::resolve(None, language.as_ref(), cx)
|
||||
.word_diff_enabled
|
||||
.then_some(DiffOptions {
|
||||
language_scope,
|
||||
@@ -1494,7 +1493,6 @@ impl BufferDiff {
|
||||
let base_text_changed = base_text_change.is_some();
|
||||
let compute_base_text_edits = base_text_change == Some(true);
|
||||
let diff_options = build_diff_options(
|
||||
None,
|
||||
language.as_ref().map(|l| l.name()),
|
||||
language.as_ref().map(|l| l.default_scope()),
|
||||
cx,
|
||||
|
||||
Reference in new issue
Block a user