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
+1 -1
View File
@@ -37,7 +37,7 @@ mod yaml;
#[exclude = "*.rs"]
struct LanguageDir;
pub fn init(languages: Arc<LanguageRegistry>, node_runtime: Arc<NodeRuntime>) {
pub fn init(languages: Arc<LanguageRegistry>, node_runtime: Arc<dyn NodeRuntime>) {
let language = |name, grammar, adapters| {
languages.register(name, load_config(name), grammar, adapters, load_queries)
};
+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;
+2 -2
View File
@@ -19,7 +19,7 @@ use gpui::{Action, App, AppContext, AssetSource, AsyncAppContext, Task};
use isahc::{config::Configurable, Request};
use language::{LanguageRegistry, Point};
use log::LevelFilter;
use node_runtime::NodeRuntime;
use node_runtime::RealNodeRuntime;
use parking_lot::Mutex;
use project::Fs;
use serde::{Deserialize, Serialize};
@@ -138,7 +138,7 @@ fn main() {
languages.set_executor(cx.background().clone());
languages.set_language_server_download_dir(paths::LANGUAGES_DIR.clone());
let languages = Arc::new(languages);
let node_runtime = NodeRuntime::instance(http.clone());
let node_runtime = RealNodeRuntime::new(http.clone());
languages::init(languages.clone(), node_runtime.clone());
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http.clone(), cx));
+1 -4
View File
@@ -723,7 +723,6 @@ mod tests {
AppContext, AssetSource, Element, Entity, TestAppContext, View, ViewHandle,
};
use language::LanguageRegistry;
use node_runtime::NodeRuntime;
use project::{Project, ProjectPath};
use serde_json::json;
use settings::{handle_settings_file_changes, watch_config_file, SettingsStore};
@@ -732,7 +731,6 @@ mod tests {
path::{Path, PathBuf},
};
use theme::{ThemeRegistry, ThemeSettings};
use util::http::FakeHttpClient;
use workspace::{
item::{Item, ItemHandle},
open_new, open_paths, pane, NewFile, SplitDirection, WorkspaceHandle,
@@ -2364,8 +2362,7 @@ mod tests {
let mut languages = LanguageRegistry::test();
languages.set_executor(cx.background().clone());
let languages = Arc::new(languages);
let http = FakeHttpClient::with_404_response();
let node_runtime = NodeRuntime::instance(http);
let node_runtime = node_runtime::FakeNodeRuntime::new();
languages::init(languages.clone(), node_runtime);
for name in languages.language_names() {
languages.language_for_name(&name);