diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/diagnostics.rs | 22 | ||||
-rw-r--r-- | crates/rust-analyzer/src/diagnostics/to_proto.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 12 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 20 |
4 files changed, 33 insertions, 27 deletions
diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs index f3cdb842b..1cf50b677 100644 --- a/crates/rust-analyzer/src/diagnostics.rs +++ b/crates/rust-analyzer/src/diagnostics.rs | |||
@@ -3,7 +3,6 @@ pub(crate) mod to_proto; | |||
3 | 3 | ||
4 | use std::{collections::HashMap, mem, sync::Arc}; | 4 | use std::{collections::HashMap, mem, sync::Arc}; |
5 | 5 | ||
6 | use lsp_types::{Diagnostic, Range}; | ||
7 | use ra_ide::FileId; | 6 | use ra_ide::FileId; |
8 | use rustc_hash::FxHashSet; | 7 | use rustc_hash::FxHashSet; |
9 | 8 | ||
@@ -19,15 +18,15 @@ pub struct DiagnosticsConfig { | |||
19 | 18 | ||
20 | #[derive(Debug, Default, Clone)] | 19 | #[derive(Debug, Default, Clone)] |
21 | pub(crate) struct DiagnosticCollection { | 20 | pub(crate) struct DiagnosticCollection { |
22 | pub(crate) native: HashMap<FileId, Vec<Diagnostic>>, | 21 | pub(crate) native: HashMap<FileId, Vec<lsp_types::Diagnostic>>, |
23 | pub(crate) check: HashMap<FileId, Vec<Diagnostic>>, | 22 | pub(crate) check: HashMap<FileId, Vec<lsp_types::Diagnostic>>, |
24 | pub(crate) check_fixes: CheckFixes, | 23 | pub(crate) check_fixes: CheckFixes, |
25 | changes: FxHashSet<FileId>, | 24 | changes: FxHashSet<FileId>, |
26 | } | 25 | } |
27 | 26 | ||
28 | #[derive(Debug, Clone)] | 27 | #[derive(Debug, Clone)] |
29 | pub(crate) struct Fix { | 28 | pub(crate) struct Fix { |
30 | pub(crate) range: Range, | 29 | pub(crate) range: lsp_types::Range, |
31 | pub(crate) action: lsp_ext::CodeAction, | 30 | pub(crate) action: lsp_ext::CodeAction, |
32 | } | 31 | } |
33 | 32 | ||
@@ -40,7 +39,7 @@ impl DiagnosticCollection { | |||
40 | pub(crate) fn add_check_diagnostic( | 39 | pub(crate) fn add_check_diagnostic( |
41 | &mut self, | 40 | &mut self, |
42 | file_id: FileId, | 41 | file_id: FileId, |
43 | diagnostic: Diagnostic, | 42 | diagnostic: lsp_types::Diagnostic, |
44 | fixes: Vec<lsp_ext::CodeAction>, | 43 | fixes: Vec<lsp_ext::CodeAction>, |
45 | ) { | 44 | ) { |
46 | let diagnostics = self.check.entry(file_id).or_default(); | 45 | let diagnostics = self.check.entry(file_id).or_default(); |
@@ -59,12 +58,19 @@ impl DiagnosticCollection { | |||
59 | self.changes.insert(file_id); | 58 | self.changes.insert(file_id); |
60 | } | 59 | } |
61 | 60 | ||
62 | pub(crate) fn set_native_diagnostics(&mut self, file_id: FileId, diagnostics: Vec<Diagnostic>) { | 61 | pub(crate) fn set_native_diagnostics( |
62 | &mut self, | ||
63 | file_id: FileId, | ||
64 | diagnostics: Vec<lsp_types::Diagnostic>, | ||
65 | ) { | ||
63 | self.native.insert(file_id, diagnostics); | 66 | self.native.insert(file_id, diagnostics); |
64 | self.changes.insert(file_id); | 67 | self.changes.insert(file_id); |
65 | } | 68 | } |
66 | 69 | ||
67 | pub(crate) fn diagnostics_for(&self, file_id: FileId) -> impl Iterator<Item = &Diagnostic> { | 70 | pub(crate) fn diagnostics_for( |
71 | &self, | ||
72 | file_id: FileId, | ||
73 | ) -> impl Iterator<Item = &lsp_types::Diagnostic> { | ||
68 | let native = self.native.get(&file_id).into_iter().flatten(); | 74 | let native = self.native.get(&file_id).into_iter().flatten(); |
69 | let check = self.check.get(&file_id).into_iter().flatten(); | 75 | let check = self.check.get(&file_id).into_iter().flatten(); |
70 | native.chain(check) | 76 | native.chain(check) |
@@ -78,7 +84,7 @@ impl DiagnosticCollection { | |||
78 | } | 84 | } |
79 | } | 85 | } |
80 | 86 | ||
81 | fn are_diagnostics_equal(left: &Diagnostic, right: &Diagnostic) -> bool { | 87 | fn are_diagnostics_equal(left: &lsp_types::Diagnostic, right: &lsp_types::Diagnostic) -> bool { |
82 | left.source == right.source | 88 | left.source == right.source |
83 | && left.severity == right.severity | 89 | && left.severity == right.severity |
84 | && left.range == right.range | 90 | && left.range == right.range |
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index f379f5ed0..3eed118a9 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs | |||
@@ -167,9 +167,9 @@ fn map_rust_child_diagnostic( | |||
167 | 167 | ||
168 | #[derive(Debug)] | 168 | #[derive(Debug)] |
169 | pub(crate) struct MappedRustDiagnostic { | 169 | pub(crate) struct MappedRustDiagnostic { |
170 | pub location: Location, | 170 | pub(crate) location: Location, |
171 | pub diagnostic: Diagnostic, | 171 | pub(crate) diagnostic: Diagnostic, |
172 | pub fixes: Vec<lsp_ext::CodeAction>, | 172 | pub(crate) fixes: Vec<lsp_ext::CodeAction>, |
173 | } | 173 | } |
174 | 174 | ||
175 | /// Converts a Rust root diagnostic to LSP form | 175 | /// Converts a Rust root diagnostic to LSP form |
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 7533bb319..4da094083 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -195,11 +195,7 @@ impl Drop for GlobalState { | |||
195 | 195 | ||
196 | impl GlobalStateSnapshot { | 196 | impl GlobalStateSnapshot { |
197 | pub(crate) fn url_to_file_id(&self, url: &Url) -> Result<FileId> { | 197 | pub(crate) fn url_to_file_id(&self, url: &Url) -> Result<FileId> { |
198 | let path = from_proto::abs_path(url)?; | 198 | url_to_file_id(&self.vfs.read().0, url) |
199 | let path = path.into(); | ||
200 | let res = | ||
201 | self.vfs.read().0.file_id(&path).ok_or_else(|| format!("file not found: {}", path))?; | ||
202 | Ok(res) | ||
203 | } | 199 | } |
204 | 200 | ||
205 | pub(crate) fn file_id_to_url(&self, id: FileId) -> Url { | 201 | 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 { | |||
239 | let path = path.as_path().unwrap(); | 235 | let path = path.as_path().unwrap(); |
240 | url_from_abs_path(&path) | 236 | url_from_abs_path(&path) |
241 | } | 237 | } |
238 | |||
239 | pub(crate) fn url_to_file_id(vfs: &vfs::Vfs, url: &Url) -> Result<FileId> { | ||
240 | let path = from_proto::vfs_path(url)?; | ||
241 | let res = vfs.file_id(&path).ok_or_else(|| format!("file not found: {}", path))?; | ||
242 | Ok(res) | ||
243 | } | ||
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 162c0057e..8fc816cbd 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -16,7 +16,7 @@ use crate::{ | |||
16 | config::Config, | 16 | config::Config, |
17 | dispatch::{NotificationDispatcher, RequestDispatcher}, | 17 | dispatch::{NotificationDispatcher, RequestDispatcher}, |
18 | from_proto, | 18 | from_proto, |
19 | global_state::{file_id_to_url, GlobalState, Status}, | 19 | global_state::{file_id_to_url, url_to_file_id, GlobalState, Status}, |
20 | handlers, lsp_ext, | 20 | handlers, lsp_ext, |
21 | lsp_utils::{apply_document_changes, is_canceled, notification_is, notification_new}, | 21 | lsp_utils::{apply_document_changes, is_canceled, notification_is, notification_new}, |
22 | Result, | 22 | Result, |
@@ -200,18 +200,16 @@ impl GlobalState { | |||
200 | &workspace_root, | 200 | &workspace_root, |
201 | ); | 201 | ); |
202 | for diag in diagnostics { | 202 | for diag in diagnostics { |
203 | let path = from_proto::vfs_path(&diag.location.uri)?; | 203 | match url_to_file_id(&self.vfs.read().0, &diag.location.uri) { |
204 | let file_id = match self.vfs.read().0.file_id(&path) { | 204 | Ok(file_id) => self.diagnostics.add_check_diagnostic( |
205 | Some(file) => FileId(file.0), | 205 | file_id, |
206 | None => { | 206 | diag.diagnostic, |
207 | log::error!( | 207 | diag.fixes, |
208 | "File with cargo diagnostic not found in VFS: {}", | 208 | ), |
209 | path | 209 | Err(err) => { |
210 | ); | 210 | log::error!("File with cargo diagnostic not found in VFS: {}", err); |
211 | return Ok(()); | ||
212 | } | 211 | } |
213 | }; | 212 | }; |
214 | self.diagnostics.add_check_diagnostic(file_id, diag.diagnostic, diag.fixes) | ||
215 | } | 213 | } |
216 | } | 214 | } |
217 | 215 | ||