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

View file

@ -6,7 +6,7 @@ authors = ["rust-analyzer developers"]
[dependencies] [dependencies]
crossbeam-channel = "0.4.0" 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" log = "0.4.8"
cargo_metadata = "0.9.1" cargo_metadata = "0.9.1"
serde_json = "1.0.48" serde_json = "1.0.48"

View file

@ -20,7 +20,7 @@ globset = "0.4.4"
itertools = "0.9.0" itertools = "0.9.0"
jod-thread = "0.1.0" jod-thread = "0.1.0"
log = "0.4.8" 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" parking_lot = "0.10.0"
pico-args = "0.3.1" pico-args = "0.3.1"
rand = { version = "0.7.3", features = ["small_rng"] } rand = { version = "0.7.3", features = ["small_rng"] }

View file

@ -149,7 +149,7 @@ impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem {
detail: self.detail().map(|it| it.to_string()), detail: self.detail().map(|it| it.to_string()),
filter_text: Some(self.lookup().to_string()), filter_text: Some(self.lookup().to_string()),
kind: self.kind().map(|it| it.conv()), 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), additional_text_edits: Some(additional_text_edits),
documentation: self.documentation().map(|it| it.conv()), documentation: self.documentation().map(|it| it.conv()),
deprecated: Some(self.deprecated()), deprecated: Some(self.deprecated()),

View file

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

View file

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

View file

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