Skip to content

Commit

Permalink
initial attempt at reporting progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ratmice committed Apr 25, 2022
1 parent 8c514d6 commit c403506
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
9 changes: 9 additions & 0 deletions neovim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ EOF
nimbleparse_lsp will generate diagnostics even for multiple files, even which are not open.
Beyond the builtin diagnostic support, there are neovim plugins worth looking into.

### Diagnostics

1. [telescope](https://github.com/nvim-telescope/telescope.nvim) :thumbsup: :two_hearts: :star2: :revolving_hearts:

Doesn't show diagnostics for unopened files, but `builtin.diagnostics`
Expand All @@ -119,6 +121,13 @@ Beyond the builtin diagnostic support, there are neovim plugins worth looking in
2. [Trouble](https://github.com/folke/trouble.nvim)
Shows diagnostics in it separate pane.

### Progress indication

3. [fidget](https://github.com/j-hui/fidget.nvim) :thumbsup:
Progress above the status line.
4. [lsp-status](https://github.com/nvim-lua/lsp-status.nvim)
Progress and diagnostic counts info on the status line.

## Testing

There isn't much done in the plugin yet besides logging to the log file, so you'll want to `tail -f that`...
Expand Down
74 changes: 74 additions & 0 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,80 @@ async fn process_parser_messages(
ParserMsg::Diagnostics(url, diags, version) => {
client.publish_diagnostics(url, diags, version).await;
}
ParserMsg::ProgressStart(token) => {
let token = lsp::NumberOrString::Number(token);
let begin = lsp::WorkDoneProgressBegin {
title: "Reparsing affected files".to_string(),
cancellable: Some(false),
message: None,
percentage: Some(100),
};
client
.send_request::<lsp::request::WorkDoneProgressCreate>(
lsp::WorkDoneProgressCreateParams {
token: token.clone(),
},
)
.await
.unwrap();

client
.send_notification::<lsp::notification::Progress>(lsp::ProgressParams {
token,
value: lsp::ProgressParamsValue::WorkDone(
lsp::WorkDoneProgress::Begin(begin),
),
})
.await;
}
ParserMsg::ProgressStep(token, message, pcnt) => {
let token = lsp::NumberOrString::Number(token);
let step = lsp::WorkDoneProgressReport {
cancellable: Some(false),
message: Some(message),
percentage: Some(pcnt),
};
client
.send_notification::<lsp::notification::Progress>(lsp::ProgressParams {
token,
value: lsp::ProgressParamsValue::WorkDone(
lsp::WorkDoneProgress::Report(step),
),
})
.await;
}
ParserMsg::ProgressDone(token) => {
let token = lsp::NumberOrString::Number(token);
client
.send_notification::<lsp::notification::Progress>(lsp::ProgressParams {
token,
value: lsp::ProgressParamsValue::WorkDone(lsp::WorkDoneProgress::End(
lsp::WorkDoneProgressEnd {
message: Some("Finished parsing".to_string()),
},
)),
})
.await;
}
ParserMsg::ProgressCancel(token) => {
let token = lsp::NumberOrString::Number(token);

client
.send_notification::<lsp::notification::Progress>(lsp::ProgressParams {
token: token.clone(),
value: lsp::ProgressParamsValue::WorkDone(lsp::WorkDoneProgress::End(
lsp::WorkDoneProgressEnd {
message: Some("Interrupted will resume".to_string()),
},
)),
})
.await;
client
.send_notification::<lsp::notification::Cancel>(lsp::CancelParams {
id: token.clone(),
})
.await;
}
};
}
}
Expand Down
19 changes: 18 additions & 1 deletion server/src/parse_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ struct File {
#[derive(Debug)]
pub enum ParserMsg {
Info(String),
ProgressStart(i32),
ProgressStep(i32, String, u32),
ProgressDone(i32),
ProgressCancel(i32),
Diagnostics(lsp::Url, Vec<lsp::Diagnostic>, Option<i32>),
}

Expand Down Expand Up @@ -351,6 +355,7 @@ impl ParseThread {

pub fn init(mut self: ParseThread) -> impl FnOnce() {
move || {
let mut token: i32 = std::i32::MIN;
let mut files: std::collections::HashMap<std::path::PathBuf, File> =
std::collections::HashMap::new();
let mut change_set: std::collections::HashSet<TestReparse> =
Expand Down Expand Up @@ -560,21 +565,32 @@ impl ParseThread {
// Parse everything in the change_set.
if let Some((lexerdef, _, _, _)) = &stuff {
if let Some(pb) = &pb {
token += 1;
let n = change_set.len();
self.output
.send(ParserMsg::Info(format!(
"Evaluating changes {:?}",
change_set
)))
.unwrap();
for reparse in change_set.clone() {

self.output.send(ParserMsg::ProgressStart(token)).unwrap();

for (i, reparse) in change_set.clone().iter().enumerate() {
if self.input.peek().is_some() {
self.output.send(ParserMsg::ProgressCancel(token)).unwrap();
continue 'top;
}

let TestReparse { path, pass } = &reparse;
let file = files.get(path);
if let Some(file) = file {
let message: String = format!("{}", path.display());
self.parse_file(file, path, lexerdef, pb, *pass);
let pcnt = ((i as f32 / n as f32) * 100.0).ceil();
self.output
.send(ParserMsg::ProgressStep(token, message, pcnt as u32))
.unwrap();
change_set.remove(&reparse);
} else {
self.output
Expand All @@ -586,6 +602,7 @@ impl ParseThread {
}
}
assert!(change_set.is_empty());
self.output.send(ParserMsg::ProgressDone(token)).unwrap();
self.output
.send(ParserMsg::Info("Finished changes".to_string()))
.unwrap();
Expand Down

0 comments on commit c403506

Please sign in to comment.