lsp-types 0.74

* Fixes a bunch of param types to take partial progress into account.
* Will allow us to support insert/replace text in completions
This commit is contained in:
kjeremy 2020-04-26 16:05:22 -04:00
parent 99c287148e
commit 61f1c0a990
7 changed files with 58 additions and 47 deletions

8
Cargo.lock generated
View File

@ -68,9 +68,9 @@ dependencies = [
[[package]]
name = "base64"
version = "0.11.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
checksum = "7d5ca2cd0adc3f48f9e9ea5a6bbdf9ccc0bfade884847e484d452414c7ccffb3"
[[package]]
name = "bitflags"
@ -645,9 +645,9 @@ dependencies = [
[[package]]
name = "lsp-types"
version = "0.73.0"
version = "0.74.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93d0cf64ea141b43d9e055f6b9df13f0bce32b103d84237509ce0a571ab9b159"
checksum = "820f746e5716ab9a2d664794636188bd003023b72e55404ee27105dc22869922"
dependencies = [
"base64",
"bitflags",

View File

@ -6,7 +6,7 @@ authors = ["rust-analyzer developers"]
[dependencies]
crossbeam-channel = "0.4.0"
lsp-types = { version = "0.73.0", features = ["proposed"] }
lsp-types = { version = "0.74.0", features = ["proposed"] }
log = "0.4.8"
cargo_metadata = "0.9.1"
serde_json = "1.0.48"

View File

@ -20,7 +20,7 @@ globset = "0.4.4"
itertools = "0.9.0"
jod-thread = "0.1.0"
log = "0.4.8"
lsp-types = { version = "0.73.0", features = ["proposed"] }
lsp-types = { version = "0.74.0", features = ["proposed"] }
parking_lot = "0.10.0"
pico-args = "0.3.1"
rand = { version = "0.7.3", features = ["small_rng"] }

View File

@ -149,7 +149,7 @@ fn conv_with(self, ctx: (&LineIndex, LineEndings)) -> ::lsp_types::CompletionIte
detail: self.detail().map(|it| it.to_string()),
filter_text: Some(self.lookup().to_string()),
kind: self.kind().map(|it| it.conv()),
text_edit: Some(text_edit),
text_edit: Some(text_edit.into()),
additional_text_edits: Some(additional_text_edits),
documentation: self.documentation().map(|it| it.conv()),
deprecated: Some(self.deprecated()),

View File

@ -326,10 +326,10 @@ fn exec_query(world: &WorldSnapshot, query: Query) -> Result<Vec<SymbolInformati
pub fn handle_goto_definition(
world: WorldSnapshot,
params: req::TextDocumentPositionParams,
params: req::GotoDefinitionParams,
) -> Result<Option<req::GotoDefinitionResponse>> {
let _p = profile("handle_goto_definition");
let position = params.try_conv_with(&world)?;
let position = params.text_document_position_params.try_conv_with(&world)?;
let nav_info = match world.analysis().goto_definition(position)? {
None => return Ok(None),
Some(it) => it,
@ -340,10 +340,10 @@ pub fn handle_goto_definition(
pub fn handle_goto_implementation(
world: WorldSnapshot,
params: req::TextDocumentPositionParams,
params: req::GotoImplementationParams,
) -> Result<Option<req::GotoImplementationResponse>> {
let _p = profile("handle_goto_implementation");
let position = params.try_conv_with(&world)?;
let position = params.text_document_position_params.try_conv_with(&world)?;
let nav_info = match world.analysis().goto_implementation(position)? {
None => return Ok(None),
Some(it) => it,
@ -354,10 +354,10 @@ pub fn handle_goto_implementation(
pub fn handle_goto_type_definition(
world: WorldSnapshot,
params: req::TextDocumentPositionParams,
params: req::GotoTypeDefinitionParams,
) -> Result<Option<req::GotoTypeDefinitionResponse>> {
let _p = profile("handle_goto_type_definition");
let position = params.try_conv_with(&world)?;
let position = params.text_document_position_params.try_conv_with(&world)?;
let nav_info = match world.analysis().goto_type_definition(position)? {
None => return Ok(None),
Some(it) => it,
@ -487,10 +487,10 @@ pub fn handle_folding_range(
pub fn handle_signature_help(
world: WorldSnapshot,
params: req::TextDocumentPositionParams,
params: req::SignatureHelpParams,
) -> Result<Option<req::SignatureHelp>> {
let _p = profile("handle_signature_help");
let position = params.try_conv_with(&world)?;
let position = params.text_document_position_params.try_conv_with(&world)?;
if let Some(call_info) = world.analysis().call_info(position)? {
let concise = !world.config.call_info_full;
let mut active_parameter = call_info.active_parameter.map(|it| it as i64);
@ -509,12 +509,9 @@ pub fn handle_signature_help(
}
}
pub fn handle_hover(
world: WorldSnapshot,
params: req::TextDocumentPositionParams,
) -> Result<Option<Hover>> {
pub fn handle_hover(world: WorldSnapshot, params: req::HoverParams) -> Result<Option<Hover>> {
let _p = profile("handle_hover");
let position = params.try_conv_with(&world)?;
let position = params.text_document_position_params.try_conv_with(&world)?;
let info = match world.analysis().hover(position)? {
None => return Ok(None),
Some(info) => info,
@ -878,8 +875,14 @@ pub fn handle_code_lens(
.map(|it| {
let range = it.node_range.conv_with(&line_index);
let pos = range.start;
let lens_params =
req::TextDocumentPositionParams::new(params.text_document.clone(), pos);
let lens_params = req::GotoImplementationParams {
text_document_position_params: req::TextDocumentPositionParams::new(
params.text_document.clone(),
pos,
),
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
};
CodeLens {
range,
command: None,
@ -894,7 +897,7 @@ pub fn handle_code_lens(
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
enum CodeLensResolveData {
Impls(req::TextDocumentPositionParams),
Impls(req::GotoImplementationParams),
}
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
title,
command: "rust-analyzer.showReferences".into(),
arguments: Some(vec![
to_value(&lens_params.text_document.uri).unwrap(),
to_value(&lens_params.text_document_position_params.text_document.uri).unwrap(),
to_value(code_lens.range.start).unwrap(),
to_value(locations).unwrap(),
]),
@ -944,16 +947,16 @@ pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Re
pub fn handle_document_highlight(
world: WorldSnapshot,
params: req::TextDocumentPositionParams,
params: req::DocumentHighlightParams,
) -> Result<Option<Vec<DocumentHighlight>>> {
let _p = profile("handle_document_highlight");
let file_id = params.text_document.try_conv_with(&world)?;
let file_id = params.text_document_position_params.text_document.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(file_id)?;
let refs = match world
.analysis()
.find_all_refs(params.try_conv_with(&world)?, Some(SearchScope::single_file(file_id)))?
{
let refs = match world.analysis().find_all_refs(
params.text_document_position_params.try_conv_with(&world)?,
Some(SearchScope::single_file(file_id)),
)? {
None => return Ok(None),
Some(refs) => refs,
};

View File

@ -8,14 +8,15 @@
notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
CodeLensParams, CompletionParams, CompletionResponse, ConfigurationItem, ConfigurationParams,
DiagnosticTag, DidChangeConfigurationParams, DidChangeWatchedFilesParams,
DidChangeWatchedFilesRegistrationOptions, DocumentOnTypeFormattingParams, DocumentSymbolParams,
DocumentSymbolResponse, FileSystemWatcher, Hover, InitializeResult, MessageType,
PartialResultParams, ProgressParams, ProgressParamsValue, ProgressToken,
PublishDiagnosticsParams, ReferenceParams, Registration, RegistrationParams, SelectionRange,
SelectionRangeParams, SemanticTokensParams, SemanticTokensRangeParams,
DidChangeWatchedFilesRegistrationOptions, DocumentHighlightParams,
DocumentOnTypeFormattingParams, DocumentSymbolParams, DocumentSymbolResponse,
FileSystemWatcher, GotoDefinitionParams, GotoDefinitionResponse, Hover, HoverParams,
InitializeResult, MessageType, PartialResultParams, ProgressParams, ProgressParamsValue,
ProgressToken, PublishDiagnosticsParams, ReferenceParams, Registration, RegistrationParams,
SelectionRange, SelectionRangeParams, SemanticTokensParams, SemanticTokensRangeParams,
SemanticTokensRangeResult, SemanticTokensResult, ServerCapabilities, ShowMessageParams,
SignatureHelp, SymbolKind, TextDocumentEdit, TextDocumentPositionParams, TextEdit,
WorkDoneProgressParams, WorkspaceEdit, WorkspaceSymbolParams,
SignatureHelp, SignatureHelpParams, SymbolKind, TextDocumentEdit, TextDocumentPositionParams,
TextEdit, WorkDoneProgressParams, WorkspaceEdit, WorkspaceSymbolParams,
};
use std::path::PathBuf;

View File

@ -4,8 +4,8 @@
use lsp_types::{
CodeActionContext, DidOpenTextDocumentParams, DocumentFormattingParams, FormattingOptions,
PartialResultParams, Position, Range, TextDocumentItem, TextDocumentPositionParams,
WorkDoneProgressParams,
GotoDefinitionParams, HoverParams, PartialResultParams, Position, Range, TextDocumentItem,
TextDocumentPositionParams, WorkDoneProgressParams,
};
use rust_analyzer::req::{
CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument,
@ -610,10 +610,14 @@ fn main() {
})
.server();
server.wait_until_workspace_is_loaded();
let res = server.send_request::<GotoDefinition>(TextDocumentPositionParams::new(
let res = server.send_request::<GotoDefinition>(GotoDefinitionParams {
text_document_position_params: TextDocumentPositionParams::new(
server.doc_id("src/main.rs"),
Position::new(2, 15),
));
),
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
});
assert!(format!("{}", res).contains("hello.rs"));
}
@ -692,10 +696,13 @@ pub fn foo(_input: TokenStream) -> TokenStream {
.root("bar")
.server();
server.wait_until_workspace_is_loaded();
let res = server.send_request::<HoverRequest>(TextDocumentPositionParams::new(
let res = server.send_request::<HoverRequest>(HoverParams {
text_document_position_params: TextDocumentPositionParams::new(
server.doc_id("foo/src/main.rs"),
Position::new(7, 9),
));
),
work_done_progress_params: Default::default(),
});
let value = res.get("contents").unwrap().get("value").unwrap().to_string();
assert_eq!(value, r#""```rust\nfoo::Bar\nfn bar()\n```""#)