-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of #7108 This PR includes just the static runnables part. We went with **not** having a dedicated panel for runnables. This is just a 1st PR out of N, as we want to start exploring the dynamic runnables front. Still, all that work is going to happen once this gets merged. Release Notes: - Added initial, static Runnables support to Zed. Such runnables are defined in `runnables.json` file (accessible via `zed: open runnables` action) and they can be spawned with `runnables: spawn` action. --------- Co-authored-by: Kirill Bulatov <[email protected]> Co-authored-by: Pitor <[email protected]> Co-authored-by: Beniamin <[email protected]>
- Loading branch information
1 parent
ca251ba
commit f17d0b5
Showing
30 changed files
with
1,399 additions
and
280 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Static runnables configuration. | ||
// | ||
// Example: | ||
// { | ||
// "label": "human-readable label for UI", | ||
// "command": "bash", | ||
// // rest of the parameters are optional | ||
// "args": ["-c", "for i in {1..10}; do echo \"Second $i\"; sleep 1; done"], | ||
// // Env overrides for the command, will be appended to the terminal's environment from the settings. | ||
// "env": {"foo": "bar"}, | ||
// // Current working directory to spawn the command into, defaults to current project root. | ||
// "cwd": "/path/to/working/directory", | ||
// // Whether to use a new terminal tab or reuse the existing one to spawn the process, defaults to `false`. | ||
// "use_new_terminal": false, | ||
// // Whether to allow multiple instances of the same runnable to be run, or rather wait for the existing ones to finish, defaults to `false`. | ||
// "allow_concurrent_runs": false, | ||
// }, | ||
// | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//! Project-wide storage of the runnables available, capable of updating itself from the sources set. | ||
use std::{path::Path, sync::Arc}; | ||
|
||
use gpui::{AppContext, Context, Model, ModelContext, Subscription}; | ||
use runnable::{Runnable, RunnableId, Source}; | ||
|
||
/// Inventory tracks available runnables for a given project. | ||
pub struct Inventory { | ||
sources: Vec<SourceInInventory>, | ||
pub last_scheduled_runnable: Option<RunnableId>, | ||
} | ||
|
||
struct SourceInInventory { | ||
source: Model<Box<dyn Source>>, | ||
_subscription: Subscription, | ||
} | ||
|
||
impl Inventory { | ||
pub(crate) fn new(cx: &mut AppContext) -> Model<Self> { | ||
cx.new_model(|_| Self { | ||
sources: Vec::new(), | ||
last_scheduled_runnable: None, | ||
}) | ||
} | ||
|
||
/// Registers a new runnables source, that would be fetched for available runnables. | ||
pub fn add_source(&mut self, source: Model<Box<dyn Source>>, cx: &mut ModelContext<Self>) { | ||
let _subscription = cx.observe(&source, |_, _, cx| { | ||
cx.notify(); | ||
}); | ||
let source = SourceInInventory { | ||
source, | ||
_subscription, | ||
}; | ||
self.sources.push(source); | ||
cx.notify(); | ||
} | ||
|
||
/// Pulls its sources to list runanbles for the path given (up to the source to decide what to return for no path). | ||
pub fn list_runnables( | ||
&self, | ||
path: Option<&Path>, | ||
cx: &mut AppContext, | ||
) -> Vec<Arc<dyn Runnable>> { | ||
let mut runnables = Vec::new(); | ||
for source in &self.sources { | ||
runnables.extend( | ||
source | ||
.source | ||
.update(cx, |source, cx| source.runnables_for_path(path, cx)), | ||
); | ||
} | ||
runnables | ||
} | ||
|
||
/// Returns the last scheduled runnable, if any of the sources contains one with the matching id. | ||
pub fn last_scheduled_runnable(&self, cx: &mut AppContext) -> Option<Arc<dyn Runnable>> { | ||
self.last_scheduled_runnable.as_ref().and_then(|id| { | ||
// TODO straighten the `Path` story to understand what has to be passed here: or it will break in the future. | ||
self.list_runnables(None, cx) | ||
.into_iter() | ||
.find(|runnable| runnable.id() == id) | ||
}) | ||
} | ||
} |
Oops, something went wrong.