Skip to content
Closed
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
11 changes: 11 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 @@ -662,6 +662,7 @@ tower-http = "0.4.4"
tree-sitter = { version = "0.25.6", features = ["wasm"] }
tree-sitter-bash = "0.25.0"
tree-sitter-c = "0.23"
tree-sitter-comment = "0.3"
tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "5cb9b693cfd7bfacab1d9ff4acac1a4150700609" }
tree-sitter-css = "0.23"
tree-sitter-diff = "0.1.0"
Expand Down
45 changes: 45 additions & 0 deletions assets/settings/initial_tagged_comment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// If your current theme does not define the used styles, you need to change the style
// or define custom styles in your Zed settings.
[
{
// Tag names to be recognized.
"tags": ["INFO", "NOTE"],

// Optional style used for the whole comment.
// If not set, the default comment style is used.
// If set to a style Zed can't match, no styling is used.
// "style": "comment",

// Optional style used for the tag name.
// If not set, the style set in `style` is used.
// If set to a style Zed can't match, no styling is used.
"tag_name_style": "comment.note.name",

// Style to be used for the tag user.
// "tag_user_style": "constant",

// Tagged comments may optionally be included in outline views.
// "name" - show only the tag name (e.g. "TODO").
// "user" - show tag name and user.
// "comment" - show the first line of the comment trailed by the tag name.
"outline": "comment"
},
{
"tags": ["TODO"],
"tag_name_style": "comment.todo.name",
"outline": "comment"
},
{
"tags": ["WARN", "WARNING"],
// Define a style for the whole comment, including the text.
"style": "comment.warning",
"tag_name_style": "comment.warning.name",
"outline": "comment"
},
{
"tags": ["BUG", "FIXME"],
"style": "comment.error",
"tag_name_style": "comment.error.name",
"outline": "comment"
}
]
80 changes: 80 additions & 0 deletions assets/themes/one/one.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,46 @@
"color": "#878e98ff",
"font_style": null,
"font_weight": null
},
"comment.note": {
"color": "#6060ff",
"font_style": null,
"font_weight": null
},
"comment.note.name": {
"color": "#6060ff",
"font_style": null,
"font_weight": 700
},
"comment.todo": {
"color": "#00a0aa",
"font_style": null,
"font_weight": null
},
"comment.todo.name": {
"color": "#00a0aa",
"font_style": null,
"font_weight": 700
},
"comment.warning": {
"color": "#ccaa00",
"font_style": null,
"font_weight": null
},
"comment.warning.name": {
"color": "#ccaa00",
"font_style": null,
"font_weight": 700
},
"comment.error": {
"color": "#dd0000",
"font_style": null,
"font_weight": null
},
"comment.error.name": {
"color": "#dd0000",
"font_style": null,
"font_weight": 700
},
"constant": {
"color": "#dfc184ff",
Expand Down Expand Up @@ -605,6 +645,46 @@
"font_style": null,
"font_weight": null
},
"comment.note": {
"color": "#6060ff",
"font_style": null,
"font_weight": null
},
"comment.note.name": {
"color": "#6060ff",
"font_style": null,
"font_weight": 700
},
"comment.todo": {
"color": "#00a0aa",
"font_style": null,
"font_weight": null
},
"comment.todo.name": {
"color": "#00a0aa",
"font_style": null,
"font_weight": 700
},
"comment.warning": {
"color": "#ccaa00",
"font_style": null,
"font_weight": null
},
"comment.warning.name": {
"color": "#ccaa00",
"font_style": null,
"font_weight": 700
},
"comment.error": {
"color": "#dd0000",
"font_style": null,
"font_weight": null
},
"comment.error.name": {
"color": "#dd0000",
"font_style": null,
"font_weight": 700
},
"constant": {
"color": "#c18401ff",
"font_style": null,
Expand Down
16 changes: 15 additions & 1 deletion crates/extension_host/src/extension_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use gpui::{
use http_client::{AsyncBody, HttpClient, HttpClientWithUrl};
use language::{
LanguageConfig, LanguageMatcher, LanguageName, LanguageQueries, LoadedLanguage,
QUERY_FILENAME_PREFIXES, Rope,
QUERY_FILENAME_PREFIXES, Rope, UpdateInjections,
};
use node_runtime::NodeRuntime;
use project::ContextProviderWithTasks;
Expand Down Expand Up @@ -1836,5 +1836,19 @@ fn load_plugin_queries(root_path: &Path) -> LanguageQueries {
}
}
}
LanguageExtension::update_injections_with_path(root_path, &mut result);
result
}

// Helper to enable updating injections queries based on user configuration.
struct LanguageExtension;

impl LanguageExtension {
fn update_injections_with_path(path: &Path, queries: &mut LanguageQueries) {
if let Some(language) = path.file_name().and_then(std::ffi::OsStr::to_str) {
Self::update_injections(&paths::injections_dir(), language, queries)
}
}
}

impl UpdateInjections for LanguageExtension {}
35 changes: 35 additions & 0 deletions crates/language/src/injections.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Update injections based on user configuration.
//!
//! Users may create configuration files containing injection queries for specific languages.
//! When one of these languages is loaded by Zed, the corresponding file is read and contained
//! queries are added to the language's predefined injection queries.
//!
//! Additional injection queries may be configured both for languages from Zed extensions and
//! languages built into Zed.

use {super::LanguageQueries, std::path::Path};

/// Support updating injections queries based on user configuration.
pub trait UpdateInjections {
/// Updates injections queries for a single language.
fn update_injections(dir: &Path, language: &str, queries: &mut LanguageQueries) {
let mut path = dir.join(language);
path.set_extension("scm");
match std::fs::read_to_string(&path) {
Ok(configured) => match queries.injections.as_mut() {
None => queries.injections = Some(configured.into()),
Some(injections) => {
injections.to_mut().push_str(&configured);
}
},
Err(error) => {
if error.kind() != std::io::ErrorKind::NotFound {
log::error!(
"failed to read injection queries from \"{}\": {error}",
path.display()
);
}
}
}
}
}
2 changes: 2 additions & 0 deletions crates/language/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
mod buffer;
mod diagnostic_set;
mod highlight_map;
mod injections;
mod language_registry;
pub mod language_settings;
mod manifest;
Expand Down Expand Up @@ -72,6 +73,7 @@ pub use toolchain::{
use tree_sitter::{self, Query, QueryCursor, WasmStore, wasmtime};
use util::serde::default_true;

pub use self::injections::UpdateInjections;
pub use buffer::Operation;
pub use buffer::*;
pub use diagnostic_set::{DiagnosticEntry, DiagnosticGroup};
Expand Down
2 changes: 2 additions & 0 deletions crates/languages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ load-grammars = [
"tree-sitter",
"tree-sitter-bash",
"tree-sitter-c",
"tree-sitter-comment",
"tree-sitter-cpp",
"tree-sitter-css",
"tree-sitter-diff",
Expand Down Expand Up @@ -77,6 +78,7 @@ toml.workspace = true
tree-sitter = { workspace = true, optional = true }
tree-sitter-bash = { workspace = true, optional = true }
tree-sitter-c = { workspace = true, optional = true }
tree-sitter-comment = { workspace = true, optional = true }
tree-sitter-cpp = { workspace = true, optional = true }
tree-sitter-css = { workspace = true, optional = true }
tree-sitter-diff = { workspace = true, optional = true }
Expand Down
1 change: 1 addition & 0 deletions crates/languages/src/bash/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
((comment) @injection.content (#set! injection.language "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/c/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
(preproc_function_def
value: (preproc_arg) @injection.content
(#set! injection.language "c"))

((comment) @injection.content (#set! injection.language "comment"))
Loading