Remove NodeRuntime static & add fake implementation for tests

This commit is contained in:
Julia
2023-09-06 11:18:55 -04:00
parent 9272e9354a
commit 8d672f5d4c
17 changed files with 175 additions and 127 deletions
+6 -6
View File
@@ -22,11 +22,11 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct CssLspAdapter {
node: Arc<NodeRuntime>,
node: Arc<dyn NodeRuntime>,
}
impl CssLspAdapter {
pub fn new(node: Arc<NodeRuntime>) -> Self {
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
CssLspAdapter { node }
}
}
@@ -65,7 +65,7 @@ impl LspAdapter for CssLspAdapter {
self.node
.npm_install_packages(
&container_dir,
[("vscode-langservers-extracted", version.as_str())],
&[("vscode-langservers-extracted", version.as_str())],
)
.await?;
}
@@ -81,14 +81,14 @@ impl LspAdapter for CssLspAdapter {
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn initialization_options(&self) -> Option<serde_json::Value> {
@@ -100,7 +100,7 @@ impl LspAdapter for CssLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &NodeRuntime,
node: &dyn NodeRuntime,
) -> Option<LanguageServerBinary> {
(|| async move {
let mut last_version_dir = None;
+6 -6
View File
@@ -22,11 +22,11 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct HtmlLspAdapter {
node: Arc<NodeRuntime>,
node: Arc<dyn NodeRuntime>,
}
impl HtmlLspAdapter {
pub fn new(node: Arc<NodeRuntime>) -> Self {
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
HtmlLspAdapter { node }
}
}
@@ -65,7 +65,7 @@ impl LspAdapter for HtmlLspAdapter {
self.node
.npm_install_packages(
&container_dir,
[("vscode-langservers-extracted", version.as_str())],
&[("vscode-langservers-extracted", version.as_str())],
)
.await?;
}
@@ -81,14 +81,14 @@ impl LspAdapter for HtmlLspAdapter {
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn initialization_options(&self) -> Option<serde_json::Value> {
@@ -100,7 +100,7 @@ impl LspAdapter for HtmlLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &NodeRuntime,
node: &dyn NodeRuntime,
) -> Option<LanguageServerBinary> {
(|| async move {
let mut last_version_dir = None;
+6 -6
View File
@@ -27,12 +27,12 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct JsonLspAdapter {
node: Arc<NodeRuntime>,
node: Arc<dyn NodeRuntime>,
languages: Arc<LanguageRegistry>,
}
impl JsonLspAdapter {
pub fn new(node: Arc<NodeRuntime>, languages: Arc<LanguageRegistry>) -> Self {
pub fn new(node: Arc<dyn NodeRuntime>, languages: Arc<LanguageRegistry>) -> Self {
JsonLspAdapter { node, languages }
}
}
@@ -71,7 +71,7 @@ impl LspAdapter for JsonLspAdapter {
self.node
.npm_install_packages(
&container_dir,
[("vscode-json-languageserver", version.as_str())],
&[("vscode-json-languageserver", version.as_str())],
)
.await?;
}
@@ -87,14 +87,14 @@ impl LspAdapter for JsonLspAdapter {
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn initialization_options(&self) -> Option<serde_json::Value> {
@@ -148,7 +148,7 @@ impl LspAdapter for JsonLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &NodeRuntime,
node: &dyn NodeRuntime,
) -> Option<LanguageServerBinary> {
(|| async move {
let mut last_version_dir = None;
+6 -6
View File
@@ -23,14 +23,14 @@ fn intelephense_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
pub struct IntelephenseVersion(String);
pub struct IntelephenseLspAdapter {
node: Arc<NodeRuntime>,
node: Arc<dyn NodeRuntime>,
}
impl IntelephenseLspAdapter {
const SERVER_PATH: &'static str = "node_modules/intelephense/lib/intelephense.js";
#[allow(unused)]
pub fn new(node: Arc<NodeRuntime>) -> Self {
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
Self { node }
}
}
@@ -65,7 +65,7 @@ impl LspAdapter for IntelephenseLspAdapter {
if fs::metadata(&server_path).await.is_err() {
self.node
.npm_install_packages(&container_dir, [("intelephense", version.0.as_str())])
.npm_install_packages(&container_dir, &[("intelephense", version.0.as_str())])
.await?;
}
Ok(LanguageServerBinary {
@@ -79,14 +79,14 @@ impl LspAdapter for IntelephenseLspAdapter {
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn label_for_completion(
@@ -107,7 +107,7 @@ impl LspAdapter for IntelephenseLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &NodeRuntime,
node: &dyn NodeRuntime,
) -> Option<LanguageServerBinary> {
(|| async move {
let mut last_version_dir = None;
+6 -6
View File
@@ -20,11 +20,11 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct PythonLspAdapter {
node: Arc<NodeRuntime>,
node: Arc<dyn NodeRuntime>,
}
impl PythonLspAdapter {
pub fn new(node: Arc<NodeRuntime>) -> Self {
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
PythonLspAdapter { node }
}
}
@@ -57,7 +57,7 @@ impl LspAdapter for PythonLspAdapter {
if fs::metadata(&server_path).await.is_err() {
self.node
.npm_install_packages(&container_dir, [("pyright", version.as_str())])
.npm_install_packages(&container_dir, &[("pyright", version.as_str())])
.await?;
}
@@ -72,14 +72,14 @@ impl LspAdapter for PythonLspAdapter {
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn process_completion(&self, item: &mut lsp::CompletionItem) {
@@ -162,7 +162,7 @@ impl LspAdapter for PythonLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &NodeRuntime,
node: &dyn NodeRuntime,
) -> Option<LanguageServerBinary> {
(|| async move {
let mut last_version_dir = None;
+6 -6
View File
@@ -21,11 +21,11 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct SvelteLspAdapter {
node: Arc<NodeRuntime>,
node: Arc<dyn NodeRuntime>,
}
impl SvelteLspAdapter {
pub fn new(node: Arc<NodeRuntime>) -> Self {
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
SvelteLspAdapter { node }
}
}
@@ -64,7 +64,7 @@ impl LspAdapter for SvelteLspAdapter {
self.node
.npm_install_packages(
&container_dir,
[("svelte-language-server", version.as_str())],
&[("svelte-language-server", version.as_str())],
)
.await?;
}
@@ -80,14 +80,14 @@ impl LspAdapter for SvelteLspAdapter {
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn initialization_options(&self) -> Option<serde_json::Value> {
@@ -99,7 +99,7 @@ impl LspAdapter for SvelteLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &NodeRuntime,
node: &dyn NodeRuntime,
) -> Option<LanguageServerBinary> {
(|| async move {
let mut last_version_dir = None;
+6 -6
View File
@@ -26,11 +26,11 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct TailwindLspAdapter {
node: Arc<NodeRuntime>,
node: Arc<dyn NodeRuntime>,
}
impl TailwindLspAdapter {
pub fn new(node: Arc<NodeRuntime>) -> Self {
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
TailwindLspAdapter { node }
}
}
@@ -69,7 +69,7 @@ impl LspAdapter for TailwindLspAdapter {
self.node
.npm_install_packages(
&container_dir,
[("@tailwindcss/language-server", version.as_str())],
&[("@tailwindcss/language-server", version.as_str())],
)
.await?;
}
@@ -85,14 +85,14 @@ impl LspAdapter for TailwindLspAdapter {
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn initialization_options(&self) -> Option<serde_json::Value> {
@@ -131,7 +131,7 @@ impl LspAdapter for TailwindLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &NodeRuntime,
node: &dyn NodeRuntime,
) -> Option<LanguageServerBinary> {
(|| async move {
let mut last_version_dir = None;
+11 -11
View File
@@ -33,14 +33,14 @@ fn eslint_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct TypeScriptLspAdapter {
node: Arc<NodeRuntime>,
node: Arc<dyn NodeRuntime>,
}
impl TypeScriptLspAdapter {
const OLD_SERVER_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.js";
const NEW_SERVER_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.mjs";
pub fn new(node: Arc<NodeRuntime>) -> Self {
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
TypeScriptLspAdapter { node }
}
}
@@ -86,7 +86,7 @@ impl LspAdapter for TypeScriptLspAdapter {
self.node
.npm_install_packages(
&container_dir,
[
&[
("typescript", version.typescript_version.as_str()),
(
"typescript-language-server",
@@ -108,14 +108,14 @@ impl LspAdapter for TypeScriptLspAdapter {
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_ts_server_binary(container_dir, &self.node).await
get_cached_ts_server_binary(container_dir, &*self.node).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_ts_server_binary(container_dir, &self.node).await
get_cached_ts_server_binary(container_dir, &*self.node).await
}
fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
@@ -165,7 +165,7 @@ impl LspAdapter for TypeScriptLspAdapter {
async fn get_cached_ts_server_binary(
container_dir: PathBuf,
node: &NodeRuntime,
node: &dyn NodeRuntime,
) -> Option<LanguageServerBinary> {
(|| async move {
let old_server_path = container_dir.join(TypeScriptLspAdapter::OLD_SERVER_PATH);
@@ -192,14 +192,14 @@ async fn get_cached_ts_server_binary(
}
pub struct EsLintLspAdapter {
node: Arc<NodeRuntime>,
node: Arc<dyn NodeRuntime>,
}
impl EsLintLspAdapter {
const SERVER_PATH: &'static str = "vscode-eslint/server/out/eslintServer.js";
#[allow(unused)]
pub fn new(node: Arc<NodeRuntime>) -> Self {
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
EsLintLspAdapter { node }
}
}
@@ -288,14 +288,14 @@ impl LspAdapter for EsLintLspAdapter {
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_eslint_server_binary(container_dir, &self.node).await
get_cached_eslint_server_binary(container_dir, &*self.node).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_eslint_server_binary(container_dir, &self.node).await
get_cached_eslint_server_binary(container_dir, &*self.node).await
}
async fn label_for_completion(
@@ -313,7 +313,7 @@ impl LspAdapter for EsLintLspAdapter {
async fn get_cached_eslint_server_binary(
container_dir: PathBuf,
node: &NodeRuntime,
node: &dyn NodeRuntime,
) -> Option<LanguageServerBinary> {
(|| async move {
// This is unfortunate but we don't know what the version is to build a path directly
+9 -6
View File
@@ -25,11 +25,11 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct YamlLspAdapter {
node: Arc<NodeRuntime>,
node: Arc<dyn NodeRuntime>,
}
impl YamlLspAdapter {
pub fn new(node: Arc<NodeRuntime>) -> Self {
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
YamlLspAdapter { node }
}
}
@@ -66,7 +66,10 @@ impl LspAdapter for YamlLspAdapter {
if fs::metadata(&server_path).await.is_err() {
self.node
.npm_install_packages(&container_dir, [("yaml-language-server", version.as_str())])
.npm_install_packages(
&container_dir,
&[("yaml-language-server", version.as_str())],
)
.await?;
}
@@ -81,14 +84,14 @@ impl LspAdapter for YamlLspAdapter {
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &self.node).await
get_cached_server_binary(container_dir, &*self.node).await
}
fn workspace_configuration(&self, cx: &mut AppContext) -> BoxFuture<'static, Value> {
let tab_size = all_language_settings(None, cx)
@@ -109,7 +112,7 @@ impl LspAdapter for YamlLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &NodeRuntime,
node: &dyn NodeRuntime,
) -> Option<LanguageServerBinary> {
(|| async move {
let mut last_version_dir = None;