summaryrefslogtreecommitdiff
path: root/cli/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp')
-rw-r--r--cli/lsp/cache.rs12
-rw-r--r--cli/lsp/completions.rs8
-rw-r--r--cli/lsp/config.rs7
-rw-r--r--cli/lsp/documents.rs13
-rw-r--r--cli/lsp/language_server.rs41
-rw-r--r--cli/lsp/registries.rs4
-rw-r--r--cli/lsp/testing/definitions.rs2
-rw-r--r--cli/lsp/testing/execution.rs2
-rw-r--r--cli/lsp/tsc.rs6
-rw-r--r--cli/lsp/urls.rs2
10 files changed, 49 insertions, 48 deletions
diff --git a/cli/lsp/cache.rs b/cli/lsp/cache.rs
index c4512a803..7f7f69871 100644
--- a/cli/lsp/cache.rs
+++ b/cli/lsp/cache.rs
@@ -1,6 +1,7 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
-use crate::http_cache;
+use crate::cache::CachedUrlMetadata;
+use crate::cache::HttpCache;
use deno_core::parking_lot::Mutex;
use deno_core::ModuleSpecifier;
@@ -49,14 +50,14 @@ struct Metadata {
#[derive(Debug, Default, Clone)]
pub struct CacheMetadata {
- cache: http_cache::HttpCache,
+ cache: HttpCache,
metadata: Arc<Mutex<HashMap<ModuleSpecifier, Metadata>>>,
}
impl CacheMetadata {
pub fn new(location: &Path) -> Self {
Self {
- cache: http_cache::HttpCache::new(location),
+ cache: HttpCache::new(location),
metadata: Default::default(),
}
}
@@ -87,8 +88,7 @@ impl CacheMetadata {
return None;
}
let cache_filename = self.cache.get_cache_filename(specifier)?;
- let specifier_metadata =
- http_cache::Metadata::read(&cache_filename).ok()?;
+ let specifier_metadata = CachedUrlMetadata::read(&cache_filename).ok()?;
let values = Arc::new(parse_metadata(&specifier_metadata.headers));
let version = calculate_fs_version(&cache_filename);
let mut metadata_map = self.metadata.lock();
@@ -98,7 +98,7 @@ impl CacheMetadata {
}
pub fn set_location(&mut self, location: &Path) {
- self.cache = http_cache::HttpCache::new(location);
+ self.cache = HttpCache::new(location);
self.metadata.lock().clear();
}
}
diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs
index 67978fbc9..5e0fad0f4 100644
--- a/cli/lsp/completions.rs
+++ b/cli/lsp/completions.rs
@@ -7,9 +7,9 @@ use super::lsp_custom;
use super::registries::ModuleRegistry;
use super::tsc;
-use crate::fs_util::is_supported_ext;
-use crate::fs_util::relative_specifier;
-use crate::fs_util::specifier_to_file_path;
+use crate::util::path::is_supported_ext;
+use crate::util::path::relative_specifier;
+use crate::util::path::specifier_to_file_path;
use deno_ast::LineAndColumnIndex;
use deno_ast::SourceTextInfo;
@@ -505,7 +505,7 @@ fn get_workspace_completions(
#[cfg(test)]
mod tests {
use super::*;
- use crate::http_cache::HttpCache;
+ use crate::cache::HttpCache;
use crate::lsp::documents::Documents;
use crate::lsp::documents::LanguageId;
use deno_core::resolve_url;
diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs
index 04a48435f..8d5da46b7 100644
--- a/cli/lsp/config.rs
+++ b/cli/lsp/config.rs
@@ -2,7 +2,8 @@
use super::client::Client;
use super::logging::lsp_log;
-use crate::fs_util;
+use crate::util::path::ensure_directory_specifier;
+use crate::util::path::specifier_to_file_path;
use deno_core::error::AnyError;
use deno_core::serde::Deserialize;
use deno_core::serde::Serialize;
@@ -549,11 +550,11 @@ impl Config {
workspace: &ModuleSpecifier,
enabled_paths: Vec<String>,
) -> bool {
- let workspace = fs_util::ensure_directory_specifier(workspace.clone());
+ let workspace = ensure_directory_specifier(workspace.clone());
let key = workspace.to_string();
let mut touched = false;
if !enabled_paths.is_empty() {
- if let Ok(workspace_path) = fs_util::specifier_to_file_path(&workspace) {
+ if let Ok(workspace_path) = specifier_to_file_path(&workspace) {
let mut paths = Vec::new();
for path in &enabled_paths {
let fs_path = workspace_path.join(path);
diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs
index 5c1e60e73..ce8fead0d 100644
--- a/cli/lsp/documents.rs
+++ b/cli/lsp/documents.rs
@@ -6,12 +6,11 @@ use super::tsc;
use super::tsc::AssetDocument;
use crate::args::ConfigFile;
+use crate::cache::CachedUrlMetadata;
+use crate::cache::HttpCache;
use crate::file_fetcher::get_source_from_bytes;
use crate::file_fetcher::map_content_type;
use crate::file_fetcher::SUPPORTED_SCHEMES;
-use crate::fs_util::specifier_to_file_path;
-use crate::http_cache;
-use crate::http_cache::HttpCache;
use crate::node;
use crate::node::node_resolve_npm_reference;
use crate::node::NodeResolution;
@@ -20,7 +19,8 @@ use crate::npm::NpmPackageReference;
use crate::npm::NpmPackageReq;
use crate::npm::NpmPackageResolver;
use crate::resolver::CliResolver;
-use crate::text_encoding;
+use crate::util::path::specifier_to_file_path;
+use crate::util::text_encoding;
use deno_ast::MediaType;
use deno_ast::ParsedSource;
@@ -610,7 +610,7 @@ impl SpecifierResolver {
) -> Option<ModuleSpecifier> {
let cache_filename = self.cache.get_cache_filename(specifier)?;
if redirect_limit > 0 && cache_filename.is_file() {
- let headers = http_cache::Metadata::read(&cache_filename)
+ let headers = CachedUrlMetadata::read(&cache_filename)
.ok()
.map(|m| m.headers)?;
if let Some(location) = headers.get("location") {
@@ -657,8 +657,7 @@ impl FileSystemDocuments {
)
} else {
let cache_filename = cache.get_cache_filename(specifier)?;
- let specifier_metadata =
- http_cache::Metadata::read(&cache_filename).ok()?;
+ let specifier_metadata = CachedUrlMetadata::read(&cache_filename).ok()?;
let maybe_content_type =
specifier_metadata.headers.get("content-type").cloned();
let maybe_headers = Some(&specifier_metadata.headers);
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 081bbf429..11897af9d 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -57,6 +57,8 @@ use super::tsc::Assets;
use super::tsc::AssetsSnapshot;
use super::tsc::TsServer;
use super::urls;
+use crate::args::get_root_cert_store;
+use crate::args::CacheSetting;
use crate::args::CliOptions;
use crate::args::ConfigFile;
use crate::args::Flags;
@@ -64,10 +66,7 @@ use crate::args::FmtConfig;
use crate::args::LintConfig;
use crate::args::TsConfig;
use crate::cache::DenoDir;
-use crate::file_fetcher::get_root_cert_store;
use crate::file_fetcher::get_source_from_data_url;
-use crate::file_fetcher::CacheSetting;
-use crate::fs_util;
use crate::graph_util::graph_valid;
use crate::http_util::HttpClient;
use crate::npm::NpmCache;
@@ -75,9 +74,12 @@ use crate::npm::NpmPackageResolver;
use crate::npm::RealNpmRegistryApi;
use crate::proc_state::import_map_from_text;
use crate::proc_state::ProcState;
-use crate::progress_bar::ProgressBar;
use crate::tools::fmt::format_file;
use crate::tools::fmt::format_parsed_source;
+use crate::util::fs::remove_dir_all_if_exists;
+use crate::util::path::ensure_directory_specifier;
+use crate::util::path::specifier_to_file_path;
+use crate::util::progress_bar::ProgressBar;
#[derive(Debug, Clone)]
pub struct LanguageServer(Arc<tokio::sync::Mutex<Inner>>);
@@ -407,7 +409,7 @@ impl Inner {
// file open and not a workspace. In those situations we can't
// automatically discover the configuration
if let Some(root_uri) = &self.config.root_uri {
- let root_path = fs_util::specifier_to_file_path(root_uri)?;
+ let root_path = specifier_to_file_path(root_uri)?;
let mut checked = std::collections::HashSet::new();
let maybe_config = ConfigFile::discover_from(&root_path, &mut checked)?;
Ok(maybe_config.map(|c| {
@@ -481,7 +483,7 @@ impl Inner {
let cache_url = if let Ok(url) = Url::from_file_path(cache_str) {
Ok(url)
} else if let Some(root_uri) = &self.config.root_uri {
- let root_path = fs_util::specifier_to_file_path(root_uri)?;
+ let root_path = specifier_to_file_path(root_uri)?;
let cache_path = root_path.join(cache_str);
Url::from_file_path(cache_path).map_err(|_| {
anyhow!("Bad file path for import path: {:?}", cache_str)
@@ -492,7 +494,7 @@ impl Inner {
cache_str
))
}?;
- let cache_path = fs_util::specifier_to_file_path(&cache_url)?;
+ let cache_path = specifier_to_file_path(&cache_url)?;
lsp_log!(
" Resolved cache path: \"{}\"",
cache_path.to_string_lossy()
@@ -521,7 +523,7 @@ impl Inner {
.config
.root_uri
.as_ref()
- .and_then(|uri| fs_util::specifier_to_file_path(uri).ok());
+ .and_then(|uri| specifier_to_file_path(uri).ok());
let root_cert_store = Some(get_root_cert_store(
maybe_root_path,
workspace_settings.certificate_stores.clone(),
@@ -569,7 +571,7 @@ impl Inner {
anyhow!("Bad data url for import map: {}", import_map_str)
})?)
} else if let Some(root_uri) = &self.config.root_uri {
- let root_path = fs_util::specifier_to_file_path(root_uri)?;
+ let root_path = specifier_to_file_path(root_uri)?;
let import_map_path = root_path.join(&import_map_str);
Some(Url::from_file_path(import_map_path).map_err(|_| {
anyhow!("Bad file path for import map: {}", import_map_str)
@@ -612,7 +614,7 @@ impl Inner {
let import_map_json = if import_map_url.scheme() == "data" {
get_source_from_data_url(&import_map_url)?.0
} else {
- let import_map_path = fs_util::specifier_to_file_path(&import_map_url)?;
+ let import_map_path = specifier_to_file_path(&import_map_url)?;
lsp_log!(
" Resolved import map: \"{}\"",
import_map_path.to_string_lossy()
@@ -768,7 +770,7 @@ impl Inner {
self.config.root_uri = params
.root_uri
.map(|s| self.url_map.normalize_url(&s))
- .map(fs_util::ensure_directory_specifier);
+ .map(ensure_directory_specifier);
if let Some(value) = params.initialization_options {
self.config.set_workspace_settings(value).map_err(|err| {
@@ -1137,11 +1139,10 @@ impl Inner {
_ => return Ok(None),
};
let mark = self.performance.mark("formatting", Some(&params));
- let file_path =
- fs_util::specifier_to_file_path(&specifier).map_err(|err| {
- error!("{}", err);
- LspError::invalid_request()
- })?;
+ let file_path = specifier_to_file_path(&specifier).map_err(|err| {
+ error!("{}", err);
+ LspError::invalid_request()
+ })?;
let fmt_options = if let Some(fmt_config) = self.maybe_fmt_config.as_ref() {
// skip formatting any files ignored by the config file
@@ -2063,7 +2064,7 @@ impl Inner {
.config
.root_uri
.as_ref()
- .and_then(|uri| fs_util::specifier_to_file_path(uri).ok());
+ .and_then(|uri| specifier_to_file_path(uri).ok());
let mut resolved_items = Vec::<CallHierarchyIncomingCall>::new();
for item in incoming_calls.iter() {
if let Some(resolved) = item.try_resolve_call_hierarchy_incoming_call(
@@ -2109,7 +2110,7 @@ impl Inner {
.config
.root_uri
.as_ref()
- .and_then(|uri| fs_util::specifier_to_file_path(uri).ok());
+ .and_then(|uri| specifier_to_file_path(uri).ok());
let mut resolved_items = Vec::<CallHierarchyOutgoingCall>::new();
for item in outgoing_calls.iter() {
if let Some(resolved) = item.try_resolve_call_hierarchy_outgoing_call(
@@ -2162,7 +2163,7 @@ impl Inner {
.config
.root_uri
.as_ref()
- .and_then(|uri| fs_util::specifier_to_file_path(uri).ok());
+ .and_then(|uri| specifier_to_file_path(uri).ok());
let mut resolved_items = Vec::<CallHierarchyItem>::new();
match one_or_many {
tsc::OneOrMany::One(item) => {
@@ -3010,7 +3011,7 @@ impl Inner {
}
async fn reload_import_registries(&mut self) -> LspResult<Option<Value>> {
- fs_util::remove_dir_all_if_exists(&self.module_registries_location)
+ remove_dir_all_if_exists(&self.module_registries_location)
.await
.map_err(|err| {
error!("Unable to remove registries cache: {}", err);
diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs
index 43500e697..1488077dd 100644
--- a/cli/lsp/registries.rs
+++ b/cli/lsp/registries.rs
@@ -12,10 +12,10 @@ use super::path_to_regex::StringOrNumber;
use super::path_to_regex::StringOrVec;
use super::path_to_regex::Token;
+use crate::args::CacheSetting;
use crate::cache::DenoDir;
-use crate::file_fetcher::CacheSetting;
+use crate::cache::HttpCache;
use crate::file_fetcher::FileFetcher;
-use crate::http_cache::HttpCache;
use crate::http_util::HttpClient;
use deno_core::anyhow::anyhow;
diff --git a/cli/lsp/testing/definitions.rs b/cli/lsp/testing/definitions.rs
index 14ac165fd..a2cd78012 100644
--- a/cli/lsp/testing/definitions.rs
+++ b/cli/lsp/testing/definitions.rs
@@ -2,9 +2,9 @@
use super::lsp_custom;
-use crate::checksum;
use crate::lsp::analysis::source_range_to_lsp_range;
use crate::lsp::client::TestingNotification;
+use crate::util::checksum;
use deno_ast::SourceRange;
use deno_ast::SourceTextInfo;
diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs
index d839cda56..bd4f07621 100644
--- a/cli/lsp/testing/execution.rs
+++ b/cli/lsp/testing/execution.rs
@@ -6,7 +6,6 @@ use super::lsp_custom;
use crate::args::flags_from_vec;
use crate::args::DenoSubcommand;
-use crate::checksum;
use crate::lsp::client::Client;
use crate::lsp::client::TestingNotification;
use crate::lsp::config;
@@ -15,6 +14,7 @@ use crate::ops;
use crate::proc_state;
use crate::tools::test;
use crate::tools::test::TestEventSender;
+use crate::util::checksum;
use crate::worker::create_main_worker_for_test_or_bench;
use deno_core::anyhow::anyhow;
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 4bb5ae5f9..88de60131 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -18,10 +18,10 @@ use super::urls::LspUrlMap;
use super::urls::INVALID_SPECIFIER;
use crate::args::TsConfig;
-use crate::fs_util::relative_specifier;
-use crate::fs_util::specifier_to_file_path;
use crate::tsc;
use crate::tsc::ResolveArgs;
+use crate::util::path::relative_specifier;
+use crate::util::path::specifier_to_file_path;
use deno_core::anyhow::anyhow;
use deno_core::error::custom_error;
@@ -3445,7 +3445,7 @@ pub fn request(
#[cfg(test)]
mod tests {
use super::*;
- use crate::http_cache::HttpCache;
+ use crate::cache::HttpCache;
use crate::http_util::HeadersMap;
use crate::lsp::config::WorkspaceSettings;
use crate::lsp::documents::Documents;
diff --git a/cli/lsp/urls.rs b/cli/lsp/urls.rs
index 9b14098ae..5aed54ad5 100644
--- a/cli/lsp/urls.rs
+++ b/cli/lsp/urls.rs
@@ -56,7 +56,7 @@ fn hash_data_specifier(specifier: &ModuleSpecifier) -> String {
file_name_str.push('?');
file_name_str.push_str(query);
}
- crate::checksum::gen(&[file_name_str.as_bytes()])
+ crate::util::checksum::gen(&[file_name_str.as_bytes()])
}
#[derive(Debug, Default)]