Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Change Log

## 0.9.12
- Diagnostics sent from the server will now indicate their source as 'dml' or 'dml-lint'

## 0.9.11
- Fixed deadlock when a configuration update happens
Expand Down
42 changes: 35 additions & 7 deletions src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::file_management::{PathResolver, CanonPath};
use crate::lint::{LintCfg, maybe_parse_lint_cfg};
use crate::lsp_data;
use crate::lsp_data::*;
use crate::lsp_data::ls_util::{dls_to_range, dls_to_location};
use crate::server::{Output, ServerToHandle, error_message,
Request, RequestId, SentRequest};
use crate::server::message::RawResponse;
Expand Down Expand Up @@ -305,6 +306,31 @@ impl ContextDefinition {
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourcedDMLError {
pub error: DMLError,
pub source: &'static str,
}

impl SourcedDMLError {
pub fn to_diagnostic(&self) -> Diagnostic {
Diagnostic::new(
dls_to_range(self.error.span.range),
self.error.severity,
None,
Some(self.source.to_string()),
self.error.description.clone(),
Some(
self.error.related.iter().map(
|(span, desc)|DiagnosticRelatedInformation {
location: dls_to_location(span),
message: desc.clone(),
}).collect()),
None
)
}
}

pub type ActiveDeviceContexts = HashSet<ContextDefinition>;

impl <O: Output> InitActionContext<O> {
Expand Down Expand Up @@ -452,22 +478,24 @@ impl <O: Output> InitActionContext<O> {
.collect();
let direct_opens = self.direct_opens.lock().unwrap();
for file in files {
let mut sorted_errors: Vec<DMLError> =
isolated.get(file).into_iter().flatten()
.chain(device.get(file).into_iter().flatten())
let mut sorted_errors: Vec<SourcedDMLError> =
isolated.get(file).into_iter().flatten().cloned()
.map(|e|e.with_source("dml"))
.chain(device.get(file).into_iter().flatten().cloned()
.map(|e|e.with_source("dml")))
.chain(
lint.get(file).into_iter().flatten()
.filter(
|_|!config.lint_direct_only
|| direct_opens.contains(
&file.clone().into())
))
.cloned()
).cloned()
.map(|e|e.with_source("dml-lint")))
.collect();
debug!("Reporting errors for {:?}", file);
// Sort by line
sorted_errors.sort_unstable_by(
|e1, e2|if e1.span.range > e2.span.range {
|e1, e2|if e1.error.span.range > e2.error.span.range {
Ordering::Greater
} else {
Ordering::Less
Expand All @@ -477,7 +505,7 @@ impl <O: Output> InitActionContext<O> {
PublishDiagnosticsParams::new(
url,
sorted_errors.iter()
.map(DMLError::to_diagnostic).collect(),
.map(SourcedDMLError::to_diagnostic).collect(),
None)),
// The Url crate does not report interesting errors
Err(_) => error!("Could not convert {:?} to Url", file),
Expand Down
26 changes: 7 additions & 19 deletions src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ use std::sync::Mutex;

use itertools::Itertools;

use lsp_types::{Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity};
use lsp_types::{DiagnosticSeverity};
use logos::Logos;
use log::{debug, error, info, trace};
use rayon::prelude::*;

use crate::actions::SourcedDMLError;
use crate::actions::analysis_storage::TimestampedStorage;
use crate::analysis::symbols::{SimpleSymbol, DMLSymbolKind, Symbol,
SymbolSource};
Expand Down Expand Up @@ -67,7 +68,6 @@ use crate::analysis::templating::types::DMLResolvedType;
use crate::file_management::{PathResolver, CanonPath};

use crate::vfs::{TextFile, Error};
use crate::lsp_data::ls_util::{dls_to_range, dls_to_location};

#[derive(Clone, Copy)]
pub struct FileSpec<'a> {
Expand Down Expand Up @@ -229,19 +229,11 @@ impl Hash for DMLError {
}

impl DMLError {
pub fn to_diagnostic(&self) -> Diagnostic {
Diagnostic::new(
dls_to_range(self.span.range),
self.severity, None, None,
self.description.clone(),
Some(
self.related.iter().map(
|(span, desc)|DiagnosticRelatedInformation {
location: dls_to_location(span),
message: desc.clone(),
}).collect()),
None
)
pub fn with_source(self, source: &'static str) -> SourcedDMLError {
SourcedDMLError {
error: self,
source,
}
}
}

Expand All @@ -260,10 +252,6 @@ impl LocalDMLError {
related: vec![],
}
}
pub fn to_diagnostic(&self) -> Diagnostic {
Diagnostic::new_simple(dls_to_range(self.range),
self.description.clone())
}
pub fn warning_with_file<F: Into<PathBuf>>(self, file: F) -> DMLError {
DMLError {
span: ZeroSpan::from_range(self.range, file),
Expand Down