Skip to content
Merged
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
19 changes: 15 additions & 4 deletions tooling/lsp/src/notifications/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::collections::{BTreeMap, HashSet};
use std::ops::ControlFlow;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::str::FromStr as _;

use crate::{
Expand Down Expand Up @@ -283,7 +283,7 @@ fn publish_diagnostics(
for custom_diagnostic in custom_diagnostics.into_iter() {
let file = custom_diagnostic.file;
let path = fm.path(file).expect("file must exist to have emitted diagnostic");
if let Ok(uri) = Url::from_file_path(path) {
if let Some(uri) = uri_from_path(path) {
if let Some(diagnostic) =
custom_diagnostic_to_diagnostic(custom_diagnostic, files, fm, uri.clone())
{
Expand Down Expand Up @@ -356,6 +356,7 @@ fn custom_diagnostic_to_diagnostic(
let call_stack = diagnostic
.call_stack
.into_iter()
.rev()
.filter_map(|frame| call_stack_frame_to_related_information(frame, files, fm));
let related_information: Vec<_> = secondaries.chain(notes).chain(call_stack).collect();

Expand All @@ -380,19 +381,29 @@ fn secondary_to_related_information(
) -> Option<DiagnosticRelatedInformation> {
let secondary_file = secondary.location.file;
let path = fm.path(secondary_file)?;
let uri = Url::from_file_path(path).ok()?;
let uri = uri_from_path(path)?;
let range = byte_span_to_range(files, secondary_file, secondary.location.span.into())?;
let message = secondary.message;
Some(DiagnosticRelatedInformation { location: lsp_types::Location { uri, range }, message })
}

fn uri_from_path(path: &Path) -> Option<Url> {
if let Ok(uri) = Url::from_file_path(path) {
Some(uri)
} else if path.starts_with("std") {
Some(Url::parse(&format!("noir-std://{}", path.to_string_lossy())).unwrap())
} else {
None
}
}

fn call_stack_frame_to_related_information(
frame: Location,
files: &FileMap,
fm: &FileManager,
) -> Option<DiagnosticRelatedInformation> {
let path = fm.path(frame.file)?;
let uri = Url::from_file_path(path).ok()?;
let uri = uri_from_path(path)?;
let range = byte_span_to_range(files, frame.file, frame.span.into())?;
Some(DiagnosticRelatedInformation {
location: lsp_types::Location { uri, range },
Expand Down
Loading