Skip to content

Commit

Permalink
fix(lsp): support npm workspaces and fix some resolution issues (#24627)
Browse files Browse the repository at this point in the history
Makes the lsp use the same code as the rest of the cli.
  • Loading branch information
dsherret authored Jul 18, 2024
1 parent 1722e0a commit 3bda8eb
Show file tree
Hide file tree
Showing 11 changed files with 1,047 additions and 794 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ console_static_text = "=0.8.1"
data-encoding = "2.3.3"
data-url = "=0.3.0"
deno_cache_dir = "=0.10.0"
deno_config = { version = "=0.23.0", default-features = false }
deno_config = { version = "=0.24.0", default-features = false }
dlopen2 = "0.6.1"
ecb = "=0.1.2"
elliptic-curve = { version = "0.13.4", features = ["alloc", "arithmetic", "ecdh", "std", "pem"] }
Expand Down
29 changes: 18 additions & 11 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,22 @@ fn resolve_lint_rules_options(
}
}

pub fn discover_npmrc_from_workspace(
workspace: &Workspace,
) -> Result<(Arc<ResolvedNpmRc>, Option<PathBuf>), AnyError> {
let root_folder = workspace.root_folder().1;
discover_npmrc(
root_folder.pkg_json.as_ref().map(|p| p.path.clone()),
root_folder.deno_json.as_ref().and_then(|cf| {
if cf.specifier.scheme() == "file" {
Some(cf.specifier.to_file_path().unwrap())
} else {
None
}
}),
)
}

/// Discover `.npmrc` file - currently we only support it next to `package.json`
/// or next to `deno.json`.
///
Expand Down Expand Up @@ -846,6 +862,7 @@ impl CliOptions {
}
WorkspaceDiscoverOptions {
fs: &config_fs_adapter,
deno_json_cache: None,
pkg_json_cache: Some(
&deno_runtime::deno_node::PackageJsonThreadLocalCache,
),
Expand Down Expand Up @@ -890,17 +907,7 @@ impl CliOptions {
log::warn!("{} {}", colors::yellow("Warning"), diagnostic);
}

let root_folder = workspace.root_folder().1;
let (npmrc, _) = discover_npmrc(
root_folder.pkg_json.as_ref().map(|p| p.path.clone()),
root_folder.deno_json.as_ref().and_then(|cf| {
if cf.specifier.scheme() == "file" {
Some(cf.specifier.to_file_path().unwrap())
} else {
None
}
}),
)?;
let (npmrc, _) = discover_npmrc_from_workspace(&workspace)?;

let maybe_lock_file = CliLockfile::discover(&flags, &workspace)?;

Expand Down
2 changes: 1 addition & 1 deletion cli/lsp/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ mod tests {
fs_sources: &[(&str, &str)],
) -> Documents {
let temp_dir = TempDir::new();
let cache = LspCache::new(Some(temp_dir.uri()));
let cache = LspCache::new(Some(temp_dir.uri().join(".deno_dir").unwrap()));
let mut documents = Documents::default();
documents.update_config(
&Default::default(),
Expand Down
Loading

0 comments on commit 3bda8eb

Please sign in to comment.