From d4e381f7b24179c9c4fc90e64250f9df82627397 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 31 Jul 2021 15:46:03 +0300 Subject: [PATCH 1/3] minor: follow code style --- crates/ide_completion/src/render/function.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs index 87714def967..a77dc6dd3d9 100644 --- a/crates/ide_completion/src/render/function.rs +++ b/crates/ide_completion/src/render/function.rs @@ -3,7 +3,7 @@ use hir::{AsAssocItem, HasSource, HirDisplay}; use ide_db::SymbolKind; use itertools::Itertools; -use syntax::ast::Fn; +use syntax::ast; use crate::{ item::{CompletionItem, CompletionItemKind, CompletionKind, CompletionRelevance, ImportEdit}, @@ -40,7 +40,7 @@ struct FunctionRender<'a> { name: String, receiver: Option, func: hir::Function, - ast_node: Fn, + ast_node: ast::Fn, is_method: bool, } From 08756012a5a03a2e5a474768ff1472a4fd2b9a52 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 31 Jul 2021 16:13:15 +0300 Subject: [PATCH 2/3] internal: document query implication of completion rendering --- crates/ide_completion/src/render/function.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs index a77dc6dd3d9..95244a758de 100644 --- a/crates/ide_completion/src/render/function.rs +++ b/crates/ide_completion/src/render/function.rs @@ -40,6 +40,20 @@ struct FunctionRender<'a> { name: String, receiver: Option, func: hir::Function, + /// NB: having `ast::Fn` here might or might not be a good idea. The problem + /// with it is that, to get an `ast::`, you want to parse the corresponding + /// source file. So, when flyimport completions suggest a bunch of + /// functions, we spend quite some time parsing many files. + /// + /// We need ast because we want to access parameter names (patterns). We can + /// add them to the hir of the function itself, but parameter names are not + /// something hir cares otherwise. + /// + /// Alternatively we can reconstruct params from the function body, but that + /// would require parsing anyway. + /// + /// It seems that just using `ast` is the best choice -- most of parses + /// should be cached anyway. ast_node: ast::Fn, is_method: bool, } From a5049e13bf35f70da329a64d8ea4435665f5caba Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 31 Jul 2021 16:22:03 +0300 Subject: [PATCH 3/3] internal: make non-zero times stand out in profile --- crates/profile/src/hprof.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/crates/profile/src/hprof.rs b/crates/profile/src/hprof.rs index 5fdb3720610..3ce11fd86c8 100644 --- a/crates/profile/src/hprof.rs +++ b/crates/profile/src/hprof.rs @@ -2,7 +2,7 @@ use std::{ cell::RefCell, collections::{BTreeMap, HashSet}, - env, + env, fmt, io::{stderr, Write}, sync::{ atomic::{AtomicBool, Ordering}, @@ -278,9 +278,9 @@ fn print( let detail = tree[curr].detail.as_ref().map(|it| format!(" @ {}", it)).unwrap_or_default(); writeln!( out, - "{}{:5}ms - {}{}", + "{}{} - {}{}", current_indent, - tree[curr].duration.as_millis(), + ms(tree[curr].duration), tree[curr].label, detail, ) @@ -302,14 +302,25 @@ fn print( } for (child_msg, (duration, count)) in short_children.iter() { - let millis = duration.as_millis(); - writeln!(out, " {}{:5}ms - {} ({} calls)", current_indent, millis, child_msg, count) + writeln!(out, " {}{} - {} ({} calls)", current_indent, ms(*duration), child_msg, count) .expect("printing profiling info"); } let unaccounted = tree[curr].duration - accounted_for; if tree.children(curr).next().is_some() && unaccounted > longer_than { - writeln!(out, " {}{:5}ms - ???", current_indent, unaccounted.as_millis()) + writeln!(out, " {}{} - ???", current_indent, ms(unaccounted)) .expect("printing profiling info"); } } + +#[allow(non_camel_case_types)] +struct ms(Duration); + +impl fmt::Display for ms { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.0.as_millis() { + 0 => f.write_str(" 0 "), + n => write!(f, "{:5}ms", n), + } + } +}