summaryrefslogtreecommitdiff
path: root/cli/lsp/diagnostics.rs
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2021-05-18 12:05:46 +0530
committerGitHub <noreply@github.com>2021-05-18 16:35:46 +1000
commitd69a5fbe1a4f909b7eba0eac81dd111fb7229232 (patch)
treedfa2e3a6e10f2dbc85447d4a0ef1dce727208ab9 /cli/lsp/diagnostics.rs
parent8ffeabc678dc33932ba71273fa2dc9d787274880 (diff)
feat(lsp): support formatting json and markdown files (#10180)
Resolves #9447 Resolves #9415
Diffstat (limited to 'cli/lsp/diagnostics.rs')
-rw-r--r--cli/lsp/diagnostics.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index a5b8df879..7ddb3ff7b 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -218,6 +218,17 @@ impl<'a> From<&'a diagnostics::Position> for lsp::Position {
}
}
+/// Check if diagnostics can be generated for the provided media type.
+pub fn is_diagnosable(media_type: MediaType) -> bool {
+ matches!(
+ media_type,
+ MediaType::TypeScript
+ | MediaType::JavaScript
+ | MediaType::Tsx
+ | MediaType::Jsx
+ )
+}
+
fn get_diagnostic_message(diagnostic: &diagnostics::Diagnostic) -> String {
if let Some(message) = diagnostic.message_text.clone() {
message
@@ -312,8 +323,8 @@ async fn generate_lint_diagnostics(
.lock()
.await
.get_version(specifier, &DiagnosticSource::DenoLint);
- if version != current_version {
- let media_type = MediaType::from(specifier);
+ let media_type = MediaType::from(specifier);
+ if version != current_version && is_diagnosable(media_type) {
if let Ok(Some(source_code)) = documents.content(specifier) {
if let Ok(references) = analysis::get_lint_references(
specifier,
@@ -354,10 +365,11 @@ async fn generate_ts_diagnostics(
let version = snapshot.documents.version(s);
let current_version =
collection.get_version(s, &DiagnosticSource::TypeScript);
- if version == current_version {
- None
- } else {
+ let media_type = MediaType::from(s);
+ if version != current_version && is_diagnosable(media_type) {
Some(s.clone())
+ } else {
+ None
}
})
.collect()