sway_lsp/capabilities/
runnable.rsuse lsp_types::{Command, Range};
use serde_json::{json, Value};
use sway_core::language::parsed::TreeType;
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct RunnableMainFn {
pub range: Range,
pub tree_type: TreeType,
}
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct RunnableTestFn {
pub range: Range,
pub tree_type: TreeType,
pub test_name: Option<String>,
}
pub trait Runnable: core::fmt::Debug + Send + Sync + 'static {
fn command(&self) -> Command {
Command {
command: self.cmd_string(),
title: self.label_string(),
arguments: self.arguments(),
}
}
fn cmd_string(&self) -> String;
fn label_string(&self) -> String;
fn arguments(&self) -> Option<Vec<Value>>;
fn range(&self) -> &Range;
}
impl Runnable for RunnableMainFn {
fn cmd_string(&self) -> String {
"sway.runScript".to_string()
}
fn label_string(&self) -> String {
"▶\u{fe0e} Run".to_string()
}
fn arguments(&self) -> Option<Vec<Value>> {
None
}
fn range(&self) -> &Range {
&self.range
}
}
impl Runnable for RunnableTestFn {
fn cmd_string(&self) -> String {
"sway.runTests".to_string()
}
fn label_string(&self) -> String {
"▶\u{fe0e} Run Test".to_string()
}
fn arguments(&self) -> Option<Vec<Value>> {
self.test_name
.as_ref()
.map(|test_name| vec![json!({ "name": test_name })])
}
fn range(&self) -> &Range {
&self.range
}
}