mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
perf(lsp): cleanup document dependencies (#23426)
This commit is contained in:
parent
90688edcc2
commit
8e77f091ad
12 changed files with 122 additions and 115 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -1166,9 +1166,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deno_ast"
|
name = "deno_ast"
|
||||||
version = "0.37.0"
|
version = "0.37.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "67f9b18b22c707b59cf1ee9cb6f0afbfcf0d03a59b9244ddadacf6a4dc7cfeba"
|
checksum = "b2be70f80fee64edfbbc4a61c50f18b4a0fbff0b2657d26f6f0443e1db279af9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
"base64",
|
||||||
|
@ -1381,9 +1381,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deno_doc"
|
name = "deno_doc"
|
||||||
version = "0.124.0"
|
version = "0.125.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3e1215167b2d2a7595cf32737ff9c7802d7faf58dfbe8c9e5d8f07d4c3af4987"
|
checksum = "43a44dfda00cc831fdc693d295cb90cb30b34bc28894d1b4ab023614ab5e0a3b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ammonia",
|
"ammonia",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
@ -1405,9 +1405,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deno_emit"
|
name = "deno_emit"
|
||||||
version = "0.39.1"
|
version = "0.40.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8928b70466b99a4fa6ad1e2334f5268eb319d1ddc7607b1ccbd6260cc5b45e6d"
|
checksum = "03ae8a1338bd3860f68fbfd99bbbc8a9c4ebe78e4b298f62980d2fc3547f04bb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
"base64",
|
||||||
|
@ -1477,9 +1477,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deno_graph"
|
name = "deno_graph"
|
||||||
version = "0.72.0"
|
version = "0.73.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "508791f6140a8b5b1ac40bac1842db04281b61db4b64c5fd5bf9f1f7259f328a"
|
checksum = "046123e4f8de81c7db363d0869d783a5dcd6ceb007b07c6ba4fdf3cc0a82314e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
@ -1621,9 +1621,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deno_media_type"
|
name = "deno_media_type"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "edf9879493856d1622be70f396b0b0d3e519538dd6501b7c609ecbaa7e2194d2"
|
checksum = "a8978229b82552bf8457a0125aa20863f023619cfc21ebb007b1e571d68fd85b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"data-url",
|
"data-url",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -2530,9 +2530,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "eszip"
|
name = "eszip"
|
||||||
version = "0.67.0"
|
version = "0.68.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6d43c01fc33df17895d3313cf01bf88dde2522ab19da95cddb881be1cb2642ac"
|
checksum = "96de7a1c16d3d63e7c84e14da935cebb4b7f451d4508b3ff2ae0e1c313059cd1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
"base64",
|
||||||
|
|
|
@ -43,7 +43,7 @@ license = "MIT"
|
||||||
repository = "https://github.com/denoland/deno"
|
repository = "https://github.com/denoland/deno"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
deno_ast = { version = "=0.37.0", features = ["transpiling"] }
|
deno_ast = { version = "=0.37.1", features = ["transpiling"] }
|
||||||
deno_core = { version = "0.275.0" }
|
deno_core = { version = "0.275.0" }
|
||||||
|
|
||||||
deno_bench_util = { version = "0.141.0", path = "./bench_util" }
|
deno_bench_util = { version = "0.141.0", path = "./bench_util" }
|
||||||
|
|
|
@ -66,9 +66,9 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposa
|
||||||
deno_cache_dir = { workspace = true }
|
deno_cache_dir = { workspace = true }
|
||||||
deno_config = "=0.15.0"
|
deno_config = "=0.15.0"
|
||||||
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
|
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
|
||||||
deno_doc = { version = "=0.124.0", features = ["html"] }
|
deno_doc = { version = "=0.125.0", features = ["html"] }
|
||||||
deno_emit = "=0.39.1"
|
deno_emit = "=0.40.0"
|
||||||
deno_graph = { version = "=0.72.0", features = ["tokio_executor"] }
|
deno_graph = { version = "=0.73.1", features = ["tokio_executor"] }
|
||||||
deno_lint = { version = "=0.58.3", features = ["docs"] }
|
deno_lint = { version = "=0.58.3", features = ["docs"] }
|
||||||
deno_lockfile.workspace = true
|
deno_lockfile.workspace = true
|
||||||
deno_npm = "=0.17.0"
|
deno_npm = "=0.17.0"
|
||||||
|
@ -76,7 +76,7 @@ deno_runtime = { workspace = true, features = ["include_js_files_for_snapshottin
|
||||||
deno_semver = "=0.5.4"
|
deno_semver = "=0.5.4"
|
||||||
deno_task_shell = "=0.16.0"
|
deno_task_shell = "=0.16.0"
|
||||||
deno_terminal.workspace = true
|
deno_terminal.workspace = true
|
||||||
eszip = "=0.67.0"
|
eszip = "=0.68.0"
|
||||||
napi_sym.workspace = true
|
napi_sym.workspace = true
|
||||||
|
|
||||||
async-trait.workspace = true
|
async-trait.workspace = true
|
||||||
|
|
|
@ -185,6 +185,7 @@ pub fn ts_config_to_transpile_and_emit_options(
|
||||||
jsx_fragment_factory: options.jsx_fragment_factory,
|
jsx_fragment_factory: options.jsx_fragment_factory,
|
||||||
jsx_import_source: options.jsx_import_source,
|
jsx_import_source: options.jsx_import_source,
|
||||||
precompile_jsx,
|
precompile_jsx,
|
||||||
|
precompile_jsx_skip_elements: None,
|
||||||
transform_jsx,
|
transform_jsx,
|
||||||
var_decl_imports: false,
|
var_decl_imports: false,
|
||||||
},
|
},
|
||||||
|
|
4
cli/cache/mod.rs
vendored
4
cli/cache/mod.rs
vendored
|
@ -192,7 +192,7 @@ impl Loader for FetchCacher {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load(
|
fn load(
|
||||||
&mut self,
|
&self,
|
||||||
specifier: &ModuleSpecifier,
|
specifier: &ModuleSpecifier,
|
||||||
options: deno_graph::source::LoadOptions,
|
options: deno_graph::source::LoadOptions,
|
||||||
) -> LoadFuture {
|
) -> LoadFuture {
|
||||||
|
@ -278,7 +278,7 @@ impl Loader for FetchCacher {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cache_module_info(
|
fn cache_module_info(
|
||||||
&mut self,
|
&self,
|
||||||
specifier: &ModuleSpecifier,
|
specifier: &ModuleSpecifier,
|
||||||
source: &Arc<[u8]>,
|
source: &Arc<[u8]>,
|
||||||
module_info: &deno_graph::ModuleInfo,
|
module_info: &deno_graph::ModuleInfo,
|
||||||
|
|
|
@ -453,6 +453,7 @@ impl ModuleGraphBuilder {
|
||||||
deno_graph::BuildOptions {
|
deno_graph::BuildOptions {
|
||||||
is_dynamic: options.is_dynamic,
|
is_dynamic: options.is_dynamic,
|
||||||
jsr_url_provider: &CliJsrUrlProvider,
|
jsr_url_provider: &CliJsrUrlProvider,
|
||||||
|
passthrough_jsr_specifiers: false,
|
||||||
executor: Default::default(),
|
executor: Default::default(),
|
||||||
imports: maybe_imports,
|
imports: maybe_imports,
|
||||||
resolver: Some(graph_resolver),
|
resolver: Some(graph_resolver),
|
||||||
|
|
|
@ -211,42 +211,19 @@ impl AssetOrDocument {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
struct DocumentDependencies {
|
|
||||||
deps: IndexMap<String, deno_graph::Dependency>,
|
|
||||||
maybe_types_dependency: Option<deno_graph::TypesDependency>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DocumentDependencies {
|
|
||||||
pub fn from_maybe_module(maybe_module: &Option<ModuleResult>) -> Self {
|
|
||||||
if let Some(Ok(module)) = &maybe_module {
|
|
||||||
Self::from_module(module)
|
|
||||||
} else {
|
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_module(module: &deno_graph::JsModule) -> Self {
|
|
||||||
Self {
|
|
||||||
deps: module.dependencies.clone(),
|
|
||||||
maybe_types_dependency: module.maybe_types_dependency.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type ModuleResult = Result<deno_graph::JsModule, deno_graph::ModuleGraphError>;
|
type ModuleResult = Result<deno_graph::JsModule, deno_graph::ModuleGraphError>;
|
||||||
type ParsedSourceResult = Result<ParsedSource, deno_ast::ParseDiagnostic>;
|
type ParsedSourceResult = Result<ParsedSource, deno_ast::ParseDiagnostic>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Document {
|
pub struct Document {
|
||||||
/// Contains the last-known-good set of dependencies from parsing the module.
|
/// Contains the last-known-good set of dependencies from parsing the module.
|
||||||
dependencies: Arc<DocumentDependencies>,
|
dependencies: Arc<IndexMap<String, deno_graph::Dependency>>,
|
||||||
|
maybe_types_dependency: Option<Arc<deno_graph::TypesDependency>>,
|
||||||
fs_version: String,
|
fs_version: String,
|
||||||
line_index: Arc<LineIndex>,
|
line_index: Arc<LineIndex>,
|
||||||
maybe_headers: Option<HashMap<String, String>>,
|
maybe_headers: Option<HashMap<String, String>>,
|
||||||
maybe_language_id: Option<LanguageId>,
|
maybe_language_id: Option<LanguageId>,
|
||||||
maybe_lsp_version: Option<i32>,
|
maybe_lsp_version: Option<i32>,
|
||||||
maybe_module: Option<ModuleResult>,
|
|
||||||
// this is a lazily constructed value based on the state of the document,
|
// this is a lazily constructed value based on the state of the document,
|
||||||
// so having a mutex to hold it is ok
|
// so having a mutex to hold it is ok
|
||||||
maybe_navigation_tree: Mutex<Option<Arc<tsc::NavigationTree>>>,
|
maybe_navigation_tree: Mutex<Option<Arc<tsc::NavigationTree>>>,
|
||||||
|
@ -283,17 +260,23 @@ impl Document {
|
||||||
resolver,
|
resolver,
|
||||||
npm_resolver,
|
npm_resolver,
|
||||||
);
|
);
|
||||||
let dependencies =
|
let maybe_module = maybe_module.and_then(Result::ok);
|
||||||
Arc::new(DocumentDependencies::from_maybe_module(&maybe_module));
|
let dependencies = maybe_module
|
||||||
|
.as_ref()
|
||||||
|
.map(|m| Arc::new(m.dependencies.clone()))
|
||||||
|
.unwrap_or_default();
|
||||||
|
let maybe_types_dependency = maybe_module
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|m| Some(Arc::new(m.maybe_types_dependency.clone()?)));
|
||||||
let line_index = Arc::new(LineIndex::new(text_info.text_str()));
|
let line_index = Arc::new(LineIndex::new(text_info.text_str()));
|
||||||
Arc::new(Document {
|
Arc::new(Document {
|
||||||
dependencies,
|
dependencies,
|
||||||
|
maybe_types_dependency,
|
||||||
fs_version,
|
fs_version,
|
||||||
line_index,
|
line_index,
|
||||||
maybe_headers,
|
maybe_headers,
|
||||||
maybe_language_id: None,
|
maybe_language_id: None,
|
||||||
maybe_lsp_version: None,
|
maybe_lsp_version: None,
|
||||||
maybe_module,
|
|
||||||
maybe_navigation_tree: Mutex::new(None),
|
maybe_navigation_tree: Mutex::new(None),
|
||||||
maybe_parsed_source: maybe_parsed_source
|
maybe_parsed_source: maybe_parsed_source
|
||||||
.filter(|_| specifier.scheme() == "file"),
|
.filter(|_| specifier.scheme() == "file"),
|
||||||
|
@ -309,39 +292,59 @@ impl Document {
|
||||||
maybe_node_resolver: Option<&CliNodeResolver>,
|
maybe_node_resolver: Option<&CliNodeResolver>,
|
||||||
npm_resolver: &dyn deno_graph::source::NpmResolver,
|
npm_resolver: &dyn deno_graph::source::NpmResolver,
|
||||||
) -> Option<Arc<Self>> {
|
) -> Option<Arc<Self>> {
|
||||||
let mut parsed_source_result = match &self.maybe_parsed_source {
|
|
||||||
Some(parsed_source_result) => parsed_source_result.clone(),
|
|
||||||
None => return None, // nothing to change
|
|
||||||
};
|
|
||||||
let media_type = resolve_media_type(
|
let media_type = resolve_media_type(
|
||||||
&self.specifier,
|
&self.specifier,
|
||||||
self.maybe_headers.as_ref(),
|
self.maybe_headers.as_ref(),
|
||||||
self.maybe_language_id,
|
self.maybe_language_id,
|
||||||
maybe_node_resolver,
|
maybe_node_resolver,
|
||||||
);
|
);
|
||||||
// reparse if the media type has changed
|
let dependencies;
|
||||||
if let Ok(parsed_source) = &parsed_source_result {
|
let maybe_types_dependency;
|
||||||
if parsed_source.media_type() != media_type {
|
let maybe_parsed_source;
|
||||||
parsed_source_result =
|
if media_type != self.media_type {
|
||||||
parse_source(&self.specifier, self.text_info.clone(), media_type);
|
let parsed_source_result =
|
||||||
}
|
parse_source(&self.specifier, self.text_info.clone(), media_type);
|
||||||
|
let maybe_module = analyze_module(
|
||||||
|
&self.specifier,
|
||||||
|
&parsed_source_result,
|
||||||
|
self.maybe_headers.as_ref(),
|
||||||
|
resolver,
|
||||||
|
npm_resolver,
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
|
dependencies = maybe_module
|
||||||
|
.as_ref()
|
||||||
|
.map(|m| Arc::new(m.dependencies.clone()))
|
||||||
|
.unwrap_or_default();
|
||||||
|
maybe_types_dependency = maybe_module
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|m| Some(Arc::new(m.maybe_types_dependency.clone()?)));
|
||||||
|
maybe_parsed_source = Some(parsed_source_result);
|
||||||
|
} else {
|
||||||
|
dependencies = Arc::new(
|
||||||
|
self
|
||||||
|
.dependencies
|
||||||
|
.iter()
|
||||||
|
.map(|(s, d)| {
|
||||||
|
(
|
||||||
|
s.clone(),
|
||||||
|
d.with_new_resolver(s, Some(resolver), Some(npm_resolver)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
);
|
||||||
|
maybe_types_dependency = self.maybe_types_dependency.as_ref().map(|d| {
|
||||||
|
Arc::new(d.with_new_resolver(Some(resolver), Some(npm_resolver)))
|
||||||
|
});
|
||||||
|
maybe_parsed_source = self.maybe_parsed_source.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
let maybe_module = Some(analyze_module(
|
|
||||||
&self.specifier,
|
|
||||||
&parsed_source_result,
|
|
||||||
self.maybe_headers.as_ref(),
|
|
||||||
resolver,
|
|
||||||
npm_resolver,
|
|
||||||
));
|
|
||||||
let dependencies =
|
|
||||||
Arc::new(DocumentDependencies::from_maybe_module(&maybe_module));
|
|
||||||
Some(Arc::new(Self {
|
Some(Arc::new(Self {
|
||||||
// updated properties
|
// updated properties
|
||||||
dependencies,
|
dependencies,
|
||||||
maybe_module,
|
maybe_types_dependency,
|
||||||
maybe_navigation_tree: Mutex::new(None),
|
maybe_navigation_tree: Mutex::new(None),
|
||||||
maybe_parsed_source: Some(parsed_source_result),
|
maybe_parsed_source: maybe_parsed_source
|
||||||
|
.filter(|_| self.specifier.scheme() == "file"),
|
||||||
// maintain - this should all be copies/clones
|
// maintain - this should all be copies/clones
|
||||||
fs_version: self.fs_version.clone(),
|
fs_version: self.fs_version.clone(),
|
||||||
line_index: self.line_index.clone(),
|
line_index: self.line_index.clone(),
|
||||||
|
@ -385,18 +388,24 @@ impl Document {
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
(None, None)
|
||||||
};
|
};
|
||||||
let dependencies =
|
let maybe_module = maybe_module.and_then(Result::ok);
|
||||||
Arc::new(DocumentDependencies::from_maybe_module(&maybe_module));
|
let dependencies = maybe_module
|
||||||
|
.as_ref()
|
||||||
|
.map(|m| Arc::new(m.dependencies.clone()))
|
||||||
|
.unwrap_or_default();
|
||||||
|
let maybe_types_dependency = maybe_module
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|m| Some(Arc::new(m.maybe_types_dependency.clone()?)));
|
||||||
let line_index = Arc::new(LineIndex::new(text_info.text_str()));
|
let line_index = Arc::new(LineIndex::new(text_info.text_str()));
|
||||||
Arc::new(Self {
|
Arc::new(Self {
|
||||||
dependencies,
|
dependencies,
|
||||||
|
maybe_types_dependency,
|
||||||
fs_version: calculate_fs_version(cache, &specifier)
|
fs_version: calculate_fs_version(cache, &specifier)
|
||||||
.unwrap_or_else(|| "1".to_string()),
|
.unwrap_or_else(|| "1".to_string()),
|
||||||
line_index,
|
line_index,
|
||||||
maybe_language_id: Some(language_id),
|
maybe_language_id: Some(language_id),
|
||||||
maybe_lsp_version: Some(version),
|
maybe_lsp_version: Some(version),
|
||||||
maybe_headers,
|
maybe_headers,
|
||||||
maybe_module,
|
|
||||||
maybe_navigation_tree: Mutex::new(None),
|
maybe_navigation_tree: Mutex::new(None),
|
||||||
maybe_parsed_source: maybe_parsed_source
|
maybe_parsed_source: maybe_parsed_source
|
||||||
.filter(|_| specifier.scheme() == "file"),
|
.filter(|_| specifier.scheme() == "file"),
|
||||||
|
@ -448,11 +457,15 @@ impl Document {
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
(None, None)
|
||||||
};
|
};
|
||||||
let dependencies = if let Some(Ok(module)) = &maybe_module {
|
let maybe_module = maybe_module.and_then(Result::ok);
|
||||||
Arc::new(DocumentDependencies::from_module(module))
|
let dependencies = maybe_module
|
||||||
} else {
|
.as_ref()
|
||||||
self.dependencies.clone() // use the last known good
|
.map(|m| Arc::new(m.dependencies.clone()))
|
||||||
};
|
.unwrap_or_else(|| self.dependencies.clone());
|
||||||
|
let maybe_types_dependency = maybe_module
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|m| Some(Arc::new(m.maybe_types_dependency.clone()?)))
|
||||||
|
.or_else(|| self.maybe_types_dependency.clone());
|
||||||
let line_index = if index_valid == IndexValid::All {
|
let line_index = if index_valid == IndexValid::All {
|
||||||
line_index
|
line_index
|
||||||
} else {
|
} else {
|
||||||
|
@ -463,10 +476,10 @@ impl Document {
|
||||||
fs_version: self.fs_version.clone(),
|
fs_version: self.fs_version.clone(),
|
||||||
maybe_language_id: self.maybe_language_id,
|
maybe_language_id: self.maybe_language_id,
|
||||||
dependencies,
|
dependencies,
|
||||||
|
maybe_types_dependency,
|
||||||
text_info,
|
text_info,
|
||||||
line_index,
|
line_index,
|
||||||
maybe_headers: self.maybe_headers.clone(),
|
maybe_headers: self.maybe_headers.clone(),
|
||||||
maybe_module,
|
|
||||||
maybe_parsed_source: maybe_parsed_source
|
maybe_parsed_source: maybe_parsed_source
|
||||||
.filter(|_| self.specifier.scheme() == "file"),
|
.filter(|_| self.specifier.scheme() == "file"),
|
||||||
maybe_lsp_version: Some(version),
|
maybe_lsp_version: Some(version),
|
||||||
|
@ -482,10 +495,10 @@ impl Document {
|
||||||
.unwrap_or_else(|| "1".to_string()),
|
.unwrap_or_else(|| "1".to_string()),
|
||||||
maybe_language_id: self.maybe_language_id,
|
maybe_language_id: self.maybe_language_id,
|
||||||
dependencies: self.dependencies.clone(),
|
dependencies: self.dependencies.clone(),
|
||||||
|
maybe_types_dependency: self.maybe_types_dependency.clone(),
|
||||||
text_info: self.text_info.clone(),
|
text_info: self.text_info.clone(),
|
||||||
line_index: self.line_index.clone(),
|
line_index: self.line_index.clone(),
|
||||||
maybe_headers: self.maybe_headers.clone(),
|
maybe_headers: self.maybe_headers.clone(),
|
||||||
maybe_module: self.maybe_module.clone(),
|
|
||||||
maybe_parsed_source: self.maybe_parsed_source.clone(),
|
maybe_parsed_source: self.maybe_parsed_source.clone(),
|
||||||
maybe_lsp_version: self.maybe_lsp_version,
|
maybe_lsp_version: self.maybe_lsp_version,
|
||||||
maybe_navigation_tree: Mutex::new(None),
|
maybe_navigation_tree: Mutex::new(None),
|
||||||
|
@ -541,11 +554,11 @@ impl Document {
|
||||||
self.maybe_lsp_version.is_some()
|
self.maybe_lsp_version.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_types_dependency(&self) -> Resolution {
|
pub fn maybe_types_dependency(&self) -> &Resolution {
|
||||||
if let Some(types_dep) = self.dependencies.maybe_types_dependency.as_ref() {
|
if let Some(types_dep) = self.maybe_types_dependency.as_deref() {
|
||||||
types_dep.dependency.clone()
|
&types_dep.dependency
|
||||||
} else {
|
} else {
|
||||||
Resolution::None
|
&Resolution::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,10 +575,6 @@ impl Document {
|
||||||
self.maybe_lsp_version
|
self.maybe_lsp_version
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_js_module(&self) -> Option<&ModuleResult> {
|
|
||||||
self.maybe_module.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn maybe_parsed_source(
|
pub fn maybe_parsed_source(
|
||||||
&self,
|
&self,
|
||||||
) -> Option<Result<deno_ast::ParsedSource, deno_ast::ParseDiagnostic>> {
|
) -> Option<Result<deno_ast::ParsedSource, deno_ast::ParseDiagnostic>> {
|
||||||
|
@ -591,7 +600,7 @@ impl Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dependencies(&self) -> &IndexMap<String, deno_graph::Dependency> {
|
pub fn dependencies(&self) -> &IndexMap<String, deno_graph::Dependency> {
|
||||||
&self.dependencies.deps
|
self.dependencies.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the supplied position is within a dependency range, return the resolved
|
/// If the supplied position is within a dependency range, return the resolved
|
||||||
|
@ -601,12 +610,11 @@ impl Document {
|
||||||
&self,
|
&self,
|
||||||
position: &lsp::Position,
|
position: &lsp::Position,
|
||||||
) -> Option<(String, deno_graph::Dependency, deno_graph::Range)> {
|
) -> Option<(String, deno_graph::Dependency, deno_graph::Range)> {
|
||||||
let module = self.maybe_js_module()?.as_ref().ok()?;
|
|
||||||
let position = deno_graph::Position {
|
let position = deno_graph::Position {
|
||||||
line: position.line as usize,
|
line: position.line as usize,
|
||||||
character: position.character as usize,
|
character: position.character as usize,
|
||||||
};
|
};
|
||||||
module.dependencies.iter().find_map(|(s, dep)| {
|
self.dependencies().iter().find_map(|(s, dep)| {
|
||||||
dep
|
dep
|
||||||
.includes(&position)
|
.includes(&position)
|
||||||
.map(|r| (s.clone(), dep.clone(), r.clone()))
|
.map(|r| (s.clone(), dep.clone(), r.clone()))
|
||||||
|
@ -1207,7 +1215,8 @@ impl Documents {
|
||||||
referrer: &ModuleSpecifier,
|
referrer: &ModuleSpecifier,
|
||||||
maybe_npm: Option<&StateNpmSnapshot>,
|
maybe_npm: Option<&StateNpmSnapshot>,
|
||||||
) -> Vec<Option<(ModuleSpecifier, MediaType)>> {
|
) -> Vec<Option<(ModuleSpecifier, MediaType)>> {
|
||||||
let dependencies = self.get(referrer).map(|d| d.dependencies.clone());
|
let document = self.get(referrer);
|
||||||
|
let dependencies = document.as_ref().map(|d| d.dependencies());
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
for specifier in specifiers {
|
for specifier in specifiers {
|
||||||
if let Some(npm) = maybe_npm {
|
if let Some(npm) = maybe_npm {
|
||||||
|
@ -1236,7 +1245,7 @@ impl Documents {
|
||||||
results.push(None);
|
results.push(None);
|
||||||
}
|
}
|
||||||
} else if let Some(dep) =
|
} else if let Some(dep) =
|
||||||
dependencies.as_ref().and_then(|d| d.deps.get(specifier))
|
dependencies.as_ref().and_then(|d| d.get(specifier))
|
||||||
{
|
{
|
||||||
if let Some(specifier) = dep.maybe_type.maybe_specifier() {
|
if let Some(specifier) = dep.maybe_type.maybe_specifier() {
|
||||||
results.push(self.resolve_dependency(specifier, maybe_npm, referrer));
|
results.push(self.resolve_dependency(specifier, maybe_npm, referrer));
|
||||||
|
@ -1540,12 +1549,7 @@ impl Documents {
|
||||||
let Some(doc) = self.get(specifier) else {
|
let Some(doc) = self.get(specifier) else {
|
||||||
return Some((specifier.clone(), MediaType::from_specifier(specifier)));
|
return Some((specifier.clone(), MediaType::from_specifier(specifier)));
|
||||||
};
|
};
|
||||||
let maybe_module = doc.maybe_js_module().and_then(|r| r.as_ref().ok());
|
if let Some(specifier) = doc.maybe_types_dependency().maybe_specifier() {
|
||||||
let maybe_types_dependency = maybe_module
|
|
||||||
.and_then(|m| m.maybe_types_dependency.as_ref().map(|d| &d.dependency));
|
|
||||||
if let Some(specifier) =
|
|
||||||
maybe_types_dependency.and_then(|d| d.maybe_specifier())
|
|
||||||
{
|
|
||||||
self.resolve_dependency(specifier, maybe_npm, referrer)
|
self.resolve_dependency(specifier, maybe_npm, referrer)
|
||||||
} else {
|
} else {
|
||||||
let media_type = doc.media_type();
|
let media_type = doc.media_type();
|
||||||
|
@ -1643,7 +1647,7 @@ impl<'a> OpenDocumentsGraphLoader<'a> {
|
||||||
|
|
||||||
impl<'a> deno_graph::source::Loader for OpenDocumentsGraphLoader<'a> {
|
impl<'a> deno_graph::source::Loader for OpenDocumentsGraphLoader<'a> {
|
||||||
fn load(
|
fn load(
|
||||||
&mut self,
|
&self,
|
||||||
specifier: &ModuleSpecifier,
|
specifier: &ModuleSpecifier,
|
||||||
options: deno_graph::source::LoadOptions,
|
options: deno_graph::source::LoadOptions,
|
||||||
) -> deno_graph::source::LoadFuture {
|
) -> deno_graph::source::LoadFuture {
|
||||||
|
@ -1662,7 +1666,7 @@ impl<'a> deno_graph::source::Loader for OpenDocumentsGraphLoader<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cache_module_info(
|
fn cache_module_info(
|
||||||
&mut self,
|
&self,
|
||||||
specifier: &deno_ast::ModuleSpecifier,
|
specifier: &deno_ast::ModuleSpecifier,
|
||||||
source: &Arc<[u8]>,
|
source: &Arc<[u8]>,
|
||||||
module_info: &deno_graph::ModuleInfo,
|
module_info: &deno_graph::ModuleInfo,
|
||||||
|
@ -1717,7 +1721,7 @@ fn analyze_module(
|
||||||
match parsed_source_result {
|
match parsed_source_result {
|
||||||
Ok(parsed_source) => Ok(deno_graph::parse_module_from_ast(
|
Ok(parsed_source) => Ok(deno_graph::parse_module_from_ast(
|
||||||
deno_graph::ParseModuleFromAstOptions {
|
deno_graph::ParseModuleFromAstOptions {
|
||||||
graph_kind: deno_graph::GraphKind::All,
|
graph_kind: deno_graph::GraphKind::TypesOnly,
|
||||||
specifier,
|
specifier,
|
||||||
maybe_headers,
|
maybe_headers,
|
||||||
parsed_source,
|
parsed_source,
|
||||||
|
|
|
@ -1610,10 +1610,9 @@ impl Inner {
|
||||||
let hover = if let Some((_, dep, range)) = asset_or_doc
|
let hover = if let Some((_, dep, range)) = asset_or_doc
|
||||||
.get_maybe_dependency(¶ms.text_document_position_params.position)
|
.get_maybe_dependency(¶ms.text_document_position_params.position)
|
||||||
{
|
{
|
||||||
let dep_maybe_types_dependency = dep
|
let dep_doc = dep.get_code().and_then(|s| self.documents.get(s));
|
||||||
.get_code()
|
let dep_maybe_types_dependency =
|
||||||
.and_then(|s| self.documents.get(s))
|
dep_doc.as_ref().map(|d| d.maybe_types_dependency());
|
||||||
.map(|d| d.maybe_types_dependency());
|
|
||||||
let value = match (dep.maybe_code.is_none(), dep.maybe_type.is_none(), &dep_maybe_types_dependency) {
|
let value = match (dep.maybe_code.is_none(), dep.maybe_type.is_none(), &dep_maybe_types_dependency) {
|
||||||
(false, false, None) => format!(
|
(false, false, None) => format!(
|
||||||
"**Resolved Dependency**\n\n**Code**: {}\n\n**Types**: {}\n",
|
"**Resolved Dependency**\n\n**Code**: {}\n\n**Types**: {}\n",
|
||||||
|
|
|
@ -37,7 +37,7 @@ async fn generate_doc_nodes_for_builtin_types(
|
||||||
let source_file_specifier =
|
let source_file_specifier =
|
||||||
ModuleSpecifier::parse("internal://lib.deno.d.ts").unwrap();
|
ModuleSpecifier::parse("internal://lib.deno.d.ts").unwrap();
|
||||||
let content = get_types_declaration_file_text();
|
let content = get_types_declaration_file_text();
|
||||||
let mut loader = deno_graph::source::MemoryLoader::new(
|
let loader = deno_graph::source::MemoryLoader::new(
|
||||||
vec![(
|
vec![(
|
||||||
source_file_specifier.to_string(),
|
source_file_specifier.to_string(),
|
||||||
deno_graph::source::Source::Module {
|
deno_graph::source::Source::Module {
|
||||||
|
@ -52,7 +52,7 @@ async fn generate_doc_nodes_for_builtin_types(
|
||||||
graph
|
graph
|
||||||
.build(
|
.build(
|
||||||
vec![source_file_specifier.clone()],
|
vec![source_file_specifier.clone()],
|
||||||
&mut loader,
|
&loader,
|
||||||
deno_graph::BuildOptions {
|
deno_graph::BuildOptions {
|
||||||
module_analyzer: analyzer,
|
module_analyzer: analyzer,
|
||||||
file_system: &NullFileSystem,
|
file_system: &NullFileSystem,
|
||||||
|
@ -60,6 +60,7 @@ async fn generate_doc_nodes_for_builtin_types(
|
||||||
imports: Vec::new(),
|
imports: Vec::new(),
|
||||||
executor: Default::default(),
|
executor: Default::default(),
|
||||||
jsr_url_provider: Default::default(),
|
jsr_url_provider: Default::default(),
|
||||||
|
passthrough_jsr_specifiers: false,
|
||||||
npm_resolver: None,
|
npm_resolver: None,
|
||||||
reporter: None,
|
reporter: None,
|
||||||
resolver: None,
|
resolver: None,
|
||||||
|
|
|
@ -627,6 +627,7 @@ impl ReplSession {
|
||||||
imports_not_used_as_values: ImportsNotUsedAsValues::Preserve,
|
imports_not_used_as_values: ImportsNotUsedAsValues::Preserve,
|
||||||
transform_jsx: true,
|
transform_jsx: true,
|
||||||
precompile_jsx: false,
|
precompile_jsx: false,
|
||||||
|
precompile_jsx_skip_elements: None,
|
||||||
jsx_automatic: self.jsx.import_source.is_some(),
|
jsx_automatic: self.jsx.import_source.is_some(),
|
||||||
jsx_development: false,
|
jsx_development: false,
|
||||||
jsx_factory: self.jsx.factory.clone(),
|
jsx_factory: self.jsx.factory.clone(),
|
||||||
|
|
6
cli/tools/vendor/test.rs
vendored
6
cli/tools/vendor/test.rs
vendored
|
@ -112,7 +112,7 @@ impl TestLoader {
|
||||||
|
|
||||||
impl Loader for TestLoader {
|
impl Loader for TestLoader {
|
||||||
fn load(
|
fn load(
|
||||||
&mut self,
|
&self,
|
||||||
specifier: &ModuleSpecifier,
|
specifier: &ModuleSpecifier,
|
||||||
_options: deno_graph::source::LoadOptions,
|
_options: deno_graph::source::LoadOptions,
|
||||||
) -> LoadFuture {
|
) -> LoadFuture {
|
||||||
|
@ -298,7 +298,7 @@ fn build_resolver(
|
||||||
|
|
||||||
async fn build_test_graph(
|
async fn build_test_graph(
|
||||||
roots: Vec<ModuleSpecifier>,
|
roots: Vec<ModuleSpecifier>,
|
||||||
mut loader: TestLoader,
|
loader: TestLoader,
|
||||||
resolver: &dyn deno_graph::source::Resolver,
|
resolver: &dyn deno_graph::source::Resolver,
|
||||||
analyzer: &dyn deno_graph::ModuleAnalyzer,
|
analyzer: &dyn deno_graph::ModuleAnalyzer,
|
||||||
) -> ModuleGraph {
|
) -> ModuleGraph {
|
||||||
|
@ -306,7 +306,7 @@ async fn build_test_graph(
|
||||||
graph
|
graph
|
||||||
.build(
|
.build(
|
||||||
roots,
|
roots,
|
||||||
&mut loader,
|
&loader,
|
||||||
deno_graph::BuildOptions {
|
deno_graph::BuildOptions {
|
||||||
resolver: Some(resolver),
|
resolver: Some(resolver),
|
||||||
module_analyzer: analyzer,
|
module_analyzer: analyzer,
|
||||||
|
|
|
@ -957,7 +957,7 @@ mod tests {
|
||||||
|
|
||||||
impl deno_graph::source::Loader for MockLoader {
|
impl deno_graph::source::Loader for MockLoader {
|
||||||
fn load(
|
fn load(
|
||||||
&mut self,
|
&self,
|
||||||
specifier: &ModuleSpecifier,
|
specifier: &ModuleSpecifier,
|
||||||
_options: deno_graph::source::LoadOptions,
|
_options: deno_graph::source::LoadOptions,
|
||||||
) -> deno_graph::source::LoadFuture {
|
) -> deno_graph::source::LoadFuture {
|
||||||
|
@ -987,10 +987,10 @@ mod tests {
|
||||||
.unwrap_or_else(|| ModuleSpecifier::parse("file:///main.ts").unwrap());
|
.unwrap_or_else(|| ModuleSpecifier::parse("file:///main.ts").unwrap());
|
||||||
let hash_data = maybe_hash_data.unwrap_or(0);
|
let hash_data = maybe_hash_data.unwrap_or(0);
|
||||||
let fixtures = test_util::testdata_path().join("tsc2");
|
let fixtures = test_util::testdata_path().join("tsc2");
|
||||||
let mut loader = MockLoader { fixtures };
|
let loader = MockLoader { fixtures };
|
||||||
let mut graph = ModuleGraph::new(GraphKind::TypesOnly);
|
let mut graph = ModuleGraph::new(GraphKind::TypesOnly);
|
||||||
graph
|
graph
|
||||||
.build(vec![specifier], &mut loader, Default::default())
|
.build(vec![specifier], &loader, Default::default())
|
||||||
.await;
|
.await;
|
||||||
let state = State::new(
|
let state = State::new(
|
||||||
Arc::new(graph),
|
Arc::new(graph),
|
||||||
|
@ -1013,10 +1013,10 @@ mod tests {
|
||||||
) -> Result<Response, AnyError> {
|
) -> Result<Response, AnyError> {
|
||||||
let hash_data = 123; // something random
|
let hash_data = 123; // something random
|
||||||
let fixtures = test_util::testdata_path().join("tsc2");
|
let fixtures = test_util::testdata_path().join("tsc2");
|
||||||
let mut loader = MockLoader { fixtures };
|
let loader = MockLoader { fixtures };
|
||||||
let mut graph = ModuleGraph::new(GraphKind::TypesOnly);
|
let mut graph = ModuleGraph::new(GraphKind::TypesOnly);
|
||||||
graph
|
graph
|
||||||
.build(vec![specifier.clone()], &mut loader, Default::default())
|
.build(vec![specifier.clone()], &loader, Default::default())
|
||||||
.await;
|
.await;
|
||||||
let config = TsConfig::new(json!({
|
let config = TsConfig::new(json!({
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
|
|
Loading…
Reference in a new issue