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

feat: update lsp_types to the latest version #1778

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ env_logger = "0.9"
home = "0.5.1"
itertools = "0.10"
jsonrpc-core = "18"
lsp-types = { version = "0.60", features = ["proposed"] }
lsp-types = { version = "0.92", features = ["proposed"] }
lazy_static = "1"
log = "0.4"
num_cpus = "1"
Expand Down
9 changes: 6 additions & 3 deletions rls/src/actions/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ pub fn parse_diagnostics(
source: Some(source.to_owned()),
message: diagnostic_message,
related_information,
code_description: None,
tags: None,
data: None,
};

(file_path, (diagnostic, suggestions))
Expand Down Expand Up @@ -193,9 +196,9 @@ fn format_notes(children: &[AssociatedMessage], primary: &DiagnosticSpan) -> Opt

fn severity(level: &str, is_primary_span: bool) -> DiagnosticSeverity {
match (level, is_primary_span) {
(_, false) => DiagnosticSeverity::Information,
("error", _) => DiagnosticSeverity::Error,
(..) => DiagnosticSeverity::Warning,
(_, false) => DiagnosticSeverity::INFORMATION,
("error", _) => DiagnosticSeverity::ERROR,
(..) => DiagnosticSeverity::WARNING,
}
}

Expand Down
6 changes: 3 additions & 3 deletions rls/src/actions/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ impl Rustfmt {
.into_iter()
.map(|item| {
// Rustfmt's line indices are 1-based
let start_line = u64::from(item.line_number_orig) - 1;
let end_line = start_line + u64::from(item.lines_removed);
let start_line = item.line_number_orig - 1;
let end_line = start_line + item.lines_removed;

let mut new_text = item.lines.join(newline);

Expand Down Expand Up @@ -242,7 +242,7 @@ mod tests {
Rustfmt::Internal.calc_text_edits(input.to_string(), config()).unwrap()
}

fn test_case(input: &str, output: Vec<(u64, u64, u64, u64, &str)>) {
fn test_case(input: &str, output: Vec<(u32, u32, u32, u32, &str)>) {
assert_eq!(
format(input),
output
Expand Down
7 changes: 4 additions & 3 deletions rls/src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ impl FileWatch {
}

let local = &path[self.project_uri.len()..];
local == "/Cargo.lock" || (local == "/target" && kind == FileChangeType::Deleted)
local == "/Cargo.lock" || (local == "/target" && kind == FileChangeType::DELETED)
}

#[inline]
Expand All @@ -589,7 +589,7 @@ impl FileWatch {

#[inline]
pub fn is_relevant_save_doc(&self, did_save: &DidSaveTextDocumentParams) -> bool {
self.relevant_change_kind(&did_save.text_document.uri, FileChangeType::Changed)
self.relevant_change_kind(&did_save.text_document.uri, FileChangeType::CHANGED)
}
}

Expand Down Expand Up @@ -629,12 +629,13 @@ mod test {
}

fn change(url: &str) -> FileEvent {
FileEvent::new(Url::parse(url).unwrap(), FileChangeType::Changed)
FileEvent::new(Url::parse(url).unwrap(), FileChangeType::CHANGED)
}

fn did_save(url: &str) -> DidSaveTextDocumentParams {
DidSaveTextDocumentParams {
text_document: TextDocumentIdentifier::new(Url::parse(url).unwrap()),
text: None,
}
}

Expand Down
8 changes: 4 additions & 4 deletions rls/src/actions/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ impl BlockingNotificationAction for DidChangeTextDocument {

ctx.quiescent.store(false, Ordering::SeqCst);
let file_path = parse_file_path!(&params.text_document.uri, "on_change")?;
let version_num = params.text_document.version.unwrap();
let version_num = params.text_document.version as u64;

match ctx.check_change_version(&file_path, version_num) {
VersionOrdering::Ok => {}
VersionOrdering::Duplicate => return Ok(()),
VersionOrdering::OutOfOrder => {
out.notify(Notification::<ShowMessage>::new(ShowMessageParams {
typ: MessageType::Warning,
typ: MessageType::WARNING,
message: format!("Out of order change in {:?}", file_path),
}));
return Ok(());
Expand All @@ -99,7 +99,7 @@ impl BlockingNotificationAction for DidChangeTextDocument {
// LSP sends UTF-16 code units based offsets and length
span: VfsSpan::from_utf16(
Span::from_range(range, file_path.clone()),
i.range_length,
i.range_length.map(|l| l as u64),
),
text: i.text.clone(),
}
Expand Down Expand Up @@ -311,7 +311,7 @@ mod test {
let manifest_change = Url::parse(lsp_project_manifest).unwrap();
DidChangeWatchedFiles::handle(
DidChangeWatchedFilesParams {
changes: vec![FileEvent::new(manifest_change, FileChangeType::Changed)],
changes: vec![FileEvent::new(manifest_change, FileChangeType::CHANGED)],
},
&mut ctx,
NoOutput,
Expand Down
5 changes: 3 additions & 2 deletions rls/src/actions/post_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl PostBuildHandler {
Diagnostic {
range,
message,
severity: Some(DiagnosticSeverity::Error),
severity: Some(DiagnosticSeverity::ERROR),
..Diagnostic::default()
},
vec![],
Expand Down Expand Up @@ -206,10 +206,11 @@ impl PostBuildHandler {
.iter()
.map(|(diag, _)| diag)
.filter(|diag| {
self.show_warnings || diag.severity != Some(DiagnosticSeverity::Warning)
self.show_warnings || diag.severity != Some(DiagnosticSeverity::WARNING)
})
.cloned()
.collect(),
version: None,
};

self.notifier.notify_publish_diagnostics(params);
Expand Down
67 changes: 54 additions & 13 deletions rls/src/actions/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use crate::server::{Notification, Output};
use lazy_static::lazy_static;
use lsp_types::notification::{Progress, PublishDiagnostics, ShowMessage};
use lsp_types::{MessageType, ProgressParams, PublishDiagnosticsParams, ShowMessageParams};
use lsp_types::{
MessageType, NumberOrString, ProgressParams, ProgressParamsValue, PublishDiagnosticsParams,
ShowMessageParams, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressEnd,
WorkDoneProgressReport,
};

/// Communication of build progress back to the client.
pub trait ProgressNotifier: Send {
Expand Down Expand Up @@ -37,11 +41,16 @@ fn new_progress_params(title: String) -> ProgressParams {
}

ProgressParams {
id: format!("progress_{}", PROGRESS_ID_COUNTER.fetch_add(1, Ordering::SeqCst)),
title,
message: None,
percentage: None,
done: None,
token: NumberOrString::String(format!(
"progress_{}",
PROGRESS_ID_COUNTER.fetch_add(1, Ordering::SeqCst)
)),
value: ProgressParamsValue::WorkDone(WorkDoneProgress::Begin(WorkDoneProgressBegin {
title,
cancellable: None,
message: None,
percentage: None,
})),
}
}

Expand All @@ -67,15 +76,45 @@ impl<O: Output> ProgressNotifier for BuildProgressNotifier<O> {
}
fn notify_progress(&self, update: ProgressUpdate) {
let mut params = self.progress_params.clone();
match update {
ProgressUpdate::Message(s) => params.message = Some(s),
ProgressUpdate::Percentage(p) => params.percentage = Some(p),
}

// set the value to WorkDoneProgress::Report if it is not
match &mut params.value {
ProgressParamsValue::WorkDone(work) => match work {
WorkDoneProgress::Report(_) => {}
_ => {
params.value = ProgressParamsValue::WorkDone(WorkDoneProgress::Report(
WorkDoneProgressReport {
cancellable: None,
message: None,
percentage: None,
},
))
}
},
};

match &mut params.value {
ProgressParamsValue::WorkDone(work) => match work {
WorkDoneProgress::Report(value) => match update {
ProgressUpdate::Message(m) => {
value.message = Some(m);
}
ProgressUpdate::Percentage(p) => {
value.percentage = Some(p as u32);
}
},
_ => {
unreachable!("params.value is set to WorkDoneProgress::Report");
}
},
};
self.out.notify(Notification::<Progress>::new(params));
}
fn notify_end_progress(&self) {
let mut params = self.progress_params.clone();
params.done = Some(true);
params.value = ProgressParamsValue::WorkDone(WorkDoneProgress::End(WorkDoneProgressEnd {
message: None,
}));
self.out.notify(Notification::<Progress>::new(params));
}
}
Expand Down Expand Up @@ -110,13 +149,15 @@ impl<O: Output> DiagnosticsNotifier for BuildDiagnosticsNotifier<O> {
}
fn notify_error_diagnostics(&self, message: String) {
self.out.notify(Notification::<ShowMessage>::new(ShowMessageParams {
typ: MessageType::Error,
typ: MessageType::ERROR,
message,
}));
}
fn notify_end_diagnostics(&self) {
let mut params = self.progress_params.clone();
params.done = Some(true);
params.value = ProgressParamsValue::WorkDone(WorkDoneProgress::End(WorkDoneProgressEnd {
message: None,
}));
self.out.notify(Notification::<Progress>::new(params));
}
}
Loading