Support .editorconfig (#19455)

Closes https://github.com/zed-industries/zed/issues/8534
Supersedes https://github.com/zed-industries/zed/pull/16349

Potential concerns:
* we do not follow up to the `/` when looking for `.editorconfig`, only
up to the worktree root.
Seems fine for most of the cases, and the rest should be solved
generically later, as the same issue exists for settings.json
* `fn language` in `AllLanguageSettings` is very hot, called very
frequently during rendering. We accumulate and parse all `.editorconfig`
file contents beforehand, but have to go over globs and match these
against the path given + merge the properties still.
This does not seem to be very bad, but needs more testing and
potentially some extra caching.


Release Notes:

- Added .editorconfig support

---------

Co-authored-by: Ulysse Buonomo <buonomo.ulysse@gmail.com>
This commit is contained in:
Kirill Bulatov 2024-10-21 13:05:30 +03:00 committed by GitHub
parent d95a4f8671
commit d3cb08bf35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 869 additions and 263 deletions

View file

@ -1778,7 +1778,7 @@ impl MultiBuffer {
&self,
point: T,
cx: &'a AppContext,
) -> &'a LanguageSettings {
) -> Cow<'a, LanguageSettings> {
let mut language = None;
let mut file = None;
if let Some((buffer, offset, _)) = self.point_to_buffer_offset(point, cx) {
@ -1786,7 +1786,7 @@ impl MultiBuffer {
language = buffer.language_at(offset);
file = buffer.file();
}
language_settings(language.as_ref(), file, cx)
language_settings(language.map(|l| l.name()), file, cx)
}
pub fn for_each_buffer(&self, mut f: impl FnMut(&Model<Buffer>)) {
@ -3580,14 +3580,14 @@ impl MultiBufferSnapshot {
&'a self,
point: T,
cx: &'a AppContext,
) -> &'a LanguageSettings {
) -> Cow<'a, LanguageSettings> {
let mut language = None;
let mut file = None;
if let Some((buffer, offset)) = self.point_to_buffer_offset(point) {
language = buffer.language_at(offset);
file = buffer.file();
}
language_settings(language, file, cx)
language_settings(language.map(|l| l.name()), file, cx)
}
pub fn language_scope_at<T: ToOffset>(&self, point: T) -> Option<LanguageScope> {