node_runtime: Use semver::Version to represent package versions (#44342)
Closes #ISSUE This PR is rather a nice to have change than anything critical, so review priority should remain low. Switch to using `semver::Version` for representing node binary and npm package versions. This is in an effort to root out implicit behavior and improve type safety when interacting with the `node_runtime` crate by catching invalid versions where they appear. Currently Zed may implicitly assume the current version is correct, or always install the newest version when a invalid version is passed. `semver::Version` also doesn't require the heap, which is probably more of a fun fact than anything useful. `npm_install_packages` still takes versions as a `&str`, because `latest` can be used to fetch the latest version on npm. This could likely be made into an enum as well, but would make the PR even larger. I tested changes with some node based language servers and external agents, which all worked fine. It would be nice to have some e2e tests for node. To be safe I'd put it on nightly after a Wednesday release. Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
1 parent
010b871a8e
commit
c0b3422941
18 files changed
+118
-99
No files matched your search
@@ -19,6 +19,7 @@ use pet_core::python_environment::{PythonEnvironment, PythonEnvironmentKind};
|
||||
use pet_virtualenv::is_virtualenv_dir;
|
||||
use project::Fs;
|
||||
use project::lsp_store::language_server_settings;
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
use settings::Settings;
|
||||
@@ -621,14 +622,14 @@ impl LspAdapter for PyrightLspAdapter {
|
||||
}
|
||||
|
||||
impl LspInstaller for PyrightLspAdapter {
|
||||
type BinaryVersion = String;
|
||||
type BinaryVersion = Version;
|
||||
|
||||
async fn fetch_latest_server_version(
|
||||
&self,
|
||||
_: &dyn LspAdapterDelegate,
|
||||
_: bool,
|
||||
_: &mut AsyncApp,
|
||||
) -> Result<String> {
|
||||
) -> Result<Self::BinaryVersion> {
|
||||
self.node
|
||||
.npm_package_latest_version(Self::SERVER_NAME.as_ref())
|
||||
.await
|
||||
@@ -672,6 +673,7 @@ impl LspInstaller for PyrightLspAdapter {
|
||||
delegate: &dyn LspAdapterDelegate,
|
||||
) -> Result<LanguageServerBinary> {
|
||||
let server_path = container_dir.join(Self::SERVER_PATH);
|
||||
let latest_version = latest_version.to_string();
|
||||
|
||||
self.node
|
||||
.npm_install_packages(
|
||||
@@ -2040,14 +2042,14 @@ impl LspAdapter for BasedPyrightLspAdapter {
|
||||
}
|
||||
|
||||
impl LspInstaller for BasedPyrightLspAdapter {
|
||||
type BinaryVersion = String;
|
||||
type BinaryVersion = Version;
|
||||
|
||||
async fn fetch_latest_server_version(
|
||||
&self,
|
||||
_: &dyn LspAdapterDelegate,
|
||||
_: bool,
|
||||
_: &mut AsyncApp,
|
||||
) -> Result<String> {
|
||||
) -> Result<Self::BinaryVersion> {
|
||||
self.node
|
||||
.npm_package_latest_version(Self::SERVER_NAME.as_ref())
|
||||
.await
|
||||
@@ -2092,6 +2094,7 @@ impl LspInstaller for BasedPyrightLspAdapter {
|
||||
delegate: &dyn LspAdapterDelegate,
|
||||
) -> Result<LanguageServerBinary> {
|
||||
let server_path = container_dir.join(Self::SERVER_PATH);
|
||||
let latest_version = latest_version.to_string();
|
||||
|
||||
self.node
|
||||
.npm_install_packages(
|
||||
|
||||
Reference in new issue
Block a user