"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "cli/lsp/sources.rs" between
deno-1.10.3.tar.gz and deno-1.11.0.tar.gz

About: Deno is is a simple, modern and secure runtime for JavaScript and TypeScript that uses the V8 JavaScript engine and is built in Rust.

sources.rs  (deno-1.10.3):sources.rs  (deno-1.11.0)
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use super::analysis; use super::analysis;
use super::text::LineIndex; use super::text::LineIndex;
use super::tsc;
use crate::file_fetcher::get_source_from_bytes; use crate::file_fetcher::get_source_from_bytes;
use crate::file_fetcher::map_content_type; use crate::file_fetcher::map_content_type;
use crate::file_fetcher::SUPPORTED_SCHEMES; use crate::file_fetcher::SUPPORTED_SCHEMES;
use crate::http_cache; use crate::http_cache;
use crate::http_cache::HttpCache; use crate::http_cache::HttpCache;
use crate::import_map::ImportMap; use crate::import_map::ImportMap;
use crate::media_type::MediaType; use crate::media_type::MediaType;
use crate::module_graph::GraphBuilder; use crate::module_graph::GraphBuilder;
use crate::program_state::ProgramState; use crate::program_state::ProgramState;
use crate::specifier_handler::FetchHandler; use crate::specifier_handler::FetchHandler;
use crate::text_encoding; use crate::text_encoding;
use deno_core::error::anyhow;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::serde_json; use deno_core::serde_json;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_runtime::permissions::Permissions; use deno_runtime::permissions::Permissions;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
use std::time::SystemTime; use std::time::SystemTime;
use tsc::NavigationTree;
pub async fn cache( pub async fn cache(
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
maybe_import_map: &Option<ImportMap>, maybe_import_map: &Option<ImportMap>,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let program_state = Arc::new(ProgramState::build(Default::default()).await?); let program_state = Arc::new(ProgramState::build(Default::default()).await?);
let handler = Arc::new(Mutex::new(FetchHandler::new( let handler = Arc::new(Mutex::new(FetchHandler::new(
&program_state, &program_state,
Permissions::allow_all(), Permissions::allow_all(),
Permissions::allow_all(), Permissions::allow_all(),
skipping to change at line 107 skipping to change at line 110
redirects.insert(specifier.clone(), redirect.clone()); redirects.insert(specifier.clone(), redirect.clone());
Some(redirect) Some(redirect)
} }
} }
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
struct Metadata { struct Metadata {
dependencies: Option<HashMap<String, analysis::Dependency>>, dependencies: Option<HashMap<String, analysis::Dependency>>,
length_utf16: usize, length_utf16: usize,
line_index: LineIndex, line_index: LineIndex,
maybe_navigation_tree: Option<tsc::NavigationTree>,
maybe_types: Option<analysis::ResolvedDependency>, maybe_types: Option<analysis::ResolvedDependency>,
maybe_warning: Option<String>, maybe_warning: Option<String>,
media_type: MediaType, media_type: MediaType,
source: String, source: String,
version: String, version: String,
} }
impl Metadata { impl Metadata {
fn new( fn new(
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
skipping to change at line 142 skipping to change at line 146
(Some(deps), maybe_types) (Some(deps), maybe_types)
} else { } else {
(None, None) (None, None)
}; };
let line_index = LineIndex::new(source); let line_index = LineIndex::new(source);
Self { Self {
dependencies, dependencies,
length_utf16: source.encode_utf16().count(), length_utf16: source.encode_utf16().count(),
line_index, line_index,
maybe_navigation_tree: None,
maybe_types, maybe_types,
maybe_warning, maybe_warning,
media_type: media_type.to_owned(), media_type: media_type.to_owned(),
source: source.to_string(), source: source.to_string(),
version: version.to_string(), version: version.to_string(),
} }
} }
} }
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
skipping to change at line 200 skipping to change at line 205
self.0.lock().unwrap().get_maybe_warning(specifier) self.0.lock().unwrap().get_maybe_warning(specifier)
} }
pub fn get_media_type( pub fn get_media_type(
&self, &self,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
) -> Option<MediaType> { ) -> Option<MediaType> {
self.0.lock().unwrap().get_media_type(specifier) self.0.lock().unwrap().get_media_type(specifier)
} }
pub fn get_navigation_tree(
&self,
specifier: &ModuleSpecifier,
) -> Option<tsc::NavigationTree> {
self.0.lock().unwrap().get_navigation_tree(specifier)
}
pub fn get_script_version( pub fn get_script_version(
&self, &self,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
) -> Option<String> { ) -> Option<String> {
self.0.lock().unwrap().get_script_version(specifier) self.0.lock().unwrap().get_script_version(specifier)
} }
pub fn get_source(&self, specifier: &ModuleSpecifier) -> Option<String> { pub fn get_source(&self, specifier: &ModuleSpecifier) -> Option<String> {
self.0.lock().unwrap().get_source(specifier) self.0.lock().unwrap().get_source(specifier)
} }
skipping to change at line 226 skipping to change at line 238
&self, &self,
specifier: &str, specifier: &str,
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
) -> Option<(ModuleSpecifier, MediaType)> { ) -> Option<(ModuleSpecifier, MediaType)> {
self.0.lock().unwrap().resolve_import(specifier, referrer) self.0.lock().unwrap().resolve_import(specifier, referrer)
} }
pub fn specifiers(&self) -> Vec<ModuleSpecifier> { pub fn specifiers(&self) -> Vec<ModuleSpecifier> {
self.0.lock().unwrap().metadata.keys().cloned().collect() self.0.lock().unwrap().metadata.keys().cloned().collect()
} }
pub fn set_navigation_tree(
&self,
specifier: &ModuleSpecifier,
navigation_tree: tsc::NavigationTree,
) -> Result<(), AnyError> {
self
.0
.lock()
.unwrap()
.set_navigation_tree(specifier, navigation_tree)
}
} }
impl Inner { impl Inner {
fn new(location: &Path) -> Self { fn new(location: &Path) -> Self {
Self { Self {
http_cache: HttpCache::new(location), http_cache: HttpCache::new(location),
..Default::default() ..Default::default()
} }
} }
skipping to change at line 346 skipping to change at line 370
maybe_warning, maybe_warning,
&self.maybe_import_map, &self.maybe_import_map,
); );
if maybe_types.is_some() { if maybe_types.is_some() {
metadata.maybe_types = maybe_types; metadata.maybe_types = maybe_types;
} }
self.metadata.insert(specifier.clone(), metadata.clone()); self.metadata.insert(specifier.clone(), metadata.clone());
Some(metadata) Some(metadata)
} }
fn get_navigation_tree(
&mut self,
specifier: &ModuleSpecifier,
) -> Option<tsc::NavigationTree> {
let specifier =
resolve_specifier(specifier, &mut self.redirects, &self.http_cache)?;
let metadata = self.get_metadata(&specifier)?;
metadata.maybe_navigation_tree
}
fn get_path(&mut self, specifier: &ModuleSpecifier) -> Option<PathBuf> { fn get_path(&mut self, specifier: &ModuleSpecifier) -> Option<PathBuf> {
if specifier.scheme() == "file" { if specifier.scheme() == "file" {
specifier.to_file_path().ok() specifier.to_file_path().ok()
} else if let Some(path) = self.remotes.get(&specifier) { } else if let Some(path) = self.remotes.get(&specifier) {
Some(path.clone()) Some(path.clone())
} else { } else {
let path = self.http_cache.get_cache_filename(&specifier)?; let path = self.http_cache.get_cache_filename(&specifier)?;
if path.is_file() { if path.is_file() {
self.remotes.insert(specifier.clone(), path.clone()); self.remotes.insert(specifier.clone(), path.clone());
Some(path) Some(path)
skipping to change at line 464 skipping to change at line 498
dependency: &analysis::ResolvedDependency, dependency: &analysis::ResolvedDependency,
) { ) {
if let Some(metadata) = self.metadata.get_mut(referrer) { if let Some(metadata) = self.metadata.get_mut(referrer) {
if let Some(dependencies) = &mut metadata.dependencies { if let Some(dependencies) = &mut metadata.dependencies {
if let Some(dep) = dependencies.get_mut(specifier) { if let Some(dep) = dependencies.get_mut(specifier) {
dep.maybe_type = Some(dependency.clone()); dep.maybe_type = Some(dependency.clone());
} }
} }
} }
} }
fn set_navigation_tree(
&mut self,
specifier: &ModuleSpecifier,
navigation_tree: NavigationTree,
) -> Result<(), AnyError> {
let mut metadata = self
.metadata
.get_mut(specifier)
.ok_or_else(|| anyhow!("Specifier not found {}"))?;
metadata.maybe_navigation_tree = Some(navigation_tree);
Ok(())
}
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use deno_core::resolve_path; use deno_core::resolve_path;
use deno_core::resolve_url; use deno_core::resolve_url;
use std::env; use std::env;
use tempfile::TempDir; use tempfile::TempDir;
 End of changes. 9 change blocks. 
0 lines changed or deleted 47 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)