Skip to content

Commit eee6872

Browse files
committed
Auto merge of rust-lang#14901 - Veykril:errors, r=Veykril
internal: Move flycheck and config errors to status notification cc rust-lang/rust-analyzer#14193
2 parents e963846 + f876adf commit eee6872

File tree

5 files changed

+125
-100
lines changed

5 files changed

+125
-100
lines changed

crates/rust-analyzer/src/config.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -720,11 +720,11 @@ pub struct ClientCommandsConfig {
720720
}
721721

722722
#[derive(Debug)]
723-
pub struct ConfigUpdateError {
723+
pub struct ConfigError {
724724
errors: Vec<(String, serde_json::Error)>,
725725
}
726726

727-
impl fmt::Display for ConfigUpdateError {
727+
impl fmt::Display for ConfigError {
728728
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
729729
let errors = self.errors.iter().format_with("\n", |(key, e), f| {
730730
f(key)?;
@@ -733,8 +733,7 @@ impl fmt::Display for ConfigUpdateError {
733733
});
734734
write!(
735735
f,
736-
"rust-analyzer found {} invalid config value{}:\n{}",
737-
self.errors.len(),
736+
"invalid config value{}:\n{}",
738737
if self.errors.len() == 1 { "" } else { "s" },
739738
errors
740739
)
@@ -777,7 +776,7 @@ impl Config {
777776
self.workspace_roots.extend(paths);
778777
}
779778

780-
pub fn update(&mut self, mut json: serde_json::Value) -> Result<(), ConfigUpdateError> {
779+
pub fn update(&mut self, mut json: serde_json::Value) -> Result<(), ConfigError> {
781780
tracing::info!("updating config from JSON: {:#}", json);
782781
if json.is_null() || json.as_object().map_or(false, |it| it.is_empty()) {
783782
return Ok(());
@@ -824,7 +823,7 @@ impl Config {
824823
if errors.is_empty() {
825824
Ok(())
826825
} else {
827-
Err(ConfigUpdateError { errors })
826+
Err(ConfigError { errors })
828827
}
829828
}
830829

crates/rust-analyzer/src/global_state.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use triomphe::Arc;
1919
use vfs::AnchoredPathBuf;
2020

2121
use crate::{
22-
config::Config,
22+
config::{Config, ConfigError},
2323
diagnostics::{CheckFixes, DiagnosticCollection},
2424
from_proto,
2525
line_index::{LineEndings, LineIndex},
@@ -52,24 +52,33 @@ pub(crate) type ReqQueue = lsp_server::ReqQueue<(String, Instant), ReqHandler>;
5252
pub(crate) struct GlobalState {
5353
sender: Sender<lsp_server::Message>,
5454
req_queue: ReqQueue,
55+
5556
pub(crate) task_pool: Handle<TaskPool<Task>, Receiver<Task>>,
56-
pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>,
57+
5758
pub(crate) config: Arc<Config>,
59+
pub(crate) config_errors: Option<ConfigError>,
5860
pub(crate) analysis_host: AnalysisHost,
5961
pub(crate) diagnostics: DiagnosticCollection,
6062
pub(crate) mem_docs: MemDocs,
63+
pub(crate) source_root_config: SourceRootConfig,
6164
pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>,
65+
66+
// status
6267
pub(crate) shutdown_requested: bool,
6368
pub(crate) last_reported_status: Option<lsp_ext::ServerStatusParams>,
64-
pub(crate) source_root_config: SourceRootConfig,
6569

70+
// proc macros
6671
pub(crate) proc_macro_changed: bool,
6772
pub(crate) proc_macro_clients: Arc<[anyhow::Result<ProcMacroServer>]>,
6873

74+
// Flycheck
6975
pub(crate) flycheck: Arc<[FlycheckHandle]>,
7076
pub(crate) flycheck_sender: Sender<flycheck::Message>,
7177
pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
78+
pub(crate) last_flycheck_error: Option<String>,
7279

80+
// VFS
81+
pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>,
7382
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, IntMap<FileId, LineEndings>)>>,
7483
pub(crate) vfs_config_version: u32,
7584
pub(crate) vfs_progress_config_version: u32,
@@ -102,11 +111,12 @@ pub(crate) struct GlobalState {
102111
/// the user just adds comments or whitespace to Cargo.toml, we do not want
103112
/// to invalidate any salsa caches.
104113
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
114+
115+
// op queues
105116
pub(crate) fetch_workspaces_queue: OpQueue<(), Option<Vec<anyhow::Result<ProjectWorkspace>>>>,
106117
pub(crate) fetch_build_data_queue:
107118
OpQueue<(), (Arc<Vec<ProjectWorkspace>>, Vec<anyhow::Result<WorkspaceBuildScripts>>)>,
108119
pub(crate) fetch_proc_macros_queue: OpQueue<Vec<ProcMacroPaths>, bool>,
109-
110120
pub(crate) prime_caches_queue: OpQueue,
111121
}
112122

@@ -160,6 +170,7 @@ impl GlobalState {
160170
shutdown_requested: false,
161171
last_reported_status: None,
162172
source_root_config: SourceRootConfig::default(),
173+
config_errors: Default::default(),
163174

164175
proc_macro_changed: false,
165176
// FIXME: use `Arc::from_iter` when it becomes available
@@ -169,6 +180,7 @@ impl GlobalState {
169180
flycheck: Arc::from(Vec::new()),
170181
flycheck_sender,
171182
flycheck_receiver,
183+
last_flycheck_error: None,
172184

173185
vfs: Arc::new(RwLock::new((vfs::Vfs::default(), IntMap::default()))),
174186
vfs_config_version: 0,

crates/rust-analyzer/src/handlers/notification.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,7 @@ pub(crate) fn handle_did_change_configuration(
169169
// Note that json can be null according to the spec if the client can't
170170
// provide a configuration. This is handled in Config::update below.
171171
let mut config = Config::clone(&*this.config);
172-
if let Err(error) = config.update(json.take()) {
173-
this.show_message(
174-
lsp_types::MessageType::WARNING,
175-
error.to_string(),
176-
false,
177-
);
178-
}
172+
this.config_errors = config.update(json.take()).err();
179173
this.update_configuration(config);
180174
}
181175
}

0 commit comments

Comments
 (0)