2120: Profile all request handlers r=matklad a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
This commit is contained in:
bors[bot] 2019-10-29 20:11:33 +00:00 committed by GitHub
commit 3bd3f50578
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,6 +27,7 @@ use crate::{
}; };
pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> { pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> {
let _p = profile("handle_analyzer_status");
let mut buf = world.status(); let mut buf = world.status();
writeln!(buf, "\n\nrequests:").unwrap(); writeln!(buf, "\n\nrequests:").unwrap();
let requests = world.latest_requests.read(); let requests = world.latest_requests.read();
@ -38,6 +39,7 @@ pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> {
} }
pub fn handle_syntax_tree(world: WorldSnapshot, params: req::SyntaxTreeParams) -> Result<String> { pub fn handle_syntax_tree(world: WorldSnapshot, params: req::SyntaxTreeParams) -> Result<String> {
let _p = profile("handle_syntax_tree");
let id = params.text_document.try_conv_with(&world)?; let id = params.text_document.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(id)?; let line_index = world.analysis().file_line_index(id)?;
let text_range = params.range.map(|p| p.conv_with(&line_index)); let text_range = params.range.map(|p| p.conv_with(&line_index));
@ -172,6 +174,7 @@ pub fn handle_document_symbol(
world: WorldSnapshot, world: WorldSnapshot,
params: req::DocumentSymbolParams, params: req::DocumentSymbolParams,
) -> Result<Option<req::DocumentSymbolResponse>> { ) -> Result<Option<req::DocumentSymbolResponse>> {
let _p = profile("handle_document_symbol");
let file_id = params.text_document.try_conv_with(&world)?; let file_id = 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)?;
@ -210,6 +213,7 @@ pub fn handle_workspace_symbol(
world: WorldSnapshot, world: WorldSnapshot,
params: req::WorkspaceSymbolParams, params: req::WorkspaceSymbolParams,
) -> Result<Option<Vec<SymbolInformation>>> { ) -> Result<Option<Vec<SymbolInformation>>> {
let _p = profile("handle_workspace_symbol");
let all_symbols = params.query.contains('#'); let all_symbols = params.query.contains('#');
let libs = params.query.contains('*'); let libs = params.query.contains('*');
let query = { let query = {
@ -253,6 +257,7 @@ pub fn handle_goto_definition(
world: WorldSnapshot, world: WorldSnapshot,
params: req::TextDocumentPositionParams, params: req::TextDocumentPositionParams,
) -> Result<Option<req::GotoDefinitionResponse>> { ) -> Result<Option<req::GotoDefinitionResponse>> {
let _p = profile("handle_goto_definition");
let position = params.try_conv_with(&world)?; let 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),
@ -266,6 +271,7 @@ pub fn handle_goto_implementation(
world: WorldSnapshot, world: WorldSnapshot,
params: req::TextDocumentPositionParams, params: req::TextDocumentPositionParams,
) -> Result<Option<req::GotoImplementationResponse>> { ) -> Result<Option<req::GotoImplementationResponse>> {
let _p = profile("handle_goto_implementation");
let position = params.try_conv_with(&world)?; let 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),
@ -279,6 +285,7 @@ pub fn handle_goto_type_definition(
world: WorldSnapshot, world: WorldSnapshot,
params: req::TextDocumentPositionParams, params: req::TextDocumentPositionParams,
) -> Result<Option<req::GotoTypeDefinitionResponse>> { ) -> Result<Option<req::GotoTypeDefinitionResponse>> {
let _p = profile("handle_goto_type_definition");
let position = params.try_conv_with(&world)?; let 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),
@ -292,6 +299,7 @@ pub fn handle_parent_module(
world: WorldSnapshot, world: WorldSnapshot,
params: req::TextDocumentPositionParams, params: req::TextDocumentPositionParams,
) -> Result<Vec<Location>> { ) -> Result<Vec<Location>> {
let _p = profile("handle_parent_module");
let position = params.try_conv_with(&world)?; let position = params.try_conv_with(&world)?;
world.analysis().parent_module(position)?.iter().try_conv_with_to_vec(&world) world.analysis().parent_module(position)?.iter().try_conv_with_to_vec(&world)
} }
@ -300,6 +308,7 @@ pub fn handle_runnables(
world: WorldSnapshot, world: WorldSnapshot,
params: req::RunnablesParams, params: req::RunnablesParams,
) -> Result<Vec<req::Runnable>> { ) -> Result<Vec<req::Runnable>> {
let _p = profile("handle_runnables");
let file_id = params.text_document.try_conv_with(&world)?; let file_id = 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 offset = params.position.map(|it| it.conv_with(&line_index)); let offset = params.position.map(|it| it.conv_with(&line_index));
@ -341,6 +350,7 @@ pub fn handle_decorations(
world: WorldSnapshot, world: WorldSnapshot,
params: TextDocumentIdentifier, params: TextDocumentIdentifier,
) -> Result<Vec<Decoration>> { ) -> Result<Vec<Decoration>> {
let _p = profile("handle_decorations");
let file_id = params.try_conv_with(&world)?; let file_id = params.try_conv_with(&world)?;
highlight(&world, file_id) highlight(&world, file_id)
} }
@ -389,6 +399,7 @@ pub fn handle_folding_range(
world: WorldSnapshot, world: WorldSnapshot,
params: FoldingRangeParams, params: FoldingRangeParams,
) -> Result<Option<Vec<FoldingRange>>> { ) -> Result<Option<Vec<FoldingRange>>> {
let _p = profile("handle_folding_range");
let file_id = params.text_document.try_conv_with(&world)?; let file_id = params.text_document.try_conv_with(&world)?;
let folds = world.analysis().folding_ranges(file_id)?; let folds = world.analysis().folding_ranges(file_id)?;
let text = world.analysis().file_text(file_id)?; let text = world.analysis().file_text(file_id)?;
@ -406,6 +417,7 @@ pub fn handle_signature_help(
world: WorldSnapshot, world: WorldSnapshot,
params: req::TextDocumentPositionParams, params: req::TextDocumentPositionParams,
) -> Result<Option<req::SignatureHelp>> { ) -> Result<Option<req::SignatureHelp>> {
let _p = profile("handle_signature_help");
let position = params.try_conv_with(&world)?; let 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 active_parameter = call_info.active_parameter.map(|it| it as i64); let active_parameter = call_info.active_parameter.map(|it| it as i64);
@ -425,6 +437,7 @@ pub fn handle_hover(
world: WorldSnapshot, world: WorldSnapshot,
params: req::TextDocumentPositionParams, params: req::TextDocumentPositionParams,
) -> Result<Option<Hover>> { ) -> Result<Option<Hover>> {
let _p = profile("handle_hover");
let position = params.try_conv_with(&world)?; let 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),
@ -523,6 +536,7 @@ pub fn handle_formatting(
world: WorldSnapshot, world: WorldSnapshot,
params: DocumentFormattingParams, params: DocumentFormattingParams,
) -> Result<Option<Vec<TextEdit>>> { ) -> Result<Option<Vec<TextEdit>>> {
let _p = profile("handle_formatting");
let file_id = params.text_document.try_conv_with(&world)?; let file_id = params.text_document.try_conv_with(&world)?;
let file = world.analysis().file_text(file_id)?; let file = world.analysis().file_text(file_id)?;
@ -645,6 +659,7 @@ pub fn handle_code_lens(
world: WorldSnapshot, world: WorldSnapshot,
params: req::CodeLensParams, params: req::CodeLensParams,
) -> Result<Option<Vec<CodeLens>>> { ) -> Result<Option<Vec<CodeLens>>> {
let _p = profile("handle_code_lens");
let file_id = params.text_document.try_conv_with(&world)?; let file_id = 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)?;
@ -705,6 +720,7 @@ enum CodeLensResolveData {
} }
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> {
let _p = profile("handle_code_lens_resolve");
let data = code_lens.data.unwrap(); let data = code_lens.data.unwrap();
let resolve = serde_json::from_value(data)?; let resolve = serde_json::from_value(data)?;
match resolve { match resolve {
@ -776,6 +792,7 @@ pub fn publish_diagnostics(
world: &WorldSnapshot, world: &WorldSnapshot,
file_id: FileId, file_id: FileId,
) -> Result<req::PublishDiagnosticsParams> { ) -> Result<req::PublishDiagnosticsParams> {
let _p = profile("publish_diagnostics");
let uri = world.file_id_to_uri(file_id)?; let uri = world.file_id_to_uri(file_id)?;
let line_index = world.analysis().file_line_index(file_id)?; let line_index = world.analysis().file_line_index(file_id)?;
let diagnostics = world let diagnostics = world
@ -798,6 +815,7 @@ pub fn publish_decorations(
world: &WorldSnapshot, world: &WorldSnapshot,
file_id: FileId, file_id: FileId,
) -> Result<req::PublishDecorationsParams> { ) -> Result<req::PublishDecorationsParams> {
let _p = profile("publish_decorations");
let uri = world.file_id_to_uri(file_id)?; let uri = world.file_id_to_uri(file_id)?;
Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? }) Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? })
} }
@ -847,6 +865,7 @@ pub fn handle_inlay_hints(
world: WorldSnapshot, world: WorldSnapshot,
params: InlayHintsParams, params: InlayHintsParams,
) -> Result<Vec<InlayHint>> { ) -> Result<Vec<InlayHint>> {
let _p = profile("handle_inlay_hints");
let file_id = params.text_document.try_conv_with(&world)?; let file_id = params.text_document.try_conv_with(&world)?;
let analysis = world.analysis(); let analysis = world.analysis();
let line_index = analysis.file_line_index(file_id)?; let line_index = analysis.file_line_index(file_id)?;