summaryrefslogtreecommitdiff
path: root/cli/lsp/analysis.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-11-01 12:27:00 -0400
committerGitHub <noreply@github.com>2024-11-01 12:27:00 -0400
commit826e42a5b5880c974ae019a7a21aade6a718062c (patch)
treea46502ecc3c73e4f7fc3a4517d83c7b2f3d0c0d3 /cli/lsp/analysis.rs
parent4774eab64d5176e997b6431f03f075782321b3d9 (diff)
fix: improved support for cjs and cts modules (#26558)
* cts support * better cjs/cts type checking * deno compile cjs/cts support * More efficient detect cjs (going towards stabilization) * Determination of whether .js, .ts, .jsx, or .tsx is cjs or esm is only done after loading * Support `import x = require(...);` Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/lsp/analysis.rs')
-rw-r--r--cli/lsp/analysis.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs
index 39f1ae648..0769c9047 100644
--- a/cli/lsp/analysis.rs
+++ b/cli/lsp/analysis.rs
@@ -36,7 +36,6 @@ use deno_semver::package::PackageReq;
use deno_semver::package::PackageReqReference;
use deno_semver::Version;
use import_map::ImportMap;
-use node_resolver::NpmResolver;
use once_cell::sync::Lazy;
use regex::Regex;
use std::borrow::Cow;
@@ -336,7 +335,12 @@ impl<'a> TsResponseImportMapper<'a> {
.resolver
.maybe_managed_npm_resolver(Some(&self.file_referrer))
{
- if npm_resolver.in_npm_package(specifier) {
+ let in_npm_pkg = self
+ .resolver
+ .maybe_node_resolver(Some(&self.file_referrer))
+ .map(|n| n.in_npm_package(specifier))
+ .unwrap_or(false);
+ if in_npm_pkg {
if let Ok(Some(pkg_id)) =
npm_resolver.resolve_pkg_id_from_specifier(specifier)
{
@@ -1199,14 +1203,11 @@ impl CodeActionCollection {
}),
);
- match parsed_source.program_ref() {
- deno_ast::swc::ast::Program::Module(module) => module
- .body
- .iter()
- .find(|i| i.range().contains(&specifier_range))
- .map(|i| text_info.line_and_column_index(i.range().start)),
- deno_ast::swc::ast::Program::Script(_) => None,
- }
+ parsed_source
+ .program_ref()
+ .body()
+ .find(|i| i.range().contains(&specifier_range))
+ .map(|i| text_info.line_and_column_index(i.range().start))
}
async fn deno_types_for_npm_action(