mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor: use once_cell
instead of lazy_static
(#13135)
This commit is contained in:
parent
3db18bf9e6
commit
6de53b631f
27 changed files with 434 additions and 313 deletions
|
@ -7,6 +7,7 @@ use deno_core::serde::Deserialize;
|
|||
use deno_core::serde::Serialize;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use lspower::lsp;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
pub struct RefactorCodeActionKind {
|
||||
pub kind: lsp::CodeActionKind,
|
||||
|
@ -19,58 +20,120 @@ impl RefactorCodeActionKind {
|
|||
}
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref EXTRACT_FUNCTION: RefactorCodeActionKind = RefactorCodeActionKind {
|
||||
kind : [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "function"].join(".").into(),
|
||||
pub static EXTRACT_FUNCTION: Lazy<RefactorCodeActionKind> =
|
||||
Lazy::new(|| RefactorCodeActionKind {
|
||||
kind: [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "function"]
|
||||
.join(".")
|
||||
.into(),
|
||||
matches_callback: Box::new(|tag: &str| tag.starts_with("function_")),
|
||||
};
|
||||
});
|
||||
|
||||
pub static ref EXTRACT_CONSTANT: RefactorCodeActionKind = RefactorCodeActionKind {
|
||||
kind : [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "constant"].join(".").into(),
|
||||
pub static EXTRACT_CONSTANT: Lazy<RefactorCodeActionKind> =
|
||||
Lazy::new(|| RefactorCodeActionKind {
|
||||
kind: [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "constant"]
|
||||
.join(".")
|
||||
.into(),
|
||||
matches_callback: Box::new(|tag: &str| tag.starts_with("constant_")),
|
||||
};
|
||||
});
|
||||
|
||||
pub static ref EXTRACT_TYPE: RefactorCodeActionKind = RefactorCodeActionKind {
|
||||
kind : [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "type"].join(".").into(),
|
||||
matches_callback: Box::new(|tag: &str| tag.starts_with("Extract to type alias")),
|
||||
};
|
||||
pub static EXTRACT_TYPE: Lazy<RefactorCodeActionKind> =
|
||||
Lazy::new(|| RefactorCodeActionKind {
|
||||
kind: [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "type"]
|
||||
.join(".")
|
||||
.into(),
|
||||
matches_callback: Box::new(|tag: &str| {
|
||||
tag.starts_with("Extract to type alias")
|
||||
}),
|
||||
});
|
||||
|
||||
pub static ref EXTRACT_INTERFACE: RefactorCodeActionKind = RefactorCodeActionKind {
|
||||
kind : [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "interface"].join(".").into(),
|
||||
matches_callback: Box::new(|tag: &str| tag.starts_with("Extract to interface")),
|
||||
};
|
||||
pub static EXTRACT_INTERFACE: Lazy<RefactorCodeActionKind> =
|
||||
Lazy::new(|| RefactorCodeActionKind {
|
||||
kind: [lsp::CodeActionKind::REFACTOR_EXTRACT.as_str(), "interface"]
|
||||
.join(".")
|
||||
.into(),
|
||||
matches_callback: Box::new(|tag: &str| {
|
||||
tag.starts_with("Extract to interface")
|
||||
}),
|
||||
});
|
||||
|
||||
pub static ref MOVE_NEWFILE: RefactorCodeActionKind = RefactorCodeActionKind {
|
||||
kind : [lsp::CodeActionKind::REFACTOR.as_str(), "move", "newFile"].join(".").into(),
|
||||
matches_callback: Box::new(|tag: &str| tag.starts_with("Move to a new file")),
|
||||
};
|
||||
pub static MOVE_NEWFILE: Lazy<RefactorCodeActionKind> =
|
||||
Lazy::new(|| RefactorCodeActionKind {
|
||||
kind: [lsp::CodeActionKind::REFACTOR.as_str(), "move", "newFile"]
|
||||
.join(".")
|
||||
.into(),
|
||||
matches_callback: Box::new(|tag: &str| {
|
||||
tag.starts_with("Move to a new file")
|
||||
}),
|
||||
});
|
||||
|
||||
pub static ref REWRITE_IMPORT: RefactorCodeActionKind = RefactorCodeActionKind {
|
||||
kind : [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "import"].join(".").into(),
|
||||
matches_callback: Box::new(|tag: &str| tag.starts_with("Convert namespace import") || tag.starts_with("Convert named imports")),
|
||||
};
|
||||
pub static REWRITE_IMPORT: Lazy<RefactorCodeActionKind> =
|
||||
Lazy::new(|| RefactorCodeActionKind {
|
||||
kind: [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "import"]
|
||||
.join(".")
|
||||
.into(),
|
||||
matches_callback: Box::new(|tag: &str| {
|
||||
tag.starts_with("Convert namespace import")
|
||||
|| tag.starts_with("Convert named imports")
|
||||
}),
|
||||
});
|
||||
|
||||
pub static ref REWRITE_EXPORT: RefactorCodeActionKind = RefactorCodeActionKind {
|
||||
kind : [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "export"].join(".").into(),
|
||||
matches_callback: Box::new(|tag: &str| tag.starts_with("Convert default export") || tag.starts_with("Convert named export")),
|
||||
};
|
||||
pub static REWRITE_EXPORT: Lazy<RefactorCodeActionKind> =
|
||||
Lazy::new(|| RefactorCodeActionKind {
|
||||
kind: [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "export"]
|
||||
.join(".")
|
||||
.into(),
|
||||
matches_callback: Box::new(|tag: &str| {
|
||||
tag.starts_with("Convert default export")
|
||||
|| tag.starts_with("Convert named export")
|
||||
}),
|
||||
});
|
||||
|
||||
pub static ref REWRITE_ARROW_BRACES: RefactorCodeActionKind = RefactorCodeActionKind {
|
||||
kind : [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "arrow", "braces"].join(".").into(),
|
||||
matches_callback: Box::new(|tag: &str| tag.starts_with("Add or remove braces in an arrow function")),
|
||||
};
|
||||
pub static REWRITE_ARROW_BRACES: Lazy<RefactorCodeActionKind> =
|
||||
Lazy::new(|| RefactorCodeActionKind {
|
||||
kind: [
|
||||
lsp::CodeActionKind::REFACTOR_REWRITE.as_str(),
|
||||
"arrow",
|
||||
"braces",
|
||||
]
|
||||
.join(".")
|
||||
.into(),
|
||||
matches_callback: Box::new(|tag: &str| {
|
||||
tag.starts_with("Add or remove braces in an arrow function")
|
||||
}),
|
||||
});
|
||||
|
||||
pub static ref REWRITE_PARAMETERS_TO_DESTRUCTURED: RefactorCodeActionKind = RefactorCodeActionKind {
|
||||
kind : [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "parameters", "toDestructured"].join(".").into(),
|
||||
matches_callback: Box::new(|tag: &str| tag.starts_with("Convert parameters to destructured object")),
|
||||
};
|
||||
pub static REWRITE_PARAMETERS_TO_DESTRUCTURED: Lazy<RefactorCodeActionKind> =
|
||||
Lazy::new(|| RefactorCodeActionKind {
|
||||
kind: [
|
||||
lsp::CodeActionKind::REFACTOR_REWRITE.as_str(),
|
||||
"parameters",
|
||||
"toDestructured",
|
||||
]
|
||||
.join(".")
|
||||
.into(),
|
||||
matches_callback: Box::new(|tag: &str| {
|
||||
tag.starts_with("Convert parameters to destructured object")
|
||||
}),
|
||||
});
|
||||
|
||||
pub static ref REWRITE_PROPERTY_GENERATEACCESSORS: RefactorCodeActionKind = RefactorCodeActionKind {
|
||||
kind : [lsp::CodeActionKind::REFACTOR_REWRITE.as_str(), "property", "generateAccessors"].join(".").into(),
|
||||
matches_callback: Box::new(|tag: &str| tag.starts_with("Generate 'get' and 'set' accessors")),
|
||||
};
|
||||
pub static REWRITE_PROPERTY_GENERATEACCESSORS: Lazy<RefactorCodeActionKind> =
|
||||
Lazy::new(|| RefactorCodeActionKind {
|
||||
kind: [
|
||||
lsp::CodeActionKind::REFACTOR_REWRITE.as_str(),
|
||||
"property",
|
||||
"generateAccessors",
|
||||
]
|
||||
.join(".")
|
||||
.into(),
|
||||
matches_callback: Box::new(|tag: &str| {
|
||||
tag.starts_with("Generate 'get' and 'set' accessors")
|
||||
}),
|
||||
});
|
||||
|
||||
pub static ref ALL_KNOWN_REFACTOR_ACTION_KINDS: Vec<&'static RefactorCodeActionKind> = vec![
|
||||
pub static ALL_KNOWN_REFACTOR_ACTION_KINDS: Lazy<
|
||||
Vec<&'static RefactorCodeActionKind>,
|
||||
> = Lazy::new(|| {
|
||||
vec![
|
||||
&EXTRACT_FUNCTION,
|
||||
&EXTRACT_CONSTANT,
|
||||
&EXTRACT_TYPE,
|
||||
|
@ -80,9 +143,9 @@ lazy_static::lazy_static! {
|
|||
&REWRITE_EXPORT,
|
||||
&REWRITE_ARROW_BRACES,
|
||||
&REWRITE_PARAMETERS_TO_DESTRUCTURED,
|
||||
&REWRITE_PROPERTY_GENERATEACCESSORS
|
||||
];
|
||||
}
|
||||
&REWRITE_PROPERTY_GENERATEACCESSORS,
|
||||
]
|
||||
});
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue