Remove NodeRuntime static & add fake implementation for tests

This commit is contained in:
Julia 2023-08-09 21:32:41 -04:00
parent 9272e9354a
commit 8d672f5d4c
17 changed files with 179 additions and 131 deletions

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;