Skip to content

Commit 07f690d

Browse files
bors[bot]kjeremy
andauthored
Merge #4161
4161: lsp-types 0.74 r=kjeremy a=kjeremy * Fixes a bunch of param types to take partial progress into account. * Will allow us to support insert/replace text in completions Co-authored-by: kjeremy <[email protected]>
2 parents db441de + 61f1c0a commit 07f690d

File tree

7 files changed

+58
-47
lines changed

7 files changed

+58
-47
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_flycheck/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["rust-analyzer developers"]
66

77
[dependencies]
88
crossbeam-channel = "0.4.0"
9-
lsp-types = { version = "0.73.0", features = ["proposed"] }
9+
lsp-types = { version = "0.74.0", features = ["proposed"] }
1010
log = "0.4.8"
1111
cargo_metadata = "0.9.1"
1212
serde_json = "1.0.48"

crates/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ globset = "0.4.4"
2020
itertools = "0.9.0"
2121
jod-thread = "0.1.0"
2222
log = "0.4.8"
23-
lsp-types = { version = "0.73.0", features = ["proposed"] }
23+
lsp-types = { version = "0.74.0", features = ["proposed"] }
2424
parking_lot = "0.10.0"
2525
pico-args = "0.3.1"
2626
rand = { version = "0.7.3", features = ["small_rng"] }

crates/rust-analyzer/src/conv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem {
150150
detail: self.detail().map(|it| it.to_string()),
151151
filter_text: Some(self.lookup().to_string()),
152152
kind: self.kind().map(|it| it.conv()),
153-
text_edit: Some(text_edit),
153+
text_edit: Some(text_edit.into()),
154154
additional_text_edits: Some(additional_text_edits),
155155
documentation: self.documentation().map(|it| it.conv()),
156156
deprecated: Some(self.deprecated()),

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ pub fn handle_workspace_symbol(
326326

327327
pub fn handle_goto_definition(
328328
world: WorldSnapshot,
329-
params: req::TextDocumentPositionParams,
329+
params: req::GotoDefinitionParams,
330330
) -> Result<Option<req::GotoDefinitionResponse>> {
331331
let _p = profile("handle_goto_definition");
332-
let position = params.try_conv_with(&world)?;
332+
let position = params.text_document_position_params.try_conv_with(&world)?;
333333
let nav_info = match world.analysis().goto_definition(position)? {
334334
None => return Ok(None),
335335
Some(it) => it,
@@ -340,10 +340,10 @@ pub fn handle_goto_definition(
340340

341341
pub fn handle_goto_implementation(
342342
world: WorldSnapshot,
343-
params: req::TextDocumentPositionParams,
343+
params: req::GotoImplementationParams,
344344
) -> Result<Option<req::GotoImplementationResponse>> {
345345
let _p = profile("handle_goto_implementation");
346-
let position = params.try_conv_with(&world)?;
346+
let position = params.text_document_position_params.try_conv_with(&world)?;
347347
let nav_info = match world.analysis().goto_implementation(position)? {
348348
None => return Ok(None),
349349
Some(it) => it,
@@ -354,10 +354,10 @@ pub fn handle_goto_implementation(
354354

355355
pub fn handle_goto_type_definition(
356356
world: WorldSnapshot,
357-
params: req::TextDocumentPositionParams,
357+
params: req::GotoTypeDefinitionParams,
358358
) -> Result<Option<req::GotoTypeDefinitionResponse>> {
359359
let _p = profile("handle_goto_type_definition");
360-
let position = params.try_conv_with(&world)?;
360+
let position = params.text_document_position_params.try_conv_with(&world)?;
361361
let nav_info = match world.analysis().goto_type_definition(position)? {
362362
None => return Ok(None),
363363
Some(it) => it,
@@ -487,10 +487,10 @@ pub fn handle_folding_range(
487487

488488
pub fn handle_signature_help(
489489
world: WorldSnapshot,
490-
params: req::TextDocumentPositionParams,
490+
params: req::SignatureHelpParams,
491491
) -> Result<Option<req::SignatureHelp>> {
492492
let _p = profile("handle_signature_help");
493-
let position = params.try_conv_with(&world)?;
493+
let position = params.text_document_position_params.try_conv_with(&world)?;
494494
if let Some(call_info) = world.analysis().call_info(position)? {
495495
let concise = !world.config.call_info_full;
496496
let mut active_parameter = call_info.active_parameter.map(|it| it as i64);
@@ -509,12 +509,9 @@ pub fn handle_signature_help(
509509
}
510510
}
511511

512-
pub fn handle_hover(
513-
world: WorldSnapshot,
514-
params: req::TextDocumentPositionParams,
515-
) -> Result<Option<Hover>> {
512+
pub fn handle_hover(world: WorldSnapshot, params: req::HoverParams) -> Result<Option<Hover>> {
516513
let _p = profile("handle_hover");
517-
let position = params.try_conv_with(&world)?;
514+
let position = params.text_document_position_params.try_conv_with(&world)?;
518515
let info = match world.analysis().hover(position)? {
519516
None => return Ok(None),
520517
Some(info) => info,
@@ -878,8 +875,14 @@ pub fn handle_code_lens(
878875
.map(|it| {
879876
let range = it.node_range.conv_with(&line_index);
880877
let pos = range.start;
881-
let lens_params =
882-
req::TextDocumentPositionParams::new(params.text_document.clone(), pos);
878+
let lens_params = req::GotoImplementationParams {
879+
text_document_position_params: req::TextDocumentPositionParams::new(
880+
params.text_document.clone(),
881+
pos,
882+
),
883+
work_done_progress_params: Default::default(),
884+
partial_result_params: Default::default(),
885+
};
883886
CodeLens {
884887
range,
885888
command: None,
@@ -894,7 +897,7 @@ pub fn handle_code_lens(
894897
#[derive(Debug, Serialize, Deserialize)]
895898
#[serde(rename_all = "camelCase")]
896899
enum CodeLensResolveData {
897-
Impls(req::TextDocumentPositionParams),
900+
Impls(req::GotoImplementationParams),
898901
}
899902

900903
pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Result<CodeLens> {
@@ -927,7 +930,7 @@ pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Re
927930
title,
928931
command: "rust-analyzer.showReferences".into(),
929932
arguments: Some(vec![
930-
to_value(&lens_params.text_document.uri).unwrap(),
933+
to_value(&lens_params.text_document_position_params.text_document.uri).unwrap(),
931934
to_value(code_lens.range.start).unwrap(),
932935
to_value(locations).unwrap(),
933936
]),
@@ -944,16 +947,16 @@ pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Re
944947

945948
pub fn handle_document_highlight(
946949
world: WorldSnapshot,
947-
params: req::TextDocumentPositionParams,
950+
params: req::DocumentHighlightParams,
948951
) -> Result<Option<Vec<DocumentHighlight>>> {
949952
let _p = profile("handle_document_highlight");
950-
let file_id = params.text_document.try_conv_with(&world)?;
953+
let file_id = params.text_document_position_params.text_document.try_conv_with(&world)?;
951954
let line_index = world.analysis().file_line_index(file_id)?;
952955

953-
let refs = match world
954-
.analysis()
955-
.find_all_refs(params.try_conv_with(&world)?, Some(SearchScope::single_file(file_id)))?
956-
{
956+
let refs = match world.analysis().find_all_refs(
957+
params.text_document_position_params.try_conv_with(&world)?,
958+
Some(SearchScope::single_file(file_id)),
959+
)? {
957960
None => return Ok(None),
958961
Some(refs) => refs,
959962
};

crates/rust-analyzer/src/req.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ pub use lsp_types::{
88
notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
99
CodeLensParams, CompletionParams, CompletionResponse, ConfigurationItem, ConfigurationParams,
1010
DiagnosticTag, DidChangeConfigurationParams, DidChangeWatchedFilesParams,
11-
DidChangeWatchedFilesRegistrationOptions, DocumentOnTypeFormattingParams, DocumentSymbolParams,
12-
DocumentSymbolResponse, FileSystemWatcher, Hover, InitializeResult, MessageType,
13-
PartialResultParams, ProgressParams, ProgressParamsValue, ProgressToken,
14-
PublishDiagnosticsParams, ReferenceParams, Registration, RegistrationParams, SelectionRange,
15-
SelectionRangeParams, SemanticTokensParams, SemanticTokensRangeParams,
11+
DidChangeWatchedFilesRegistrationOptions, DocumentHighlightParams,
12+
DocumentOnTypeFormattingParams, DocumentSymbolParams, DocumentSymbolResponse,
13+
FileSystemWatcher, GotoDefinitionParams, GotoDefinitionResponse, Hover, HoverParams,
14+
InitializeResult, MessageType, PartialResultParams, ProgressParams, ProgressParamsValue,
15+
ProgressToken, PublishDiagnosticsParams, ReferenceParams, Registration, RegistrationParams,
16+
SelectionRange, SelectionRangeParams, SemanticTokensParams, SemanticTokensRangeParams,
1617
SemanticTokensRangeResult, SemanticTokensResult, ServerCapabilities, ShowMessageParams,
17-
SignatureHelp, SymbolKind, TextDocumentEdit, TextDocumentPositionParams, TextEdit,
18-
WorkDoneProgressParams, WorkspaceEdit, WorkspaceSymbolParams,
18+
SignatureHelp, SignatureHelpParams, SymbolKind, TextDocumentEdit, TextDocumentPositionParams,
19+
TextEdit, WorkDoneProgressParams, WorkspaceEdit, WorkspaceSymbolParams,
1920
};
2021
use std::path::PathBuf;
2122

crates/rust-analyzer/tests/heavy_tests/main.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::{collections::HashMap, path::PathBuf, time::Instant};
44

55
use lsp_types::{
66
CodeActionContext, DidOpenTextDocumentParams, DocumentFormattingParams, FormattingOptions,
7-
PartialResultParams, Position, Range, TextDocumentItem, TextDocumentPositionParams,
8-
WorkDoneProgressParams,
7+
GotoDefinitionParams, HoverParams, PartialResultParams, Position, Range, TextDocumentItem,
8+
TextDocumentPositionParams, WorkDoneProgressParams,
99
};
1010
use rust_analyzer::req::{
1111
CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument,
@@ -610,10 +610,14 @@ fn main() { message(); }
610610
})
611611
.server();
612612
server.wait_until_workspace_is_loaded();
613-
let res = server.send_request::<GotoDefinition>(TextDocumentPositionParams::new(
614-
server.doc_id("src/main.rs"),
615-
Position::new(2, 15),
616-
));
613+
let res = server.send_request::<GotoDefinition>(GotoDefinitionParams {
614+
text_document_position_params: TextDocumentPositionParams::new(
615+
server.doc_id("src/main.rs"),
616+
Position::new(2, 15),
617+
),
618+
work_done_progress_params: Default::default(),
619+
partial_result_params: Default::default(),
620+
});
617621
assert!(format!("{}", res).contains("hello.rs"));
618622
}
619623

@@ -692,10 +696,13 @@ pub fn foo(_input: TokenStream) -> TokenStream {
692696
.root("bar")
693697
.server();
694698
server.wait_until_workspace_is_loaded();
695-
let res = server.send_request::<HoverRequest>(TextDocumentPositionParams::new(
696-
server.doc_id("foo/src/main.rs"),
697-
Position::new(7, 9),
698-
));
699+
let res = server.send_request::<HoverRequest>(HoverParams {
700+
text_document_position_params: TextDocumentPositionParams::new(
701+
server.doc_id("foo/src/main.rs"),
702+
Position::new(7, 9),
703+
),
704+
work_done_progress_params: Default::default(),
705+
});
699706

700707
let value = res.get("contents").unwrap().get("value").unwrap().to_string();
701708
assert_eq!(value, r#""```rust\nfoo::Bar\nfn bar()\n```""#)

0 commit comments

Comments
 (0)