mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Profile completions better
This commit is contained in:
parent
c66d477f5a
commit
b2e6ca46ca
9 changed files with 22 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1658,6 +1658,7 @@ dependencies = [
|
|||
"itertools",
|
||||
"once_cell",
|
||||
"parser",
|
||||
"profile",
|
||||
"rayon",
|
||||
"rowan",
|
||||
"rustc-ap-rustc_lexer",
|
||||
|
|
|
@ -25,6 +25,7 @@ use crate::{
|
|||
pub use insert_use::{insert_use, ImportScope, MergeBehaviour};
|
||||
|
||||
pub fn mod_path_to_ast(path: &hir::ModPath) -> ast::Path {
|
||||
let _p = profile::span("mod_path_to_ast");
|
||||
let mut segments = Vec::new();
|
||||
let mut is_abs = false;
|
||||
match path.kind {
|
||||
|
|
|
@ -95,6 +95,7 @@ pub fn insert_use<'a>(
|
|||
path: ast::Path,
|
||||
merge: Option<MergeBehaviour>,
|
||||
) -> SyntaxRewriter<'a> {
|
||||
let _p = profile::span("mod_path_to_ast");
|
||||
let mut rewriter = SyntaxRewriter::default();
|
||||
let use_item = make::use_(make::use_tree(path.clone(), None, None, false));
|
||||
// merge into existing imports if possible
|
||||
|
|
|
@ -278,6 +278,8 @@ pub(crate) struct Builder {
|
|||
|
||||
impl Builder {
|
||||
pub(crate) fn build(self) -> CompletionItem {
|
||||
let _p = profile::span("item::Builder::build");
|
||||
|
||||
let mut label = self.label;
|
||||
let mut lookup = self.lookup;
|
||||
let mut insert_text = self.insert_text;
|
||||
|
|
|
@ -17,6 +17,7 @@ pub(crate) fn render_enum_variant<'a>(
|
|||
variant: hir::EnumVariant,
|
||||
path: Option<ModPath>,
|
||||
) -> CompletionItem {
|
||||
let _p = profile::span("render_enum_variant");
|
||||
EnumVariantRender::new(ctx, local_name, variant, path).render(import_data)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ pub(crate) fn render_fn<'a>(
|
|||
local_name: Option<String>,
|
||||
fn_: hir::Function,
|
||||
) -> CompletionItem {
|
||||
let _p = profile::span("render_fn");
|
||||
FunctionRender::new(ctx, local_name, fn_).render(import_data)
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ pub(crate) fn render_macro<'a>(
|
|||
name: String,
|
||||
macro_: hir::MacroDef,
|
||||
) -> Option<CompletionItem> {
|
||||
let _p = profile::span("render_macro");
|
||||
MacroRender::new(ctx, name, macro_).render(import_data)
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ stdx = { path = "../stdx", version = "0.0.0" }
|
|||
text_edit = { path = "../text_edit", version = "0.0.0" }
|
||||
parser = { path = "../parser", version = "0.0.0" }
|
||||
test_utils = { path = "../test_utils", version = "0.0.0" }
|
||||
profile = { path = "../profile", version = "0.0.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
walkdir = "2.3.1"
|
||||
|
|
|
@ -127,6 +127,8 @@ pub struct TreeDiff {
|
|||
|
||||
impl TreeDiff {
|
||||
pub fn into_text_edit(&self, builder: &mut TextEditBuilder) {
|
||||
let _p = profile::span("into_text_edit");
|
||||
|
||||
for (anchor, to) in self.insertions.iter() {
|
||||
let offset = match anchor {
|
||||
TreeDiffInsertPos::After(it) => it.text_range().end(),
|
||||
|
@ -154,6 +156,8 @@ impl TreeDiff {
|
|||
///
|
||||
/// This function tries to find a fine-grained diff.
|
||||
pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
|
||||
let _p = profile::span("diff");
|
||||
|
||||
let mut diff = TreeDiff {
|
||||
replacements: FxHashMap::default(),
|
||||
insertions: FxIndexMap::default(),
|
||||
|
@ -467,6 +471,8 @@ impl<'a> SyntaxRewriter<'a> {
|
|||
}
|
||||
|
||||
pub fn rewrite(&self, node: &SyntaxNode) -> SyntaxNode {
|
||||
let _p = profile::span("rewrite");
|
||||
|
||||
if self.f.is_none() && self.replacements.is_empty() && self.insertions.is_empty() {
|
||||
return node.clone();
|
||||
}
|
||||
|
@ -483,6 +489,7 @@ impl<'a> SyntaxRewriter<'a> {
|
|||
///
|
||||
/// Returns `None` when there are no replacements.
|
||||
pub fn rewrite_root(&self) -> Option<SyntaxNode> {
|
||||
let _p = profile::span("rewrite_root");
|
||||
fn element_to_node_or_parent(element: &SyntaxElement) -> SyntaxNode {
|
||||
match element {
|
||||
SyntaxElement::Node(it) => it.clone(),
|
||||
|
@ -517,6 +524,8 @@ impl<'a> SyntaxRewriter<'a> {
|
|||
}
|
||||
|
||||
fn rewrite_children(&self, node: &SyntaxNode) -> SyntaxNode {
|
||||
let _p = profile::span("rewrite_children");
|
||||
|
||||
// FIXME: this could be made much faster.
|
||||
let mut new_children = Vec::new();
|
||||
if let Some(elements) = self.insertions(&InsertPos::FirstChildOf(node.clone())) {
|
||||
|
@ -533,6 +542,8 @@ impl<'a> SyntaxRewriter<'a> {
|
|||
acc: &mut Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>,
|
||||
element: &SyntaxElement,
|
||||
) {
|
||||
let _p = profile::span("rewrite_self");
|
||||
|
||||
if let Some(replacement) = self.replacement(&element) {
|
||||
match replacement {
|
||||
Replacement::Single(element) => acc.push(element_to_green(element)),
|
||||
|
@ -588,6 +599,8 @@ fn with_children(
|
|||
parent: &SyntaxNode,
|
||||
new_children: Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>,
|
||||
) -> SyntaxNode {
|
||||
let _p = profile::span("with_children");
|
||||
|
||||
let len = new_children.iter().map(|it| it.text_len()).sum::<TextSize>();
|
||||
let new_node = rowan::GreenNode::new(rowan::SyntaxKind(parent.kind() as u16), new_children);
|
||||
let new_root_node = parent.replace_with(new_node);
|
||||
|
|
Loading…
Reference in a new issue