From adeb0e552a2e9ec1e48075d9f604e1a155cc7542 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 27 May 2024 11:38:59 +0200 Subject: [PATCH 1/2] json: Register tasks on Rust side and not via tasks.json --- crates/languages/src/json.rs | 22 ++++++++++++++++++++++ crates/languages/src/json/tasks.json | 14 -------------- crates/languages/src/lib.rs | 4 +++- 3 files changed, 25 insertions(+), 15 deletions(-) delete mode 100644 crates/languages/src/json/tasks.json diff --git a/crates/languages/src/json.rs b/crates/languages/src/json.rs index 442f0afff1738..b3d8e8d4b83f2 100644 --- a/crates/languages/src/json.rs +++ b/crates/languages/src/json.rs @@ -20,6 +20,28 @@ use util::{maybe, paths, ResultExt}; const SERVER_PATH: &str = "node_modules/vscode-json-languageserver/bin/vscode-json-languageserver"; +use project::ContextProviderWithTasks; +use task::{TaskTemplate, TaskTemplates, VariableName}; + +pub(super) fn json_task_context() -> ContextProviderWithTasks { + ContextProviderWithTasks::new(TaskTemplates(vec![ + TaskTemplate { + label: "package script $ZED_CUSTOM_script".to_owned(), + command: "npm run".to_owned(), + args: vec![VariableName::Custom("script".into()).template_value()], + tags: vec!["package-script".into()], + ..TaskTemplate::default() + }, + TaskTemplate { + label: "composer script $ZED_CUSTOM_script".to_owned(), + command: "composer".to_owned(), + args: vec![VariableName::Custom("script".into()).template_value()], + tags: vec!["composer-script".into()], + ..TaskTemplate::default() + }, + ])) +} + fn server_binary_arguments(server_path: &Path) -> Vec { vec![server_path.into(), "--stdio".into()] } diff --git a/crates/languages/src/json/tasks.json b/crates/languages/src/json/tasks.json deleted file mode 100644 index 07bb0a9f0ada2..0000000000000 --- a/crates/languages/src/json/tasks.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "label": "package script $ZED_CUSTOM_script", - "command": "npm run", - "args": ["$ZED_CUSTOM_script"], - "tags": ["package-script"] - }, - { - "label": "composer script $ZED_CUSTOM_script", - "command": "composer", - "args": ["$ZED_CUSTOM_script"], - "tags": ["composer-script"] - } -] diff --git a/crates/languages/src/lib.rs b/crates/languages/src/lib.rs index ec7a0d38891ba..ae51e880ecc2c 100644 --- a/crates/languages/src/lib.rs +++ b/crates/languages/src/lib.rs @@ -1,5 +1,6 @@ use anyhow::Context; use gpui::{AppContext, UpdateGlobal}; +use json::json_task_context; pub use language::*; use node_runtime::NodeRuntime; use rust_embed::RustEmbed; @@ -119,7 +120,8 @@ pub fn init( vec![Arc::new(json::JsonLspAdapter::new( node_runtime.clone(), languages.clone(), - ))] + ))], + json_task_context() ); language!("markdown"); language!( From 1bba71cb1e0779c693c903d48927249715ae50ee Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 27 May 2024 11:39:55 +0200 Subject: [PATCH 2/2] Sort imports --- crates/languages/src/json.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/languages/src/json.rs b/crates/languages/src/json.rs index b3d8e8d4b83f2..74a249f915e4f 100644 --- a/crates/languages/src/json.rs +++ b/crates/languages/src/json.rs @@ -7,6 +7,7 @@ use gpui::{AppContext, AsyncAppContext}; use language::{LanguageRegistry, LanguageServerName, LspAdapter, LspAdapterDelegate}; use lsp::LanguageServerBinary; use node_runtime::NodeRuntime; +use project::ContextProviderWithTasks; use serde_json::{json, Value}; use settings::{KeymapFile, SettingsJsonSchemaParams, SettingsStore}; use smol::fs; @@ -16,13 +17,11 @@ use std::{ path::{Path, PathBuf}, sync::{Arc, OnceLock}, }; +use task::{TaskTemplate, TaskTemplates, VariableName}; use util::{maybe, paths, ResultExt}; const SERVER_PATH: &str = "node_modules/vscode-json-languageserver/bin/vscode-json-languageserver"; -use project::ContextProviderWithTasks; -use task::{TaskTemplate, TaskTemplates, VariableName}; - pub(super) fn json_task_context() -> ContextProviderWithTasks { ContextProviderWithTasks::new(TaskTemplates(vec![ TaskTemplate {