Don't re-export lsp_types

This commit is contained in:
Aleksey Kladov
2020-05-10 19:24:02 +02:00
parent a78e1573b1
commit bec3bf701c
3 changed files with 119 additions and 119 deletions

View File

@@ -104,7 +104,7 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
if project_roots.is_empty() && config.notifications.cargo_toml_not_found { if project_roots.is_empty() && config.notifications.cargo_toml_not_found {
show_message( show_message(
req::MessageType::Error, lsp_types::MessageType::Error,
format!( format!(
"rust-analyzer failed to discover workspace, no Cargo.toml found, dirs searched: {}", "rust-analyzer failed to discover workspace, no Cargo.toml found, dirs searched: {}",
ws_roots.iter().format_with(", ", |it, f| f(&it.display())) ws_roots.iter().format_with(", ", |it, f| f(&it.display()))
@@ -124,7 +124,7 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
.map_err(|err| { .map_err(|err| {
log::error!("failed to load workspace: {:#}", err); log::error!("failed to load workspace: {:#}", err);
show_message( show_message(
req::MessageType::Error, lsp_types::MessageType::Error,
format!("rust-analyzer failed to load workspace: {:#}", err), format!("rust-analyzer failed to load workspace: {:#}", err),
&connection.sender, &connection.sender,
); );
@@ -142,23 +142,25 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
.collect::<std::result::Result<Vec<_>, _>>()?; .collect::<std::result::Result<Vec<_>, _>>()?;
if let FilesWatcher::Client = config.files.watcher { if let FilesWatcher::Client = config.files.watcher {
let registration_options = req::DidChangeWatchedFilesRegistrationOptions { let registration_options = lsp_types::DidChangeWatchedFilesRegistrationOptions {
watchers: workspaces watchers: workspaces
.iter() .iter()
.flat_map(ProjectWorkspace::to_roots) .flat_map(ProjectWorkspace::to_roots)
.filter(PackageRoot::is_member) .filter(PackageRoot::is_member)
.map(|root| format!("{}/**/*.rs", root.path().display())) .map(|root| format!("{}/**/*.rs", root.path().display()))
.map(|glob_pattern| req::FileSystemWatcher { glob_pattern, kind: None }) .map(|glob_pattern| lsp_types::FileSystemWatcher { glob_pattern, kind: None })
.collect(), .collect(),
}; };
let registration = req::Registration { let registration = lsp_types::Registration {
id: "file-watcher".to_string(), id: "file-watcher".to_string(),
method: "workspace/didChangeWatchedFiles".to_string(), method: "workspace/didChangeWatchedFiles".to_string(),
register_options: Some(serde_json::to_value(registration_options).unwrap()), register_options: Some(serde_json::to_value(registration_options).unwrap()),
}; };
let params = req::RegistrationParams { registrations: vec![registration] }; let params = lsp_types::RegistrationParams { registrations: vec![registration] };
let request = let request = request_new::<lsp_types::request::RegisterCapability>(
request_new::<req::RegisterCapability>(loop_state.next_request_id(), params); loop_state.next_request_id(),
params,
);
connection.sender.send(request.into()).unwrap(); connection.sender.send(request.into()).unwrap();
} }
@@ -258,14 +260,14 @@ impl fmt::Debug for Event {
match self { match self {
Event::Msg(Message::Notification(not)) => { Event::Msg(Message::Notification(not)) => {
if notification_is::<req::DidOpenTextDocument>(not) if notification_is::<lsp_types::notification::DidOpenTextDocument>(not)
|| notification_is::<req::DidChangeTextDocument>(not) || notification_is::<lsp_types::notification::DidChangeTextDocument>(not)
{ {
return debug_verbose_not(not, f); return debug_verbose_not(not, f);
} }
} }
Event::Task(Task::Notify(not)) => { Event::Task(Task::Notify(not)) => {
if notification_is::<req::PublishDiagnostics>(not) { if notification_is::<lsp_types::notification::PublishDiagnostics>(not) {
return debug_verbose_not(not, f); return debug_verbose_not(not, f);
} }
} }
@@ -450,7 +452,7 @@ fn loop_turn(
log::error!("overly long loop turn: {:?}", loop_duration); log::error!("overly long loop turn: {:?}", loop_duration);
if env::var("RA_PROFILE").is_ok() { if env::var("RA_PROFILE").is_ok() {
show_message( show_message(
req::MessageType::Error, lsp_types::MessageType::Error,
format!("overly long loop turn: {:?}", loop_duration), format!("overly long loop turn: {:?}", loop_duration),
&connection.sender, &connection.sender,
); );
@@ -503,7 +505,7 @@ fn on_request(
.on_sync::<req::CollectGarbage>(|s, ()| Ok(s.collect_garbage()))? .on_sync::<req::CollectGarbage>(|s, ()| Ok(s.collect_garbage()))?
.on_sync::<req::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))? .on_sync::<req::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
.on_sync::<req::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))? .on_sync::<req::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
.on_sync::<req::SelectionRangeRequest>(|s, p| { .on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| {
handlers::handle_selection_range(s.snapshot(), p) handlers::handle_selection_range(s.snapshot(), p)
})? })?
.on_sync::<req::FindMatchingBrace>(|s, p| { .on_sync::<req::FindMatchingBrace>(|s, p| {
@@ -512,32 +514,38 @@ fn on_request(
.on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)? .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)?
.on::<req::SyntaxTree>(handlers::handle_syntax_tree)? .on::<req::SyntaxTree>(handlers::handle_syntax_tree)?
.on::<req::ExpandMacro>(handlers::handle_expand_macro)? .on::<req::ExpandMacro>(handlers::handle_expand_macro)?
.on::<req::OnTypeFormatting>(handlers::handle_on_type_formatting)? .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)?
.on::<req::DocumentSymbolRequest>(handlers::handle_document_symbol)? .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)?
.on::<req::WorkspaceSymbol>(handlers::handle_workspace_symbol)? .on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)?
.on::<req::GotoDefinition>(handlers::handle_goto_definition)? .on::<lsp_types::request::GotoDefinition>(handlers::handle_goto_definition)?
.on::<req::GotoImplementation>(handlers::handle_goto_implementation)? .on::<lsp_types::request::GotoImplementation>(handlers::handle_goto_implementation)?
.on::<req::GotoTypeDefinition>(handlers::handle_goto_type_definition)? .on::<lsp_types::request::GotoTypeDefinition>(handlers::handle_goto_type_definition)?
.on::<req::ParentModule>(handlers::handle_parent_module)? .on::<req::ParentModule>(handlers::handle_parent_module)?
.on::<req::Runnables>(handlers::handle_runnables)? .on::<req::Runnables>(handlers::handle_runnables)?
.on::<req::Completion>(handlers::handle_completion)? .on::<lsp_types::request::Completion>(handlers::handle_completion)?
.on::<req::CodeActionRequest>(handlers::handle_code_action)? .on::<lsp_types::request::CodeActionRequest>(handlers::handle_code_action)?
.on::<req::CodeLensRequest>(handlers::handle_code_lens)? .on::<lsp_types::request::CodeLensRequest>(handlers::handle_code_lens)?
.on::<req::CodeLensResolve>(handlers::handle_code_lens_resolve)? .on::<lsp_types::request::CodeLensResolve>(handlers::handle_code_lens_resolve)?
.on::<req::FoldingRangeRequest>(handlers::handle_folding_range)? .on::<lsp_types::request::FoldingRangeRequest>(handlers::handle_folding_range)?
.on::<req::SignatureHelpRequest>(handlers::handle_signature_help)? .on::<lsp_types::request::SignatureHelpRequest>(handlers::handle_signature_help)?
.on::<req::HoverRequest>(handlers::handle_hover)? .on::<lsp_types::request::HoverRequest>(handlers::handle_hover)?
.on::<req::PrepareRenameRequest>(handlers::handle_prepare_rename)? .on::<lsp_types::request::PrepareRenameRequest>(handlers::handle_prepare_rename)?
.on::<req::Rename>(handlers::handle_rename)? .on::<lsp_types::request::Rename>(handlers::handle_rename)?
.on::<req::References>(handlers::handle_references)? .on::<lsp_types::request::References>(handlers::handle_references)?
.on::<req::Formatting>(handlers::handle_formatting)? .on::<lsp_types::request::Formatting>(handlers::handle_formatting)?
.on::<req::DocumentHighlightRequest>(handlers::handle_document_highlight)? .on::<lsp_types::request::DocumentHighlightRequest>(handlers::handle_document_highlight)?
.on::<req::InlayHints>(handlers::handle_inlay_hints)? .on::<req::InlayHints>(handlers::handle_inlay_hints)?
.on::<req::CallHierarchyPrepare>(handlers::handle_call_hierarchy_prepare)? .on::<lsp_types::request::CallHierarchyPrepare>(handlers::handle_call_hierarchy_prepare)?
.on::<req::CallHierarchyIncomingCalls>(handlers::handle_call_hierarchy_incoming)? .on::<lsp_types::request::CallHierarchyIncomingCalls>(
.on::<req::CallHierarchyOutgoingCalls>(handlers::handle_call_hierarchy_outgoing)? handlers::handle_call_hierarchy_incoming,
.on::<req::SemanticTokensRequest>(handlers::handle_semantic_tokens)? )?
.on::<req::SemanticTokensRangeRequest>(handlers::handle_semantic_tokens_range)? .on::<lsp_types::request::CallHierarchyOutgoingCalls>(
handlers::handle_call_hierarchy_outgoing,
)?
.on::<lsp_types::request::SemanticTokensRequest>(handlers::handle_semantic_tokens)?
.on::<lsp_types::request::SemanticTokensRangeRequest>(
handlers::handle_semantic_tokens_range,
)?
.on::<req::Ssr>(handlers::handle_ssr)? .on::<req::Ssr>(handlers::handle_ssr)?
.finish(); .finish();
Ok(()) Ok(())
@@ -549,7 +557,7 @@ fn on_notification(
loop_state: &mut LoopState, loop_state: &mut LoopState,
not: Notification, not: Notification,
) -> Result<()> { ) -> Result<()> {
let not = match notification_cast::<req::Cancel>(not) { let not = match notification_cast::<lsp_types::notification::Cancel>(not) {
Ok(params) => { Ok(params) => {
let id: RequestId = match params.id { let id: RequestId = match params.id {
NumberOrString::Number(id) => id.into(), NumberOrString::Number(id) => id.into(),
@@ -567,7 +575,7 @@ fn on_notification(
} }
Err(not) => not, Err(not) => not,
}; };
let not = match notification_cast::<req::DidOpenTextDocument>(not) { let not = match notification_cast::<lsp_types::notification::DidOpenTextDocument>(not) {
Ok(params) => { Ok(params) => {
let uri = params.text_document.uri; let uri = params.text_document.uri;
let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?; let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?;
@@ -580,7 +588,7 @@ fn on_notification(
} }
Err(not) => not, Err(not) => not,
}; };
let not = match notification_cast::<req::DidChangeTextDocument>(not) { let not = match notification_cast::<lsp_types::notification::DidChangeTextDocument>(not) {
Ok(params) => { Ok(params) => {
let DidChangeTextDocumentParams { text_document, content_changes } = params; let DidChangeTextDocumentParams { text_document, content_changes } = params;
let world = state.snapshot(); let world = state.snapshot();
@@ -595,7 +603,7 @@ fn on_notification(
} }
Err(not) => not, Err(not) => not,
}; };
let not = match notification_cast::<req::DidSaveTextDocument>(not) { let not = match notification_cast::<lsp_types::notification::DidSaveTextDocument>(not) {
Ok(_params) => { Ok(_params) => {
if let Some(flycheck) = &state.flycheck { if let Some(flycheck) = &state.flycheck {
flycheck.update(); flycheck.update();
@@ -604,7 +612,7 @@ fn on_notification(
} }
Err(not) => not, Err(not) => not,
}; };
let not = match notification_cast::<req::DidCloseTextDocument>(not) { let not = match notification_cast::<lsp_types::notification::DidCloseTextDocument>(not) {
Ok(params) => { Ok(params) => {
let uri = params.text_document.uri; let uri = params.text_document.uri;
let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?; let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?;
@@ -612,22 +620,22 @@ fn on_notification(
loop_state.subscriptions.remove_sub(FileId(file_id.0)); loop_state.subscriptions.remove_sub(FileId(file_id.0));
} }
let params = let params =
req::PublishDiagnosticsParams { uri, diagnostics: Vec::new(), version: None }; lsp_types::PublishDiagnosticsParams { uri, diagnostics: Vec::new(), version: None };
let not = notification_new::<req::PublishDiagnostics>(params); let not = notification_new::<lsp_types::notification::PublishDiagnostics>(params);
msg_sender.send(not.into()).unwrap(); msg_sender.send(not.into()).unwrap();
return Ok(()); return Ok(());
} }
Err(not) => not, Err(not) => not,
}; };
let not = match notification_cast::<req::DidChangeConfiguration>(not) { let not = match notification_cast::<lsp_types::notification::DidChangeConfiguration>(not) {
Ok(_) => { Ok(_) => {
// As stated in https://github.com/microsoft/language-server-protocol/issues/676, // As stated in https://github.com/microsoft/language-server-protocol/issues/676,
// this notification's parameters should be ignored and the actual config queried separately. // this notification's parameters should be ignored and the actual config queried separately.
let request_id = loop_state.next_request_id(); let request_id = loop_state.next_request_id();
let request = request_new::<req::WorkspaceConfiguration>( let request = request_new::<lsp_types::request::WorkspaceConfiguration>(
request_id.clone(), request_id.clone(),
req::ConfigurationParams { lsp_types::ConfigurationParams {
items: vec![req::ConfigurationItem { items: vec![lsp_types::ConfigurationItem {
scope_uri: None, scope_uri: None,
section: Some("rust-analyzer".to_string()), section: Some("rust-analyzer".to_string()),
}], }],
@@ -640,7 +648,7 @@ fn on_notification(
} }
Err(not) => not, Err(not) => not,
}; };
let not = match notification_cast::<req::DidChangeWatchedFiles>(not) { let not = match notification_cast::<lsp_types::notification::DidChangeWatchedFiles>(not) {
Ok(params) => { Ok(params) => {
let mut vfs = state.vfs.write(); let mut vfs = state.vfs.write();
for change in params.changes { for change in params.changes {
@@ -742,11 +750,11 @@ fn on_check_task(
} }
CheckTask::Status(progress) => { CheckTask::Status(progress) => {
let params = req::ProgressParams { let params = lsp_types::ProgressParams {
token: req::ProgressToken::String("rustAnalyzer/cargoWatcher".to_string()), token: lsp_types::ProgressToken::String("rustAnalyzer/cargoWatcher".to_string()),
value: req::ProgressParamsValue::WorkDone(progress), value: lsp_types::ProgressParamsValue::WorkDone(progress),
}; };
let not = notification_new::<req::Progress>(params); let not = notification_new::<lsp_types::notification::Progress>(params);
task_sender.send(Task::Notify(not)).unwrap(); task_sender.send(Task::Notify(not)).unwrap();
} }
}; };
@@ -768,8 +776,8 @@ fn on_diagnostic_task(task: DiagnosticTask, msg_sender: &Sender<Message>, state:
}; };
let diagnostics = state.diagnostics.diagnostics_for(file_id).cloned().collect(); let diagnostics = state.diagnostics.diagnostics_for(file_id).cloned().collect();
let params = req::PublishDiagnosticsParams { uri, diagnostics, version: None }; let params = lsp_types::PublishDiagnosticsParams { uri, diagnostics, version: None };
let not = notification_new::<req::PublishDiagnostics>(params); let not = notification_new::<lsp_types::notification::PublishDiagnostics>(params);
msg_sender.send(not.into()).unwrap(); msg_sender.send(not.into()).unwrap();
} }
} }
@@ -782,10 +790,10 @@ fn send_startup_progress(sender: &Sender<Message>, loop_state: &mut LoopState) {
match (prev, loop_state.workspace_loaded) { match (prev, loop_state.workspace_loaded) {
(None, false) => { (None, false) => {
let work_done_progress_create = request_new::<req::WorkDoneProgressCreate>( let work_done_progress_create = request_new::<lsp_types::request::WorkDoneProgressCreate>(
loop_state.next_request_id(), loop_state.next_request_id(),
WorkDoneProgressCreateParams { WorkDoneProgressCreateParams {
token: req::ProgressToken::String("rustAnalyzer/startup".into()), token: lsp_types::ProgressToken::String("rustAnalyzer/startup".into()),
}, },
); );
sender.send(work_done_progress_create.into()).unwrap(); sender.send(work_done_progress_create.into()).unwrap();
@@ -817,9 +825,10 @@ fn send_startup_progress(sender: &Sender<Message>, loop_state: &mut LoopState) {
} }
fn send_startup_progress_notif(sender: &Sender<Message>, work_done_progress: WorkDoneProgress) { fn send_startup_progress_notif(sender: &Sender<Message>, work_done_progress: WorkDoneProgress) {
let notif = notification_new::<req::Progress>(req::ProgressParams { let notif =
token: req::ProgressToken::String("rustAnalyzer/startup".into()), notification_new::<lsp_types::notification::Progress>(lsp_types::ProgressParams {
value: req::ProgressParamsValue::WorkDone(work_done_progress), token: lsp_types::ProgressToken::String("rustAnalyzer/startup".into()),
value: lsp_types::ProgressParamsValue::WorkDone(work_done_progress),
}); });
sender.send(notif.into()).unwrap(); sender.send(notif.into()).unwrap();
} }
@@ -842,7 +851,7 @@ impl<'a> PoolDispatcher<'a> {
f: fn(&mut WorldState, R::Params) -> Result<R::Result>, f: fn(&mut WorldState, R::Params) -> Result<R::Result>,
) -> Result<&mut Self> ) -> Result<&mut Self>
where where
R: req::Request + 'static, R: lsp_types::request::Request + 'static,
R::Params: DeserializeOwned + panic::UnwindSafe + 'static, R::Params: DeserializeOwned + panic::UnwindSafe + 'static,
R::Result: Serialize + 'static, R::Result: Serialize + 'static,
{ {
@@ -865,7 +874,7 @@ impl<'a> PoolDispatcher<'a> {
/// Dispatches the request onto thread pool /// Dispatches the request onto thread pool
fn on<R>(&mut self, f: fn(WorldSnapshot, R::Params) -> Result<R::Result>) -> Result<&mut Self> fn on<R>(&mut self, f: fn(WorldSnapshot, R::Params) -> Result<R::Result>) -> Result<&mut Self>
where where
R: req::Request + 'static, R: lsp_types::request::Request + 'static,
R::Params: DeserializeOwned + Send + 'static, R::Params: DeserializeOwned + Send + 'static,
R::Result: Serialize + 'static, R::Result: Serialize + 'static,
{ {
@@ -891,7 +900,7 @@ impl<'a> PoolDispatcher<'a> {
fn parse<R>(&mut self) -> Option<(RequestId, R::Params)> fn parse<R>(&mut self) -> Option<(RequestId, R::Params)>
where where
R: req::Request + 'static, R: lsp_types::request::Request + 'static,
R::Params: DeserializeOwned + 'static, R::Params: DeserializeOwned + 'static,
{ {
let req = self.req.take()?; let req = self.req.take()?;
@@ -928,7 +937,7 @@ impl<'a> PoolDispatcher<'a> {
fn result_to_task<R>(id: RequestId, result: Result<R::Result>) -> Task fn result_to_task<R>(id: RequestId, result: Result<R::Result>) -> Task
where where
R: req::Request + 'static, R: lsp_types::request::Request + 'static,
R::Params: DeserializeOwned + 'static, R::Params: DeserializeOwned + 'static,
R::Result: Serialize + 'static, R::Result: Serialize + 'static,
{ {
@@ -984,10 +993,14 @@ fn update_file_notifications_on_threadpool(
} }
} }
pub fn show_message(typ: req::MessageType, message: impl Into<String>, sender: &Sender<Message>) { pub fn show_message(
typ: lsp_types::MessageType,
message: impl Into<String>,
sender: &Sender<Message>,
) {
let message = message.into(); let message = message.into();
let params = req::ShowMessageParams { typ, message }; let params = lsp_types::ShowMessageParams { typ, message };
let not = notification_new::<req::ShowMessage>(params); let not = notification_new::<lsp_types::notification::ShowMessage>(params);
sender.send(not.into()).unwrap(); sender.send(not.into()).unwrap();
} }

View File

@@ -81,12 +81,12 @@ pub fn handle_expand_macro(
pub fn handle_selection_range( pub fn handle_selection_range(
world: WorldSnapshot, world: WorldSnapshot,
params: req::SelectionRangeParams, params: lsp_types::SelectionRangeParams,
) -> Result<Option<Vec<req::SelectionRange>>> { ) -> Result<Option<Vec<lsp_types::SelectionRange>>> {
let _p = profile("handle_selection_range"); let _p = profile("handle_selection_range");
let file_id = from_proto::file_id(&world, &params.text_document.uri)?; let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
let line_index = world.analysis().file_line_index(file_id)?; let line_index = world.analysis().file_line_index(file_id)?;
let res: Result<Vec<req::SelectionRange>> = params let res: Result<Vec<lsp_types::SelectionRange>> = params
.positions .positions
.into_iter() .into_iter()
.map(|position| { .map(|position| {
@@ -105,12 +105,12 @@ pub fn handle_selection_range(
} }
} }
} }
let mut range = req::SelectionRange { let mut range = lsp_types::SelectionRange {
range: to_proto::range(&line_index, *ranges.last().unwrap()), range: to_proto::range(&line_index, *ranges.last().unwrap()),
parent: None, parent: None,
}; };
for &r in ranges.iter().rev().skip(1) { for &r in ranges.iter().rev().skip(1) {
range = req::SelectionRange { range = lsp_types::SelectionRange {
range: to_proto::range(&line_index, r), range: to_proto::range(&line_index, r),
parent: Some(Box::new(range)), parent: Some(Box::new(range)),
} }
@@ -156,7 +156,7 @@ pub fn handle_join_lines(
pub fn handle_on_enter( pub fn handle_on_enter(
world: WorldSnapshot, world: WorldSnapshot,
params: req::TextDocumentPositionParams, params: lsp_types::TextDocumentPositionParams,
) -> Result<Option<req::SourceChange>> { ) -> Result<Option<req::SourceChange>> {
let _p = profile("handle_on_enter"); let _p = profile("handle_on_enter");
let position = from_proto::file_position(&world, params)?; let position = from_proto::file_position(&world, params)?;
@@ -169,7 +169,7 @@ pub fn handle_on_enter(
// Don't forget to add new trigger characters to `ServerCapabilities` in `caps.rs`. // Don't forget to add new trigger characters to `ServerCapabilities` in `caps.rs`.
pub fn handle_on_type_formatting( pub fn handle_on_type_formatting(
world: WorldSnapshot, world: WorldSnapshot,
params: req::DocumentOnTypeFormattingParams, params: lsp_types::DocumentOnTypeFormattingParams,
) -> Result<Option<Vec<TextEdit>>> { ) -> Result<Option<Vec<TextEdit>>> {
let _p = profile("handle_on_type_formatting"); let _p = profile("handle_on_type_formatting");
let mut position = from_proto::file_position(&world, params.text_document_position)?; let mut position = from_proto::file_position(&world, params.text_document_position)?;
@@ -208,8 +208,8 @@ pub fn handle_on_type_formatting(
pub fn handle_document_symbol( pub fn handle_document_symbol(
world: WorldSnapshot, world: WorldSnapshot,
params: req::DocumentSymbolParams, params: lsp_types::DocumentSymbolParams,
) -> Result<Option<req::DocumentSymbolResponse>> { ) -> Result<Option<lsp_types::DocumentSymbolResponse>> {
let _p = profile("handle_document_symbol"); let _p = profile("handle_document_symbol");
let file_id = from_proto::file_id(&world, &params.text_document.uri)?; let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
let line_index = world.analysis().file_line_index(file_id)?; let line_index = world.analysis().file_line_index(file_id)?;
@@ -276,7 +276,7 @@ pub fn handle_document_symbol(
pub fn handle_workspace_symbol( pub fn handle_workspace_symbol(
world: WorldSnapshot, world: WorldSnapshot,
params: req::WorkspaceSymbolParams, params: lsp_types::WorkspaceSymbolParams,
) -> Result<Option<Vec<SymbolInformation>>> { ) -> Result<Option<Vec<SymbolInformation>>> {
let _p = profile("handle_workspace_symbol"); let _p = profile("handle_workspace_symbol");
let all_symbols = params.query.contains('#'); let all_symbols = params.query.contains('#');
@@ -320,8 +320,8 @@ pub fn handle_workspace_symbol(
pub fn handle_goto_definition( pub fn handle_goto_definition(
world: WorldSnapshot, world: WorldSnapshot,
params: req::GotoDefinitionParams, params: lsp_types::GotoDefinitionParams,
) -> Result<Option<req::GotoDefinitionResponse>> { ) -> Result<Option<lsp_types::GotoDefinitionResponse>> {
let _p = profile("handle_goto_definition"); let _p = profile("handle_goto_definition");
let position = from_proto::file_position(&world, params.text_document_position_params)?; let position = from_proto::file_position(&world, params.text_document_position_params)?;
let nav_info = match world.analysis().goto_definition(position)? { let nav_info = match world.analysis().goto_definition(position)? {
@@ -338,8 +338,8 @@ pub fn handle_goto_definition(
pub fn handle_goto_implementation( pub fn handle_goto_implementation(
world: WorldSnapshot, world: WorldSnapshot,
params: req::GotoImplementationParams, params: lsp_types::request::GotoImplementationParams,
) -> Result<Option<req::GotoImplementationResponse>> { ) -> Result<Option<lsp_types::request::GotoImplementationResponse>> {
let _p = profile("handle_goto_implementation"); let _p = profile("handle_goto_implementation");
let position = from_proto::file_position(&world, params.text_document_position_params)?; let position = from_proto::file_position(&world, params.text_document_position_params)?;
let nav_info = match world.analysis().goto_implementation(position)? { let nav_info = match world.analysis().goto_implementation(position)? {
@@ -356,8 +356,8 @@ pub fn handle_goto_implementation(
pub fn handle_goto_type_definition( pub fn handle_goto_type_definition(
world: WorldSnapshot, world: WorldSnapshot,
params: req::GotoTypeDefinitionParams, params: lsp_types::request::GotoTypeDefinitionParams,
) -> Result<Option<req::GotoTypeDefinitionResponse>> { ) -> Result<Option<lsp_types::request::GotoTypeDefinitionResponse>> {
let _p = profile("handle_goto_type_definition"); let _p = profile("handle_goto_type_definition");
let position = from_proto::file_position(&world, params.text_document_position_params)?; let position = from_proto::file_position(&world, params.text_document_position_params)?;
let nav_info = match world.analysis().goto_type_definition(position)? { let nav_info = match world.analysis().goto_type_definition(position)? {
@@ -374,7 +374,7 @@ pub fn handle_goto_type_definition(
pub fn handle_parent_module( pub fn handle_parent_module(
world: WorldSnapshot, world: WorldSnapshot,
params: req::TextDocumentPositionParams, params: lsp_types::TextDocumentPositionParams,
) -> Result<Vec<Location>> { ) -> Result<Vec<Location>> {
let _p = profile("handle_parent_module"); let _p = profile("handle_parent_module");
let position = from_proto::file_position(&world, params)?; let position = from_proto::file_position(&world, params)?;
@@ -447,8 +447,8 @@ pub fn handle_runnables(
pub fn handle_completion( pub fn handle_completion(
world: WorldSnapshot, world: WorldSnapshot,
params: req::CompletionParams, params: lsp_types::CompletionParams,
) -> Result<Option<req::CompletionResponse>> { ) -> Result<Option<lsp_types::CompletionResponse>> {
let _p = profile("handle_completion"); let _p = profile("handle_completion");
let position = from_proto::file_position(&world, params.text_document_position)?; let position = from_proto::file_position(&world, params.text_document_position)?;
let completion_triggered_after_single_colon = { let completion_triggered_after_single_colon = {
@@ -506,8 +506,8 @@ pub fn handle_folding_range(
pub fn handle_signature_help( pub fn handle_signature_help(
world: WorldSnapshot, world: WorldSnapshot,
params: req::SignatureHelpParams, params: lsp_types::SignatureHelpParams,
) -> Result<Option<req::SignatureHelp>> { ) -> Result<Option<lsp_types::SignatureHelp>> {
let _p = profile("handle_signature_help"); let _p = profile("handle_signature_help");
let position = from_proto::file_position(&world, params.text_document_position_params)?; let position = from_proto::file_position(&world, params.text_document_position_params)?;
let call_info = match world.analysis().call_info(position)? { let call_info = match world.analysis().call_info(position)? {
@@ -521,14 +521,14 @@ pub fn handle_signature_help(
} }
let sig_info = to_proto::signature_information(call_info.signature, concise); let sig_info = to_proto::signature_information(call_info.signature, concise);
Ok(Some(req::SignatureHelp { Ok(Some(lsp_types::SignatureHelp {
signatures: vec![sig_info], signatures: vec![sig_info],
active_signature: Some(0), active_signature: Some(0),
active_parameter, active_parameter,
})) }))
} }
pub fn handle_hover(world: WorldSnapshot, params: req::HoverParams) -> Result<Option<Hover>> { pub fn handle_hover(world: WorldSnapshot, params: lsp_types::HoverParams) -> Result<Option<Hover>> {
let _p = profile("handle_hover"); let _p = profile("handle_hover");
let position = from_proto::file_position(&world, params.text_document_position_params)?; let position = from_proto::file_position(&world, params.text_document_position_params)?;
let info = match world.analysis().hover(position)? { let info = match world.analysis().hover(position)? {
@@ -549,7 +549,7 @@ pub fn handle_hover(world: WorldSnapshot, params: req::HoverParams) -> Result<Op
pub fn handle_prepare_rename( pub fn handle_prepare_rename(
world: WorldSnapshot, world: WorldSnapshot,
params: req::TextDocumentPositionParams, params: lsp_types::TextDocumentPositionParams,
) -> Result<Option<PrepareRenameResponse>> { ) -> Result<Option<PrepareRenameResponse>> {
let _p = profile("handle_prepare_rename"); let _p = profile("handle_prepare_rename");
let position = from_proto::file_position(&world, params)?; let position = from_proto::file_position(&world, params)?;
@@ -589,7 +589,7 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Optio
pub fn handle_references( pub fn handle_references(
world: WorldSnapshot, world: WorldSnapshot,
params: req::ReferenceParams, params: lsp_types::ReferenceParams,
) -> Result<Option<Vec<Location>>> { ) -> Result<Option<Vec<Location>>> {
let _p = profile("handle_references"); let _p = profile("handle_references");
let position = from_proto::file_position(&world, params.text_document_position)?; let position = from_proto::file_position(&world, params.text_document_position)?;
@@ -692,7 +692,7 @@ pub fn handle_formatting(
pub fn handle_code_action( pub fn handle_code_action(
world: WorldSnapshot, world: WorldSnapshot,
params: req::CodeActionParams, params: lsp_types::CodeActionParams,
) -> Result<Option<CodeActionResponse>> { ) -> Result<Option<CodeActionResponse>> {
let _p = profile("handle_code_action"); let _p = profile("handle_code_action");
let file_id = from_proto::file_id(&world, &params.text_document.uri)?; let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
@@ -806,7 +806,7 @@ pub fn handle_code_action(
pub fn handle_code_lens( pub fn handle_code_lens(
world: WorldSnapshot, world: WorldSnapshot,
params: req::CodeLensParams, params: lsp_types::CodeLensParams,
) -> Result<Option<Vec<CodeLens>>> { ) -> Result<Option<Vec<CodeLens>>> {
let _p = profile("handle_code_lens"); let _p = profile("handle_code_lens");
let file_id = from_proto::file_id(&world, &params.text_document.uri)?; let file_id = from_proto::file_id(&world, &params.text_document.uri)?;
@@ -875,8 +875,8 @@ pub fn handle_code_lens(
.map(|it| { .map(|it| {
let range = to_proto::range(&line_index, it.node_range); let range = to_proto::range(&line_index, it.node_range);
let pos = range.start; let pos = range.start;
let lens_params = req::GotoImplementationParams { let lens_params = lsp_types::request::GotoImplementationParams {
text_document_position_params: req::TextDocumentPositionParams::new( text_document_position_params: lsp_types::TextDocumentPositionParams::new(
params.text_document.clone(), params.text_document.clone(),
pos, pos,
), ),
@@ -897,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::GotoImplementationParams), Impls(lsp_types::request::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> {
@@ -908,9 +908,9 @@ pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Re
Some(CodeLensResolveData::Impls(lens_params)) => { Some(CodeLensResolveData::Impls(lens_params)) => {
let locations: Vec<Location> = let locations: Vec<Location> =
match handle_goto_implementation(world, lens_params.clone())? { match handle_goto_implementation(world, lens_params.clone())? {
Some(req::GotoDefinitionResponse::Scalar(loc)) => vec![loc], Some(lsp_types::GotoDefinitionResponse::Scalar(loc)) => vec![loc],
Some(req::GotoDefinitionResponse::Array(locs)) => locs, Some(lsp_types::GotoDefinitionResponse::Array(locs)) => locs,
Some(req::GotoDefinitionResponse::Link(links)) => links Some(lsp_types::GotoDefinitionResponse::Link(links)) => links
.into_iter() .into_iter()
.map(|link| Location::new(link.target_uri, link.target_selection_range)) .map(|link| Location::new(link.target_uri, link.target_selection_range))
.collect(), .collect(),
@@ -947,7 +947,7 @@ 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::DocumentHighlightParams, params: lsp_types::DocumentHighlightParams,
) -> Result<Option<Vec<DocumentHighlight>>> { ) -> Result<Option<Vec<DocumentHighlight>>> {
let _p = profile("handle_document_highlight"); let _p = profile("handle_document_highlight");
let position = from_proto::file_position(&world, params.text_document_position_params)?; let position = from_proto::file_position(&world, params.text_document_position_params)?;

View File

@@ -1,23 +1,10 @@
//! Defines `rust-analyzer` specific custom messages. //! Defines `rust-analyzer` specific custom messages.
use lsp_types::request::Request;
use lsp_types::{Location, Position, Range, TextDocumentIdentifier}; use lsp_types::{Location, Position, Range, TextDocumentIdentifier};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub use lsp_types::{
notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
CodeLensParams, CompletionParams, CompletionResponse, ConfigurationItem, ConfigurationParams,
DiagnosticTag, DidChangeConfigurationParams, DidChangeWatchedFilesParams,
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, SignatureHelpParams, SymbolKind, TextDocumentEdit, TextDocumentPositionParams,
TextEdit, WorkDoneProgressParams, WorkspaceEdit, WorkspaceSymbolParams,
};
use std::path::PathBuf; use std::path::PathBuf;
pub enum AnalyzerStatus {} pub enum AnalyzerStatus {}
@@ -91,7 +78,7 @@ pub struct FindMatchingBraceParams {
pub enum ParentModule {} pub enum ParentModule {}
impl Request for ParentModule { impl Request for ParentModule {
type Params = TextDocumentPositionParams; type Params = lsp_types::TextDocumentPositionParams;
type Result = Vec<Location>; type Result = Vec<Location>;
const METHOD: &'static str = "rust-analyzer/parentModule"; const METHOD: &'static str = "rust-analyzer/parentModule";
} }
@@ -114,7 +101,7 @@ pub struct JoinLinesParams {
pub enum OnEnter {} pub enum OnEnter {}
impl Request for OnEnter { impl Request for OnEnter {
type Params = TextDocumentPositionParams; type Params = lsp_types::TextDocumentPositionParams;
type Result = Option<SourceChange>; type Result = Option<SourceChange>;
const METHOD: &'static str = "rust-analyzer/onEnter"; const METHOD: &'static str = "rust-analyzer/onEnter";
} }
@@ -150,8 +137,8 @@ pub struct Runnable {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct SourceChange { pub struct SourceChange {
pub label: String, pub label: String,
pub workspace_edit: WorkspaceEdit, pub workspace_edit: lsp_types::WorkspaceEdit,
pub cursor_position: Option<TextDocumentPositionParams>, pub cursor_position: Option<lsp_types::TextDocumentPositionParams>,
} }
pub enum InlayHints {} pub enum InlayHints {}