feat(lsp): support lockfile and node_modules directory (#19203)

This adds support for the lockfile and node_modules directory to the
lsp.

In the case of the node_modules directory, it is only enabled when
explicitly opted into via `"nodeModulesDir": true` in the configuration
file. This is to reduce the language server automatically modifying the
node_modules directory when the user doesn't want it to.

Closes #16510
Closes #16373
This commit is contained in:
David Sherret 2023-05-22 21:28:36 -04:00 committed by GitHub
parent 5878258952
commit bb37dfb5b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 567 additions and 176 deletions

View file

@ -64,6 +64,12 @@ impl PackageJsonDepsInstaller {
}))
}
/// Creates an installer that never installs local packages during
/// resolution. A top level install will be a no-op.
pub fn no_op() -> Self {
Self(None)
}
/// Installs the top level dependencies in the package.json file
/// without going through and resolving the descendant dependencies yet.
pub async fn ensure_top_level_install(&self) -> Result<(), AnyError> {

View file

@ -91,6 +91,16 @@ impl CliNpmResolver {
self.fs_resolver.node_modules_path()
}
/// Checks if the provided package req's folder is cached.
pub fn is_pkg_req_folder_cached(&self, req: &NpmPackageReq) -> bool {
self
.resolve_pkg_id_from_pkg_req(req)
.ok()
.and_then(|id| self.fs_resolver.package_folder(&id).ok())
.map(|folder| folder.exists())
.unwrap_or(false)
}
pub fn resolve_pkg_id_from_pkg_req(
&self,
req: &NpmPackageReq,