|
|
@ -173,7 +173,7 @@ macro_rules! static_commands {
|
|
|
|
impl MappableCommand {
|
|
|
|
impl MappableCommand {
|
|
|
|
pub fn execute(&self, cx: &mut Context) {
|
|
|
|
pub fn execute(&self, cx: &mut Context) {
|
|
|
|
match &self {
|
|
|
|
match &self {
|
|
|
|
MappableCommand::Typable { name, args, doc: _ } => {
|
|
|
|
Self::Typable { name, args, doc: _ } => {
|
|
|
|
let args: Vec<Cow<str>> = args.iter().map(Cow::from).collect();
|
|
|
|
let args: Vec<Cow<str>> = args.iter().map(Cow::from).collect();
|
|
|
|
if let Some(command) = cmd::TYPABLE_COMMAND_MAP.get(name.as_str()) {
|
|
|
|
if let Some(command) = cmd::TYPABLE_COMMAND_MAP.get(name.as_str()) {
|
|
|
|
let mut cx = compositor::Context {
|
|
|
|
let mut cx = compositor::Context {
|
|
|
@ -186,21 +186,21 @@ impl MappableCommand {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MappableCommand::Static { fun, .. } => (fun)(cx),
|
|
|
|
Self::Static { fun, .. } => (fun)(cx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn name(&self) -> &str {
|
|
|
|
pub fn name(&self) -> &str {
|
|
|
|
match &self {
|
|
|
|
match &self {
|
|
|
|
MappableCommand::Typable { name, .. } => name,
|
|
|
|
Self::Typable { name, .. } => name,
|
|
|
|
MappableCommand::Static { name, .. } => name,
|
|
|
|
Self::Static { name, .. } => name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn doc(&self) -> &str {
|
|
|
|
pub fn doc(&self) -> &str {
|
|
|
|
match &self {
|
|
|
|
match &self {
|
|
|
|
MappableCommand::Typable { doc, .. } => doc,
|
|
|
|
Self::Typable { doc, .. } => doc,
|
|
|
|
MappableCommand::Static { doc, .. } => doc,
|
|
|
|
Self::Static { doc, .. } => doc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -3494,11 +3494,9 @@ pub fn apply_document_resource_op(op: &lsp::ResourceOp) -> std::io::Result<()> {
|
|
|
|
match op {
|
|
|
|
match op {
|
|
|
|
ResourceOp::Create(op) => {
|
|
|
|
ResourceOp::Create(op) => {
|
|
|
|
let path = op.uri.to_file_path().unwrap();
|
|
|
|
let path = op.uri.to_file_path().unwrap();
|
|
|
|
let ignore_if_exists = if let Some(options) = &op.options {
|
|
|
|
let ignore_if_exists = op.options.as_ref().map_or(false, |options| {
|
|
|
|
!options.overwrite.unwrap_or(false) && options.ignore_if_exists.unwrap_or(false)
|
|
|
|
!options.overwrite.unwrap_or(false) && options.ignore_if_exists.unwrap_or(false)
|
|
|
|
} else {
|
|
|
|
});
|
|
|
|
false
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if ignore_if_exists && path.exists() {
|
|
|
|
if ignore_if_exists && path.exists() {
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -3508,11 +3506,12 @@ pub fn apply_document_resource_op(op: &lsp::ResourceOp) -> std::io::Result<()> {
|
|
|
|
ResourceOp::Delete(op) => {
|
|
|
|
ResourceOp::Delete(op) => {
|
|
|
|
let path = op.uri.to_file_path().unwrap();
|
|
|
|
let path = op.uri.to_file_path().unwrap();
|
|
|
|
if path.is_dir() {
|
|
|
|
if path.is_dir() {
|
|
|
|
let recursive = if let Some(options) = &op.options {
|
|
|
|
let recursive = op
|
|
|
|
options.recursive.unwrap_or(false)
|
|
|
|
.options
|
|
|
|
} else {
|
|
|
|
.as_ref()
|
|
|
|
false
|
|
|
|
.and_then(|options| options.recursive)
|
|
|
|
};
|
|
|
|
.unwrap_or(false);
|
|
|
|
|
|
|
|
|
|
|
|
if recursive {
|
|
|
|
if recursive {
|
|
|
|
fs::remove_dir_all(&path)
|
|
|
|
fs::remove_dir_all(&path)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -3527,11 +3526,9 @@ pub fn apply_document_resource_op(op: &lsp::ResourceOp) -> std::io::Result<()> {
|
|
|
|
ResourceOp::Rename(op) => {
|
|
|
|
ResourceOp::Rename(op) => {
|
|
|
|
let from = op.old_uri.to_file_path().unwrap();
|
|
|
|
let from = op.old_uri.to_file_path().unwrap();
|
|
|
|
let to = op.new_uri.to_file_path().unwrap();
|
|
|
|
let to = op.new_uri.to_file_path().unwrap();
|
|
|
|
let ignore_if_exists = if let Some(options) = &op.options {
|
|
|
|
let ignore_if_exists = op.options.as_ref().map_or(false, |options| {
|
|
|
|
!options.overwrite.unwrap_or(false) && options.ignore_if_exists.unwrap_or(false)
|
|
|
|
!options.overwrite.unwrap_or(false) && options.ignore_if_exists.unwrap_or(false)
|
|
|
|
} else {
|
|
|
|
});
|
|
|
|
false
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if ignore_if_exists && to.exists() {
|
|
|
|
if ignore_if_exists && to.exists() {
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|