Cleanup
This commit is contained in:
parent
b039f0d1ba
commit
12831b74af
@ -3,7 +3,6 @@
|
||||
|
||||
use std::{collections::HashMap, mem, sync::Arc};
|
||||
|
||||
use lsp_types::{Diagnostic, Range};
|
||||
use ra_ide::FileId;
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
@ -19,15 +18,15 @@ pub struct DiagnosticsConfig {
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub(crate) struct DiagnosticCollection {
|
||||
pub(crate) native: HashMap<FileId, Vec<Diagnostic>>,
|
||||
pub(crate) check: HashMap<FileId, Vec<Diagnostic>>,
|
||||
pub(crate) native: HashMap<FileId, Vec<lsp_types::Diagnostic>>,
|
||||
pub(crate) check: HashMap<FileId, Vec<lsp_types::Diagnostic>>,
|
||||
pub(crate) check_fixes: CheckFixes,
|
||||
changes: FxHashSet<FileId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct Fix {
|
||||
pub(crate) range: Range,
|
||||
pub(crate) range: lsp_types::Range,
|
||||
pub(crate) action: lsp_ext::CodeAction,
|
||||
}
|
||||
|
||||
@ -40,7 +39,7 @@ pub(crate) fn clear_check(&mut self) {
|
||||
pub(crate) fn add_check_diagnostic(
|
||||
&mut self,
|
||||
file_id: FileId,
|
||||
diagnostic: Diagnostic,
|
||||
diagnostic: lsp_types::Diagnostic,
|
||||
fixes: Vec<lsp_ext::CodeAction>,
|
||||
) {
|
||||
let diagnostics = self.check.entry(file_id).or_default();
|
||||
@ -59,12 +58,19 @@ pub(crate) fn add_check_diagnostic(
|
||||
self.changes.insert(file_id);
|
||||
}
|
||||
|
||||
pub(crate) fn set_native_diagnostics(&mut self, file_id: FileId, diagnostics: Vec<Diagnostic>) {
|
||||
pub(crate) fn set_native_diagnostics(
|
||||
&mut self,
|
||||
file_id: FileId,
|
||||
diagnostics: Vec<lsp_types::Diagnostic>,
|
||||
) {
|
||||
self.native.insert(file_id, diagnostics);
|
||||
self.changes.insert(file_id);
|
||||
}
|
||||
|
||||
pub(crate) fn diagnostics_for(&self, file_id: FileId) -> impl Iterator<Item = &Diagnostic> {
|
||||
pub(crate) fn diagnostics_for(
|
||||
&self,
|
||||
file_id: FileId,
|
||||
) -> impl Iterator<Item = &lsp_types::Diagnostic> {
|
||||
let native = self.native.get(&file_id).into_iter().flatten();
|
||||
let check = self.check.get(&file_id).into_iter().flatten();
|
||||
native.chain(check)
|
||||
@ -78,7 +84,7 @@ pub(crate) fn take_changes(&mut self) -> Option<FxHashSet<FileId>> {
|
||||
}
|
||||
}
|
||||
|
||||
fn are_diagnostics_equal(left: &Diagnostic, right: &Diagnostic) -> bool {
|
||||
fn are_diagnostics_equal(left: &lsp_types::Diagnostic, right: &lsp_types::Diagnostic) -> bool {
|
||||
left.source == right.source
|
||||
&& left.severity == right.severity
|
||||
&& left.range == right.range
|
||||
|
@ -167,9 +167,9 @@ fn map_rust_child_diagnostic(
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct MappedRustDiagnostic {
|
||||
pub location: Location,
|
||||
pub diagnostic: Diagnostic,
|
||||
pub fixes: Vec<lsp_ext::CodeAction>,
|
||||
pub(crate) location: Location,
|
||||
pub(crate) diagnostic: Diagnostic,
|
||||
pub(crate) fixes: Vec<lsp_ext::CodeAction>,
|
||||
}
|
||||
|
||||
/// Converts a Rust root diagnostic to LSP form
|
||||
|
@ -195,11 +195,7 @@ fn drop(&mut self) {
|
||||
|
||||
impl GlobalStateSnapshot {
|
||||
pub(crate) fn url_to_file_id(&self, url: &Url) -> Result<FileId> {
|
||||
let path = from_proto::abs_path(url)?;
|
||||
let path = path.into();
|
||||
let res =
|
||||
self.vfs.read().0.file_id(&path).ok_or_else(|| format!("file not found: {}", path))?;
|
||||
Ok(res)
|
||||
url_to_file_id(&self.vfs.read().0, url)
|
||||
}
|
||||
|
||||
pub(crate) fn file_id_to_url(&self, id: FileId) -> Url {
|
||||
@ -239,3 +235,9 @@ pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url {
|
||||
let path = path.as_path().unwrap();
|
||||
url_from_abs_path(&path)
|
||||
}
|
||||
|
||||
pub(crate) fn url_to_file_id(vfs: &vfs::Vfs, url: &Url) -> Result<FileId> {
|
||||
let path = from_proto::vfs_path(url)?;
|
||||
let res = vfs.file_id(&path).ok_or_else(|| format!("file not found: {}", path))?;
|
||||
Ok(res)
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
config::Config,
|
||||
dispatch::{NotificationDispatcher, RequestDispatcher},
|
||||
from_proto,
|
||||
global_state::{file_id_to_url, GlobalState, Status},
|
||||
global_state::{file_id_to_url, url_to_file_id, GlobalState, Status},
|
||||
handlers, lsp_ext,
|
||||
lsp_utils::{apply_document_changes, is_canceled, notification_is, notification_new},
|
||||
Result,
|
||||
@ -200,18 +200,16 @@ fn handle_event(&mut self, event: Event) -> Result<()> {
|
||||
&workspace_root,
|
||||
);
|
||||
for diag in diagnostics {
|
||||
let path = from_proto::vfs_path(&diag.location.uri)?;
|
||||
let file_id = match self.vfs.read().0.file_id(&path) {
|
||||
Some(file) => FileId(file.0),
|
||||
None => {
|
||||
log::error!(
|
||||
"File with cargo diagnostic not found in VFS: {}",
|
||||
path
|
||||
);
|
||||
return Ok(());
|
||||
match url_to_file_id(&self.vfs.read().0, &diag.location.uri) {
|
||||
Ok(file_id) => self.diagnostics.add_check_diagnostic(
|
||||
file_id,
|
||||
diag.diagnostic,
|
||||
diag.fixes,
|
||||
),
|
||||
Err(err) => {
|
||||
log::error!("File with cargo diagnostic not found in VFS: {}", err);
|
||||
}
|
||||
};
|
||||
self.diagnostics.add_check_diagnostic(file_id, diag.diagnostic, diag.fixes)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user