mirror of
https://github.com/zed-industries/zed.git
synced 2026-05-25 23:04:27 +00:00
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>
55 lines
2 KiB
Rust
55 lines
2 KiB
Rust
use std::{ops::Range, path::PathBuf, sync::Arc};
|
|
|
|
use crate::{Buffer, LanguageToolchainStore, Location, Runnable};
|
|
|
|
use anyhow::Result;
|
|
use collections::HashMap;
|
|
use fs::Fs;
|
|
use gpui::{App, Entity, Task};
|
|
use lsp::LanguageServerName;
|
|
use task::{TaskTemplates, TaskVariables};
|
|
use text::BufferId;
|
|
|
|
pub struct RunnableRange {
|
|
pub buffer_id: BufferId,
|
|
pub run_range: Range<usize>,
|
|
pub full_range: Range<usize>,
|
|
pub runnable: Runnable,
|
|
pub extra_captures: HashMap<String, String>,
|
|
}
|
|
|
|
/// Language Contexts are used by Zed tasks to extract information about the source file where the tasks are supposed to be scheduled from.
|
|
/// Multiple context providers may be used together: by default, Zed provides a base [`BasicContextProvider`] context that fills all non-custom [`VariableName`] variants.
|
|
///
|
|
/// The context will be used to fill data for the tasks, and filter out the ones that do not have the variables required.
|
|
pub trait ContextProvider: Send + Sync {
|
|
/// Builds a specific context to be placed on top of the basic one (replacing all conflicting entries) and to be used for task resolving later.
|
|
fn build_context(
|
|
&self,
|
|
_variables: &TaskVariables,
|
|
_location: ContextLocation<'_>,
|
|
_project_env: Option<HashMap<String, String>>,
|
|
_toolchains: Arc<dyn LanguageToolchainStore>,
|
|
_cx: &mut App,
|
|
) -> Task<Result<TaskVariables>> {
|
|
let _ = _location;
|
|
Task::ready(Ok(TaskVariables::default()))
|
|
}
|
|
|
|
/// Provides all tasks, associated with the current language.
|
|
fn associated_tasks(&self, _: Option<Entity<Buffer>>, _: &App) -> Task<Option<TaskTemplates>> {
|
|
Task::ready(None)
|
|
}
|
|
|
|
/// A language server name, that can return tasks using LSP (ext) for this language.
|
|
fn lsp_task_source(&self) -> Option<LanguageServerName> {
|
|
None
|
|
}
|
|
}
|
|
|
|
/// Metadata about the place in the project we gather the context for.
|
|
pub struct ContextLocation<'a> {
|
|
pub fs: Option<Arc<dyn Fs>>,
|
|
pub worktree_root: Option<PathBuf>,
|
|
pub file_location: &'a Location,
|
|
}
|