Allow using system node (#18172)

Release Notes:

- (Potentially breaking change) Zed will now use the node installed on
your $PATH (if it is more recent than v18) instead of downloading its
own. You can disable the new behavior with `{"node":
{"disable_path_lookup": true}}` in your settings. We do not yet use
system/project-local node_modules.

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Conrad Irwin 2024-09-23 15:28:04 -06:00 committed by GitHub
parent e4080ef565
commit 3ba071b993
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 614 additions and 391 deletions

View file

@ -22,11 +22,11 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct CssLspAdapter {
node: Arc<dyn NodeRuntime>,
node: NodeRuntime,
}
impl CssLspAdapter {
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
pub fn new(node: NodeRuntime) -> Self {
CssLspAdapter { node }
}
}
@ -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(
@ -103,7 +103,7 @@ impl LspAdapter for CssLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &dyn NodeRuntime,
node: &NodeRuntime,
) -> Option<LanguageServerBinary> {
maybe!(async {
let mut last_version_dir = None;

View file

@ -59,13 +59,13 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct JsonLspAdapter {
node: Arc<dyn NodeRuntime>,
node: NodeRuntime,
languages: Arc<LanguageRegistry>,
workspace_config: OnceLock<Value>,
}
impl JsonLspAdapter {
pub fn new(node: Arc<dyn NodeRuntime>, languages: Arc<LanguageRegistry>) -> Self {
pub fn new(node: NodeRuntime, languages: Arc<LanguageRegistry>) -> Self {
Self {
node,
languages,
@ -183,14 +183,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(
@ -226,7 +226,7 @@ impl LspAdapter for JsonLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &dyn NodeRuntime,
node: &NodeRuntime,
) -> Option<LanguageServerBinary> {
maybe!(async {
let mut last_version_dir = None;

View file

@ -30,11 +30,7 @@ mod yaml;
#[exclude = "*.rs"]
struct LanguageDir;
pub fn init(
languages: Arc<LanguageRegistry>,
node_runtime: Arc<dyn NodeRuntime>,
cx: &mut AppContext,
) {
pub fn init(languages: Arc<LanguageRegistry>, node_runtime: NodeRuntime, cx: &mut AppContext) {
languages.register_native_grammars([
("bash", tree_sitter_bash::LANGUAGE),
("c", tree_sitter_c::LANGUAGE),

View file

@ -26,13 +26,13 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct PythonLspAdapter {
node: Arc<dyn NodeRuntime>,
node: NodeRuntime,
}
impl PythonLspAdapter {
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("pyright");
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
pub fn new(node: NodeRuntime) -> Self {
PythonLspAdapter { node }
}
}
@ -94,14 +94,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_completions(&self, items: &mut [lsp::CompletionItem]) {
@ -198,7 +198,7 @@ impl LspAdapter for PythonLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &dyn NodeRuntime,
node: &NodeRuntime,
) -> Option<LanguageServerBinary> {
let server_path = container_dir.join(SERVER_PATH);
if server_path.exists() {

View file

@ -28,14 +28,14 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct TailwindLspAdapter {
node: Arc<dyn NodeRuntime>,
node: NodeRuntime,
}
impl TailwindLspAdapter {
const SERVER_NAME: LanguageServerName =
LanguageServerName::new_static("tailwindcss-language-server");
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
pub fn new(node: NodeRuntime) -> Self {
TailwindLspAdapter { node }
}
}
@ -122,14 +122,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(
@ -198,7 +198,7 @@ impl LspAdapter for TailwindLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &dyn NodeRuntime,
node: &NodeRuntime,
) -> Option<LanguageServerBinary> {
maybe!(async {
let mut last_version_dir = None;

View file

@ -65,7 +65,7 @@ fn eslint_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct TypeScriptLspAdapter {
node: Arc<dyn NodeRuntime>,
node: NodeRuntime,
}
impl TypeScriptLspAdapter {
@ -73,7 +73,7 @@ impl TypeScriptLspAdapter {
const NEW_SERVER_PATH: &'static str = "node_modules/typescript-language-server/lib/cli.mjs";
const SERVER_NAME: LanguageServerName =
LanguageServerName::new_static("typescript-language-server");
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
pub fn new(node: NodeRuntime) -> Self {
TypeScriptLspAdapter { node }
}
async fn tsdk_path(adapter: &Arc<dyn LspAdapterDelegate>) -> &'static str {
@ -161,14 +161,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>> {
@ -264,7 +264,7 @@ impl LspAdapter for TypeScriptLspAdapter {
async fn get_cached_ts_server_binary(
container_dir: PathBuf,
node: &dyn NodeRuntime,
node: &NodeRuntime,
) -> Option<LanguageServerBinary> {
maybe!(async {
let old_server_path = container_dir.join(TypeScriptLspAdapter::OLD_SERVER_PATH);
@ -293,7 +293,7 @@ async fn get_cached_ts_server_binary(
}
pub struct EsLintLspAdapter {
node: Arc<dyn NodeRuntime>,
node: NodeRuntime,
}
impl EsLintLspAdapter {
@ -310,7 +310,7 @@ impl EsLintLspAdapter {
const FLAT_CONFIG_FILE_NAMES: &'static [&'static str] =
&["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs"];
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
pub fn new(node: NodeRuntime) -> Self {
EsLintLspAdapter { node }
}
}
@ -476,11 +476,11 @@ impl LspAdapter for EsLintLspAdapter {
}
self.node
.run_npm_subcommand(Some(&repo_root), "install", &[])
.run_npm_subcommand(&repo_root, "install", &[])
.await?;
self.node
.run_npm_subcommand(Some(&repo_root), "run-script", &["compile"])
.run_npm_subcommand(&repo_root, "run-script", &["compile"])
.await?;
}
@ -496,20 +496,20 @@ 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 get_cached_eslint_server_binary(
container_dir: PathBuf,
node: &dyn NodeRuntime,
node: &NodeRuntime,
) -> Option<LanguageServerBinary> {
maybe!(async {
// This is unfortunate but we don't know what the version is to build a path directly

View file

@ -20,13 +20,13 @@ fn typescript_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct VtslsLspAdapter {
node: Arc<dyn NodeRuntime>,
node: NodeRuntime,
}
impl VtslsLspAdapter {
const SERVER_PATH: &'static str = "node_modules/@vtsls/language-server/bin/vtsls.js";
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
pub fn new(node: NodeRuntime) -> Self {
VtslsLspAdapter { node }
}
async fn tsdk_path(adapter: &Arc<dyn LspAdapterDelegate>) -> &'static str {
@ -154,14 +154,14 @@ impl LspAdapter for VtslsLspAdapter {
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>> {
@ -298,7 +298,7 @@ impl LspAdapter for VtslsLspAdapter {
async fn get_cached_ts_server_binary(
container_dir: PathBuf,
node: &dyn NodeRuntime,
node: &NodeRuntime,
) -> Option<LanguageServerBinary> {
maybe!(async {
let server_path = container_dir.join(VtslsLspAdapter::SERVER_PATH);

View file

@ -26,12 +26,12 @@ fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
}
pub struct YamlLspAdapter {
node: Arc<dyn NodeRuntime>,
node: NodeRuntime,
}
impl YamlLspAdapter {
const SERVER_NAME: LanguageServerName = LanguageServerName::new_static("yaml-language-server");
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
pub fn new(node: NodeRuntime) -> Self {
YamlLspAdapter { node }
}
}
@ -117,14 +117,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
}
async fn workspace_configuration(
@ -157,7 +157,7 @@ impl LspAdapter for YamlLspAdapter {
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &dyn NodeRuntime,
node: &NodeRuntime,
) -> Option<LanguageServerBinary> {
maybe!(async {
let mut last_version_dir = None;