Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 658d0f8

Browse files
committed
replaced beginBuild, diagnosticsBegin and diagnosticsEnd with progress
1 parent e0e143e commit 658d0f8

File tree

6 files changed

+114
-159
lines changed

6 files changed

+114
-159
lines changed

contributing.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,14 @@ The RLS uses some custom extensions to the Language Server Protocol.
306306
These are all sent from the RLS to an LSP client and are only used to improve
307307
the user experience by showing progress indicators.
308308

309-
310-
* `rustDocument/beginBuild`: notification, no arguments. Sent before a
311-
build starts.
312-
* `rustDocument/diagnosticsBegin`: notification, no arguments. Sent before
313-
indexing or any diagnostics from a build are sent (build is likely in progress).
314-
* `rustDocument/diagnosticsEnd`: notification, no arguments. Sent when a build
315-
is complete (successfully or not, or even skipped) and all post-build analysis
316-
by the RLS is complete.
309+
* `window/progress`: notification, `title: "Build"`. Sent before build starts.
310+
* `window/progress`: notification with `title: "Build"`, repeated for each compile target.
311+
* When total amount of work is not known, has field `message` set to the current crate name.
312+
* When total amount of work is known, has field `percentage` set to how much of build has started.
313+
* `window/progress`: notification, `title: "Build"`, `"done": true`. Sent when build ends.
314+
* `window/progress`: notification, `title: "Diagnostics"`. Sent before analysis of build starts.
315+
* ... standard LSP `publishDiagnostics`
316+
* `window/progress`: notification, `title: "Diagnostics"`, `"done": true`. Sent when analysis ends.
317317

318318
#### LSP Client to RLS
319319

src/actions/mod.rs

+33-19
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ use span;
2222
use Span;
2323

2424
use actions::post_build::{BuildResults, PostBuildHandler, DiagnosticsNotifier};
25-
use actions::notifications::{BeginBuild, DiagnosticsBegin, DiagnosticsEnd, PublishDiagnostics, Progress};
25+
use actions::notifications::{PublishDiagnostics, Progress};
2626
use build::*;
2727
use lsp_data;
2828
use lsp_data::*;
29-
use server::{Output, Notification, NoParams};
29+
use server::{Output, Notification};
3030

3131
use std::collections::HashMap;
3232
use std::path::{Path, PathBuf};
@@ -198,22 +198,48 @@ impl InitActionContext {
198198

199199
fn build<O: Output>(&self, project_path: &Path, priority: BuildPriority, out: O) {
200200

201+
lazy_static! {
202+
static ref PROGRESS_ID_COUNTER: AtomicUsize = {
203+
AtomicUsize::new(0)
204+
};
205+
}
206+
207+
fn new_progress_params(id: String, title: &str) -> ProgressParams {
208+
ProgressParams {
209+
id,
210+
title: Some(title.into()),
211+
message: None,
212+
percentage: None,
213+
done: None,
214+
}
215+
}
216+
201217
// notifier of diagnostics after the build
202218
struct BuildDiagnosticsNotifier<O: Output> {
203219
out: O,
204220
active_build_count: Arc<AtomicUsize>,
221+
progress_params: ProgressParams,
205222
}
206223

224+
// base progress parameters for notification of the analysis.
225+
let diganostics_progress_params = {
226+
let id = format!("diagnostics_{}", PROGRESS_ID_COUNTER.fetch_add(1, Ordering::SeqCst));
227+
new_progress_params(id, "Diagnostics")
228+
};
229+
207230
impl<O: Output> DiagnosticsNotifier for BuildDiagnosticsNotifier<O> {
208231
fn notify_begin_diagnostics(&self) {
209-
self.out.notify(Notification::<DiagnosticsBegin>::new(NoParams {}));
232+
let params = self.progress_params.clone();
233+
self.out.notify(Notification::<Progress>::new(params));
210234
}
211235
fn notify_publish_diagnostics(&self, params: PublishDiagnosticsParams) {
212236
self.out.notify(Notification::<PublishDiagnostics>::new(params));
213237
}
214238
fn notify_end_diagnostics(&self) {
215239
self.active_build_count.fetch_sub(1, Ordering::SeqCst);
216-
self.out.notify(Notification::<DiagnosticsEnd>::new(NoParams {}));
240+
let mut params = self.progress_params.clone();
241+
params.done = Some(true);
242+
self.out.notify(Notification::<Progress>::new(params));
217243
}
218244
}
219245

@@ -225,19 +251,8 @@ impl InitActionContext {
225251

226252
// base progress parameters for notification of this build.
227253
let progress_params = {
228-
lazy_static! {
229-
static ref ID_COUNTER: AtomicUsize = {
230-
AtomicUsize::new(0)
231-
};
232-
}
233-
234-
ProgressParams {
235-
id: format!("progress_{}", ID_COUNTER.fetch_add(1, Ordering::SeqCst)),
236-
title: None,
237-
message: None,
238-
percentage: None,
239-
done: None,
240-
}
254+
let id = format!("progress_{}", PROGRESS_ID_COUNTER.fetch_add(1, Ordering::SeqCst));
255+
new_progress_params(id, "Build")
241256
};
242257

243258
impl<O: Output> ProgressNotifier for BuildProgressNotifier<O> {
@@ -255,7 +270,6 @@ impl InitActionContext {
255270
}
256271
fn notify_end_progress(&self) {
257272
let mut params = self.progress_params.clone();
258-
params.percentage = Some(1.0);
259273
params.done = Some(true);
260274
self.out.notify(Notification::<Progress>::new(params));
261275
}
@@ -272,6 +286,7 @@ impl InitActionContext {
272286
notifier: Box::new(BuildDiagnosticsNotifier {
273287
out: out.clone(),
274288
active_build_count: self.active_build_count.clone(),
289+
progress_params: diganostics_progress_params,
275290
}),
276291
blocked_threads: vec![],
277292
}
@@ -282,7 +297,6 @@ impl InitActionContext {
282297
progress_params,
283298
});
284299

285-
out.notify(Notification::<BeginBuild>::new(NoParams {}));
286300
self.active_build_count.fetch_add(1, Ordering::SeqCst);
287301
self.build_queue
288302
.request_build(project_path, priority, notifier, pbh);

src/actions/notifications.rs

-32
Original file line numberDiff line numberDiff line change
@@ -389,38 +389,6 @@ impl Action for ShowMessage {
389389
const METHOD: &'static str = NOTIFICATION__ShowMessage;
390390
}
391391

392-
/// Custom LSP notification sent to client indicating that the server is currently
393-
/// processing data and may publish new diagnostics on `rustDocument/diagnosticsEnd`.
394-
#[derive(Debug)]
395-
pub struct DiagnosticsBegin;
396-
397-
impl Action for DiagnosticsBegin {
398-
type Params = NoParams;
399-
const METHOD: &'static str = "rustDocument/diagnosticsBegin";
400-
}
401-
402-
/// Custom LSP notification sent to client indicating that data processing started
403-
/// by a `rustDocument`/diagnosticsBegin` has ended.
404-
/// For each `diagnosticsBegin` message, there is a single `diagnosticsEnd` message.
405-
/// This means that for multiple active `diagnosticsBegin` messages, there will
406-
/// be sent multiple `diagnosticsEnd` notifications.
407-
#[derive(Debug)]
408-
pub struct DiagnosticsEnd;
409-
410-
impl Action for DiagnosticsEnd {
411-
type Params = NoParams;
412-
const METHOD: &'static str = "rustDocument/diagnosticsEnd";
413-
}
414-
415-
/// Custom LSP notification sent to client indicating that a build process has begun.
416-
#[derive(Debug)]
417-
pub struct BeginBuild;
418-
419-
impl Action for BeginBuild {
420-
type Params = NoParams;
421-
const METHOD: &'static str = "rustDocument/beginBuild";
422-
}
423-
424392
// Notification from server to client for build progress.
425393
#[derive(Debug)]
426394
pub struct Progress;

src/actions/post_build.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ pub trait DiagnosticsNotifier: Send {
5353

5454
impl PostBuildHandler {
5555
pub fn handle(mut self, result: BuildResult) {
56-
self.notifier.notify_begin_diagnostics();
5756

5857
match result {
5958
BuildResult::Success(cwd, messages, new_analysis) => {
6059
thread::spawn(move || {
6160
trace!("build - Success");
61+
self.notifier.notify_begin_diagnostics();
6262

6363
// Emit appropriate diagnostics using the ones from build.
6464
self.handle_messages(&cwd, messages);
@@ -81,11 +81,9 @@ impl PostBuildHandler {
8181
}
8282
BuildResult::Squashed => {
8383
trace!("build - Squashed");
84-
self.notifier.notify_end_diagnostics();
8584
}
8685
BuildResult::Err => {
8786
trace!("build - Error");
88-
self.notifier.notify_end_diagnostics();
8987
}
9088
}
9189
}

src/cmd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ fn init() -> Sender<String> {
442442
).to_string(),
443443
)
444444
.expect("Error sending init");
445-
println!("Initializing (look for `diagnosticsEnd` message)...");
445+
println!("Initializing (look for `progress[done:true]` message)...");
446446

447447
sender
448448
}

0 commit comments

Comments
 (0)