summaryrefslogtreecommitdiff
path: root/cli/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp')
-rw-r--r--cli/lsp/diagnostics.rs91
-rw-r--r--cli/lsp/language_server.rs40
2 files changed, 47 insertions, 84 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index 8a0d50ef1..c20307bb3 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -2,13 +2,11 @@
use super::analysis;
use super::documents;
-use super::documents::Document;
use super::documents::Documents;
use super::language_server;
use super::tsc;
use crate::diagnostics;
-use crate::fs_util::specifier_to_file_path;
use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
@@ -302,59 +300,14 @@ fn ts_json_to_diagnostics(
.collect()
}
-// Filters documents according to the `include` and the `exclude` lists (from `StateSnapshot::maybe_lint_config`).
-// If a document is in the `exclude` list - then it be removed.
-// If the `include` list is not empty, and a document is not in - then it be removed too.
-fn filter_lint_documents(
- snapshot: &language_server::StateSnapshot,
- documents: &mut Vec<Document>,
-) {
- let lint_config = match &snapshot.maybe_lint_config {
- Some(config) => config,
- None => return,
- };
-
- documents.retain(|doc| {
- let path = if let Ok(file_path) = specifier_to_file_path(doc.specifier()) {
- file_path
- } else {
- return false;
- };
-
- // Skip files which is in the exclude list.
- if lint_config
- .files
- .exclude
- .iter()
- .any(|i| path.starts_with(i))
- {
- return false;
- }
-
- // Early return if the include list is empty.
- if lint_config.files.include.is_empty() {
- return true;
- }
-
- // Ignore files not in the include list.
- lint_config
- .files
- .include
- .iter()
- .any(|i| path.starts_with(i))
- });
-}
-
async fn generate_lint_diagnostics(
snapshot: &language_server::StateSnapshot,
collection: Arc<Mutex<DiagnosticCollection>>,
) -> Result<DiagnosticVec, AnyError> {
- let mut documents = snapshot.documents.documents(true, true);
+ let documents = snapshot.documents.documents(true, true);
let workspace_settings = snapshot.config.settings.workspace.clone();
let maybe_lint_config = snapshot.maybe_lint_config.clone();
- filter_lint_documents(snapshot, &mut documents);
-
tokio::task::spawn(async move {
let mut diagnostics_vec = Vec::new();
if workspace_settings.lint {
@@ -365,25 +318,35 @@ async fn generate_lint_diagnostics(
.await
.get_version(document.specifier(), &DiagnosticSource::DenoLint);
if version != current_version {
- let diagnostics = match document.maybe_parsed_source() {
- Some(Ok(parsed_source)) => {
- if let Ok(references) = analysis::get_lint_references(
- &parsed_source,
- maybe_lint_config.as_ref(),
- ) {
- references
- .into_iter()
- .map(|r| r.to_diagnostic())
- .collect::<Vec<_>>()
- } else {
+ let is_allowed = match &maybe_lint_config {
+ Some(lint_config) => {
+ lint_config.files.matches_specifier(document.specifier())
+ }
+ None => true,
+ };
+ let diagnostics = if is_allowed {
+ match document.maybe_parsed_source() {
+ Some(Ok(parsed_source)) => {
+ if let Ok(references) = analysis::get_lint_references(
+ &parsed_source,
+ maybe_lint_config.as_ref(),
+ ) {
+ references
+ .into_iter()
+ .map(|r| r.to_diagnostic())
+ .collect::<Vec<_>>()
+ } else {
+ Vec::new()
+ }
+ }
+ Some(Err(_)) => Vec::new(),
+ None => {
+ error!("Missing file contents for: {}", document.specifier());
Vec::new()
}
}
- Some(Err(_)) => Vec::new(),
- None => {
- error!("Missing file contents for: {}", document.specifier());
- Vec::new()
- }
+ } else {
+ Vec::new()
};
diagnostics_vec.push((
document.specifier().clone(),
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index a2faf8a83..e7d0dae34 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -60,7 +60,6 @@ use crate::config_file::TsConfig;
use crate::deno_dir;
use crate::file_fetcher::get_source_from_data_url;
use crate::fs_util;
-use crate::fs_util::specifier_to_file_path;
use crate::logger;
use crate::tools::fmt::format_file;
use crate::tools::fmt::format_parsed_source;
@@ -304,9 +303,7 @@ impl Inner {
let config_url = if let Ok(url) = Url::from_file_path(config_str) {
Ok(url)
} else if let Some(root_uri) = maybe_root_uri {
- let root_path = specifier_to_file_path(&root_uri)?;
- let config_path = root_path.join(config_str);
- Url::from_file_path(config_path).map_err(|_| {
+ root_uri.join(config_str).map_err(|_| {
anyhow!("Bad file path for configuration file: \"{}\"", config_str)
})
} else {
@@ -317,13 +314,7 @@ impl Inner {
}?;
info!(" Resolved configuration file: \"{}\"", config_url);
- let config_file = {
- let buffer = specifier_to_file_path(&config_url)?;
- let path = buffer
- .to_str()
- .ok_or_else(|| anyhow!("Bad uri: \"{}\"", config_url))?;
- ConfigFile::read(path)?
- };
+ let config_file = ConfigFile::from_specifier(&config_url)?;
return Ok(Some((config_file, config_url)));
}
}
@@ -401,7 +392,7 @@ impl Inner {
let cache_url = if let Ok(url) = Url::from_file_path(cache_str) {
Ok(url)
} else if let Some(root_uri) = &maybe_root_uri {
- let root_path = specifier_to_file_path(root_uri)?;
+ let root_path = fs_util::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)
@@ -412,7 +403,7 @@ impl Inner {
cache_str
))
}?;
- let cache_path = specifier_to_file_path(&cache_url)?;
+ let cache_path = fs_util::specifier_to_file_path(&cache_url)?;
info!(
" Resolved cache path: \"{}\"",
cache_path.to_string_lossy()
@@ -457,7 +448,7 @@ impl Inner {
anyhow!("Bad data url for import map: {:?}", import_map_str)
})
} else if let Some(root_uri) = &maybe_root_uri {
- let root_path = specifier_to_file_path(root_uri)?;
+ let root_path = fs_util::specifier_to_file_path(root_uri)?;
let import_map_path = root_path.join(import_map_str);
Url::from_file_path(import_map_path).map_err(|_| {
anyhow!("Bad file path for import map: {:?}", import_map_str)
@@ -472,7 +463,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 = specifier_to_file_path(&import_map_url)?;
+ let import_map_path = fs_util::specifier_to_file_path(&import_map_url)?;
info!(
" Resolved import map: \"{}\"",
import_map_path.to_string_lossy()
@@ -660,7 +651,12 @@ impl Inner {
{
let config = &mut self.config;
- config.root_uri = params.root_uri;
+ // sometimes this root uri may not have a trailing slash, so force it to
+ config.root_uri = params
+ .root_uri
+ .map(|s| self.url_map.normalize_url(&s))
+ .map(fs_util::ensure_directory_specifier);
+
if let Some(value) = params.initialization_options {
config.set_workspace_settings(value).map_err(|err| {
error!("Cannot set workspace settings: {}", err);
@@ -1019,12 +1015,16 @@ impl Inner {
};
let mark = self.performance.mark("formatting", Some(&params));
let file_path =
- specifier_to_file_path(&params.text_document.uri).map_err(|err| {
+ fs_util::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
+ if !fmt_config.files.matches_specifier(&specifier) {
+ return Ok(None);
+ }
fmt_config.options.clone()
} else {
Default::default()
@@ -1907,7 +1907,7 @@ impl Inner {
.config
.root_uri
.as_ref()
- .and_then(|uri| specifier_to_file_path(uri).ok());
+ .and_then(|uri| fs_util::specifier_to_file_path(uri).ok());
let mut resolved_items = Vec::<CallHierarchyIncomingCall>::new();
for item in incoming_calls.iter() {
if let Some(resolved) = item
@@ -1956,7 +1956,7 @@ impl Inner {
.config
.root_uri
.as_ref()
- .and_then(|uri| specifier_to_file_path(uri).ok());
+ .and_then(|uri| fs_util::specifier_to_file_path(uri).ok());
let mut resolved_items = Vec::<CallHierarchyOutgoingCall>::new();
for item in outgoing_calls.iter() {
if let Some(resolved) = item
@@ -2012,7 +2012,7 @@ impl Inner {
.config
.root_uri
.as_ref()
- .and_then(|uri| specifier_to_file_path(uri).ok());
+ .and_then(|uri| fs_util::specifier_to_file_path(uri).ok());
let mut resolved_items = Vec::<CallHierarchyItem>::new();
match one_or_many {
tsc::OneOrMany::One(item) => {