mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 09:48:10 +00:00
5072: Cleanup r=matklad a=matklad
bors r+
🤖
5073: `iterate_method_candidates`: Address review comments r=jonas-schievink a=jonas-schievink
bors r+
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
This commit is contained in:
commit
ce06f8d041
5 changed files with 35 additions and 28 deletions
|
@ -281,6 +281,7 @@ pub fn iterate_method_candidates<T>(
|
|||
name,
|
||||
mode,
|
||||
&mut |ty, item| {
|
||||
assert!(slot.is_none());
|
||||
slot = callback(ty, item);
|
||||
slot.is_some()
|
||||
},
|
||||
|
@ -288,7 +289,7 @@ pub fn iterate_method_candidates<T>(
|
|||
slot
|
||||
}
|
||||
|
||||
pub fn iterate_method_candidates_impl(
|
||||
fn iterate_method_candidates_impl(
|
||||
ty: &Canonical<Ty>,
|
||||
db: &dyn HirDatabase,
|
||||
env: Arc<TraitEnvironment>,
|
||||
|
|
|
@ -3,7 +3,6 @@ pub(crate) mod to_proto;
|
|||
|
||||
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 @@ impl DiagnosticCollection {
|
|||
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 @@ impl DiagnosticCollection {
|
|||
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 @@ impl DiagnosticCollection {
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ impl Drop for GlobalState {
|
|||
|
||||
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 @@ use crate::{
|
|||
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 @@ impl GlobalState {
|
|||
&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 a new issue