2021-09-13 13:43:13 +03:00
|
|
|
//! See [`import_on_the_fly`].
|
2022-04-07 20:02:33 +02:00
|
|
|
use hir::{ItemInNs, ModuleDef};
|
2022-03-06 19:01:30 +01:00
|
|
|
use ide_db::imports::{
|
2022-06-18 00:47:28 +02:00
|
|
|
import_assets::{ImportAssets, LocatedImport},
|
2021-01-17 00:53:15 +02:00
|
|
|
insert_use::ImportScope,
|
|
|
|
};
|
2021-03-03 01:26:53 +02:00
|
|
|
use itertools::Itertools;
|
2023-03-13 10:42:24 +02:00
|
|
|
use syntax::{ast, AstNode, SyntaxNode, T};
|
2021-01-16 19:33:36 +02:00
|
|
|
|
|
|
|
use crate::{
|
2022-06-17 10:45:19 +02:00
|
|
|
context::{
|
2022-06-18 00:47:28 +02:00
|
|
|
CompletionContext, DotAccess, PathCompletionCtx, PathKind, PatternContext, Qualified,
|
|
|
|
TypeLocation,
|
2022-06-17 10:45:19 +02:00
|
|
|
},
|
2022-06-20 20:16:40 +02:00
|
|
|
render::{render_resolution_with_import, render_resolution_with_import_pat, RenderContext},
|
2021-01-16 19:33:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
use super::Completions;
|
|
|
|
|
2021-09-13 13:43:13 +03:00
|
|
|
// Feature: Completion With Autoimport
|
|
|
|
//
|
|
|
|
// When completing names in the current scope, proposes additional imports from other modules or crates,
|
|
|
|
// if they can be qualified in the scope, and their name contains all symbols from the completion input.
|
|
|
|
//
|
|
|
|
// To be considered applicable, the name must contain all input symbols in the given order, not necessarily adjacent.
|
|
|
|
// If any input symbol is not lowercased, the name must contain all symbols in exact case; otherwise the containing is checked case-insensitively.
|
|
|
|
//
|
|
|
|
// ```
|
|
|
|
// fn main() {
|
|
|
|
// pda$0
|
|
|
|
// }
|
|
|
|
// # pub mod std { pub mod marker { pub struct PhantomData { } } }
|
|
|
|
// ```
|
|
|
|
// ->
|
|
|
|
// ```
|
|
|
|
// use std::marker::PhantomData;
|
|
|
|
//
|
|
|
|
// fn main() {
|
|
|
|
// PhantomData
|
|
|
|
// }
|
|
|
|
// # pub mod std { pub mod marker { pub struct PhantomData { } } }
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// Also completes associated items, that require trait imports.
|
|
|
|
// If any unresolved and/or partially-qualified path precedes the input, it will be taken into account.
|
|
|
|
// Currently, only the imports with their import path ending with the whole qualifier will be proposed
|
|
|
|
// (no fuzzy matching for qualifier).
|
|
|
|
//
|
|
|
|
// ```
|
|
|
|
// mod foo {
|
|
|
|
// pub mod bar {
|
|
|
|
// pub struct Item;
|
|
|
|
//
|
|
|
|
// impl Item {
|
|
|
|
// pub const TEST_ASSOC: usize = 3;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// fn main() {
|
|
|
|
// bar::Item::TEST_A$0
|
|
|
|
// }
|
|
|
|
// ```
|
|
|
|
// ->
|
|
|
|
// ```
|
|
|
|
// use foo::bar;
|
|
|
|
//
|
|
|
|
// mod foo {
|
|
|
|
// pub mod bar {
|
|
|
|
// pub struct Item;
|
|
|
|
//
|
|
|
|
// impl Item {
|
|
|
|
// pub const TEST_ASSOC: usize = 3;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// fn main() {
|
|
|
|
// bar::Item::TEST_ASSOC
|
|
|
|
// }
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// NOTE: currently, if an assoc item comes from a trait that's not currently imported, and it also has an unresolved and/or partially-qualified path,
|
|
|
|
// no imports will be proposed.
|
|
|
|
//
|
|
|
|
// .Fuzzy search details
|
|
|
|
//
|
|
|
|
// To avoid an excessive amount of the results returned, completion input is checked for inclusion in the names only
|
|
|
|
// (i.e. in `HashMap` in the `std::collections::HashMap` path).
|
|
|
|
// For the same reasons, avoids searching for any path imports for inputs with their length less than 2 symbols
|
|
|
|
// (but shows all associated items for any input length).
|
|
|
|
//
|
|
|
|
// .Import configuration
|
|
|
|
//
|
2022-07-11 15:42:49 +09:00
|
|
|
// It is possible to configure how use-trees are merged with the `imports.granularity.group` setting.
|
2021-09-13 13:43:13 +03:00
|
|
|
// Mimics the corresponding behavior of the `Auto Import` feature.
|
|
|
|
//
|
|
|
|
// .LSP and performance implications
|
|
|
|
//
|
|
|
|
// The feature is enabled only if the LSP client supports LSP protocol version 3.16+ and reports the `additionalTextEdits`
|
|
|
|
// (case-sensitive) resolve client capability in its client capabilities.
|
|
|
|
// This way the server is able to defer the costly computations, doing them for a selected completion item only.
|
|
|
|
// For clients with no such support, all edits have to be calculated on the completion request, including the fuzzy search completion ones,
|
|
|
|
// which might be slow ergo the feature is automatically disabled.
|
|
|
|
//
|
|
|
|
// .Feature toggle
|
|
|
|
//
|
|
|
|
// The feature can be forcefully turned off in the settings with the `rust-analyzer.completion.autoimport.enable` flag.
|
|
|
|
// Note that having this flag set to `true` does not guarantee that the feature is enabled: your client needs to have the corresponding
|
|
|
|
// capability enabled.
|
2022-06-18 00:47:28 +02:00
|
|
|
pub(crate) fn import_on_the_fly_path(
|
|
|
|
acc: &mut Completions,
|
2022-07-20 15:02:08 +02:00
|
|
|
ctx: &CompletionContext<'_>,
|
2022-06-18 00:47:28 +02:00
|
|
|
path_ctx: &PathCompletionCtx,
|
|
|
|
) -> Option<()> {
|
2021-01-05 10:34:03 +02:00
|
|
|
if !ctx.config.enable_imports_on_the_fly {
|
2021-01-16 19:33:36 +02:00
|
|
|
return None;
|
|
|
|
}
|
2022-06-20 17:41:04 +02:00
|
|
|
let qualified = match path_ctx {
|
2022-06-18 00:47:28 +02:00
|
|
|
PathCompletionCtx {
|
2022-06-17 10:45:19 +02:00
|
|
|
kind:
|
2022-06-20 17:41:04 +02:00
|
|
|
PathKind::Expr { .. }
|
2022-06-18 00:47:28 +02:00
|
|
|
| PathKind::Type { .. }
|
|
|
|
| PathKind::Attr { .. }
|
|
|
|
| PathKind::Derive { .. }
|
2022-07-02 16:15:13 +02:00
|
|
|
| PathKind::Item { .. }
|
2022-06-20 17:41:04 +02:00
|
|
|
| PathKind::Pat { .. },
|
2022-06-18 00:47:28 +02:00
|
|
|
qualified,
|
2022-06-17 10:45:19 +02:00
|
|
|
..
|
2022-06-20 17:41:04 +02:00
|
|
|
} => qualified,
|
2022-06-03 20:49:25 +02:00
|
|
|
_ => return None,
|
|
|
|
};
|
2022-06-18 00:47:28 +02:00
|
|
|
let potential_import_name = import_name(ctx);
|
|
|
|
let qualifier = match qualified {
|
|
|
|
Qualified::With { path, .. } => Some(path.clone()),
|
|
|
|
_ => None,
|
|
|
|
};
|
|
|
|
let import_assets = import_assets_for_path(ctx, &potential_import_name, qualifier.clone())?;
|
2022-06-03 20:49:25 +02:00
|
|
|
|
2022-06-18 00:47:28 +02:00
|
|
|
import_on_the_fly(
|
|
|
|
acc,
|
|
|
|
ctx,
|
2022-06-20 17:41:04 +02:00
|
|
|
path_ctx,
|
2022-06-18 00:47:28 +02:00
|
|
|
import_assets,
|
|
|
|
qualifier.map(|it| it.syntax().clone()).or_else(|| ctx.original_token.parent())?,
|
|
|
|
potential_import_name,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-20 17:41:04 +02:00
|
|
|
pub(crate) fn import_on_the_fly_pat(
|
2022-06-18 00:47:28 +02:00
|
|
|
acc: &mut Completions,
|
2022-07-20 15:02:08 +02:00
|
|
|
ctx: &CompletionContext<'_>,
|
2022-06-20 20:16:40 +02:00
|
|
|
pattern_ctx: &PatternContext,
|
2022-06-18 00:47:28 +02:00
|
|
|
) -> Option<()> {
|
|
|
|
if !ctx.config.enable_imports_on_the_fly {
|
|
|
|
return None;
|
|
|
|
}
|
2022-06-20 20:16:40 +02:00
|
|
|
if let PatternContext { record_pat: Some(_), .. } = pattern_ctx {
|
2022-06-20 17:41:04 +02:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2022-06-18 00:47:28 +02:00
|
|
|
let potential_import_name = import_name(ctx);
|
2022-06-20 17:41:04 +02:00
|
|
|
let import_assets = import_assets_for_path(ctx, &potential_import_name, None)?;
|
2022-06-18 00:47:28 +02:00
|
|
|
|
2022-07-02 16:15:13 +02:00
|
|
|
import_on_the_fly_pat_(
|
2022-06-18 00:47:28 +02:00
|
|
|
acc,
|
|
|
|
ctx,
|
2022-06-20 20:16:40 +02:00
|
|
|
pattern_ctx,
|
2022-06-18 00:47:28 +02:00
|
|
|
import_assets,
|
2022-06-20 17:41:04 +02:00
|
|
|
ctx.original_token.parent()?,
|
2022-06-18 00:47:28 +02:00
|
|
|
potential_import_name,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-20 17:41:04 +02:00
|
|
|
pub(crate) fn import_on_the_fly_dot(
|
2022-06-18 00:47:28 +02:00
|
|
|
acc: &mut Completions,
|
2022-07-20 15:02:08 +02:00
|
|
|
ctx: &CompletionContext<'_>,
|
2022-06-20 17:41:04 +02:00
|
|
|
dot_access: &DotAccess,
|
2022-06-18 00:47:28 +02:00
|
|
|
) -> Option<()> {
|
|
|
|
if !ctx.config.enable_imports_on_the_fly {
|
|
|
|
return None;
|
|
|
|
}
|
2022-06-20 17:41:04 +02:00
|
|
|
let receiver = dot_access.receiver.as_ref()?;
|
|
|
|
let ty = dot_access.receiver_ty.as_ref()?;
|
2022-06-18 00:47:28 +02:00
|
|
|
let potential_import_name = import_name(ctx);
|
2022-06-20 17:41:04 +02:00
|
|
|
let import_assets = ImportAssets::for_fuzzy_method_call(
|
|
|
|
ctx.module,
|
|
|
|
ty.original.clone(),
|
|
|
|
potential_import_name.clone(),
|
|
|
|
receiver.syntax().clone(),
|
|
|
|
)?;
|
2022-06-18 00:47:28 +02:00
|
|
|
|
2022-06-20 17:41:04 +02:00
|
|
|
import_on_the_fly_method(
|
2022-06-18 00:47:28 +02:00
|
|
|
acc,
|
|
|
|
ctx,
|
2022-06-20 17:41:04 +02:00
|
|
|
dot_access,
|
2022-06-18 00:47:28 +02:00
|
|
|
import_assets,
|
2022-06-20 17:41:04 +02:00
|
|
|
receiver.syntax().clone(),
|
2022-06-18 00:47:28 +02:00
|
|
|
potential_import_name,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn import_on_the_fly(
|
|
|
|
acc: &mut Completions,
|
2022-07-20 15:02:08 +02:00
|
|
|
ctx: &CompletionContext<'_>,
|
2022-06-20 17:41:04 +02:00
|
|
|
path_ctx @ PathCompletionCtx { kind, .. }: &PathCompletionCtx,
|
2022-06-18 00:47:28 +02:00
|
|
|
import_assets: ImportAssets,
|
|
|
|
position: SyntaxNode,
|
|
|
|
potential_import_name: String,
|
|
|
|
) -> Option<()> {
|
2021-10-28 19:19:30 +02:00
|
|
|
let _p = profile::span("import_on_the_fly").detail(|| potential_import_name.clone());
|
2021-01-16 19:33:36 +02:00
|
|
|
|
2022-04-02 01:42:21 +02:00
|
|
|
if ImportScope::find_insert_use_container(&position, &ctx.sema).is_none() {
|
|
|
|
return None;
|
|
|
|
}
|
2021-02-20 13:53:50 +02:00
|
|
|
|
2021-12-05 15:57:28 +01:00
|
|
|
let ns_filter = |import: &LocatedImport| {
|
2022-06-20 17:41:04 +02:00
|
|
|
match (kind, import.original_item) {
|
2021-12-06 15:51:33 +01:00
|
|
|
// Aren't handled in flyimport
|
2022-03-10 21:22:13 +01:00
|
|
|
(PathKind::Vis { .. } | PathKind::Use, _) => false,
|
2021-12-06 15:51:33 +01:00
|
|
|
// modules are always fair game
|
|
|
|
(_, ItemInNs::Types(hir::ModuleDef::Module(_))) => true,
|
|
|
|
// and so are macros(except for attributes)
|
|
|
|
(
|
2022-06-03 15:41:51 +02:00
|
|
|
PathKind::Expr { .. }
|
|
|
|
| PathKind::Type { .. }
|
|
|
|
| PathKind::Item { .. }
|
2022-06-18 08:58:47 +02:00
|
|
|
| PathKind::Pat { .. },
|
2021-12-06 15:51:33 +01:00
|
|
|
ItemInNs::Macros(mac),
|
2022-03-08 23:52:26 +01:00
|
|
|
) => mac.is_fn_like(ctx.db),
|
2022-07-02 16:15:13 +02:00
|
|
|
(PathKind::Item { .. }, ..) => false,
|
2021-12-06 15:51:33 +01:00
|
|
|
|
2022-05-06 15:44:41 +02:00
|
|
|
(PathKind::Expr { .. }, ItemInNs::Types(_) | ItemInNs::Values(_)) => true,
|
2021-12-05 15:57:28 +01:00
|
|
|
|
2022-06-18 08:58:47 +02:00
|
|
|
(PathKind::Pat { .. }, ItemInNs::Types(_)) => true,
|
|
|
|
(PathKind::Pat { .. }, ItemInNs::Values(def)) => {
|
|
|
|
matches!(def, hir::ModuleDef::Const(_))
|
|
|
|
}
|
2021-12-06 15:51:33 +01:00
|
|
|
|
2022-06-17 14:18:03 +02:00
|
|
|
(PathKind::Type { location }, ItemInNs::Types(ty)) => {
|
|
|
|
if matches!(location, TypeLocation::TypeBound) {
|
2022-04-07 20:02:33 +02:00
|
|
|
matches!(ty, ModuleDef::Trait(_))
|
|
|
|
} else {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
2022-06-03 15:41:51 +02:00
|
|
|
(PathKind::Type { .. }, ItemInNs::Values(_)) => false,
|
2021-12-05 15:57:28 +01:00
|
|
|
|
2022-03-08 23:52:26 +01:00
|
|
|
(PathKind::Attr { .. }, ItemInNs::Macros(mac)) => mac.is_attr(ctx.db),
|
2022-02-02 13:35:46 +01:00
|
|
|
(PathKind::Attr { .. }, _) => false,
|
2022-03-10 21:22:13 +01:00
|
|
|
|
2022-06-17 16:56:21 +02:00
|
|
|
(PathKind::Derive { existing_derives }, ItemInNs::Macros(mac)) => {
|
|
|
|
mac.is_derive(ctx.db) && !existing_derives.contains(&mac)
|
2022-03-10 21:22:13 +01:00
|
|
|
}
|
2022-06-17 16:56:21 +02:00
|
|
|
(PathKind::Derive { .. }, _) => false,
|
2021-12-05 15:57:28 +01:00
|
|
|
}
|
|
|
|
};
|
2022-06-18 00:47:28 +02:00
|
|
|
let user_input_lowercased = potential_import_name.to_lowercase();
|
2021-12-05 15:57:28 +01:00
|
|
|
|
2023-06-05 12:04:23 +03:00
|
|
|
import_assets
|
|
|
|
.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind, ctx.config.prefer_no_std)
|
|
|
|
.into_iter()
|
|
|
|
.filter(ns_filter)
|
|
|
|
.filter(|import| {
|
|
|
|
let original_item = &import.original_item;
|
|
|
|
!ctx.is_item_hidden(&import.item_to_import)
|
|
|
|
&& !ctx.is_item_hidden(original_item)
|
|
|
|
&& ctx.check_stability(original_item.attrs(ctx.db).as_deref())
|
|
|
|
})
|
|
|
|
.sorted_by_key(|located_import| {
|
|
|
|
compute_fuzzy_completion_order_key(&located_import.import_path, &user_input_lowercased)
|
|
|
|
})
|
|
|
|
.filter_map(|import| {
|
|
|
|
render_resolution_with_import(RenderContext::new(ctx), path_ctx, import)
|
|
|
|
})
|
|
|
|
.map(|builder| builder.build(ctx.db))
|
|
|
|
.for_each(|item| acc.add(item));
|
2021-01-16 19:33:36 +02:00
|
|
|
Some(())
|
|
|
|
}
|
|
|
|
|
2022-07-02 16:15:13 +02:00
|
|
|
fn import_on_the_fly_pat_(
|
2022-06-20 20:16:40 +02:00
|
|
|
acc: &mut Completions,
|
2022-07-20 15:02:08 +02:00
|
|
|
ctx: &CompletionContext<'_>,
|
2022-06-20 20:16:40 +02:00
|
|
|
pattern_ctx: &PatternContext,
|
|
|
|
import_assets: ImportAssets,
|
|
|
|
position: SyntaxNode,
|
|
|
|
potential_import_name: String,
|
|
|
|
) -> Option<()> {
|
|
|
|
let _p = profile::span("import_on_the_fly_pat").detail(|| potential_import_name.clone());
|
|
|
|
|
|
|
|
if ImportScope::find_insert_use_container(&position, &ctx.sema).is_none() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
let ns_filter = |import: &LocatedImport| match import.original_item {
|
|
|
|
ItemInNs::Macros(mac) => mac.is_fn_like(ctx.db),
|
|
|
|
ItemInNs::Types(_) => true,
|
|
|
|
ItemInNs::Values(def) => matches!(def, hir::ModuleDef::Const(_)),
|
|
|
|
};
|
|
|
|
let user_input_lowercased = potential_import_name.to_lowercase();
|
|
|
|
|
2023-06-05 12:04:23 +03:00
|
|
|
import_assets
|
|
|
|
.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind, ctx.config.prefer_no_std)
|
|
|
|
.into_iter()
|
|
|
|
.filter(ns_filter)
|
|
|
|
.filter(|import| {
|
|
|
|
let original_item = &import.original_item;
|
|
|
|
!ctx.is_item_hidden(&import.item_to_import)
|
|
|
|
&& !ctx.is_item_hidden(original_item)
|
|
|
|
&& ctx.check_stability(original_item.attrs(ctx.db).as_deref())
|
|
|
|
})
|
|
|
|
.sorted_by_key(|located_import| {
|
|
|
|
compute_fuzzy_completion_order_key(&located_import.import_path, &user_input_lowercased)
|
|
|
|
})
|
|
|
|
.filter_map(|import| {
|
|
|
|
render_resolution_with_import_pat(RenderContext::new(ctx), pattern_ctx, import)
|
|
|
|
})
|
|
|
|
.map(|builder| builder.build(ctx.db))
|
|
|
|
.for_each(|item| acc.add(item));
|
2022-06-20 20:16:40 +02:00
|
|
|
Some(())
|
|
|
|
}
|
|
|
|
|
2022-06-20 17:41:04 +02:00
|
|
|
fn import_on_the_fly_method(
|
|
|
|
acc: &mut Completions,
|
2022-07-20 15:02:08 +02:00
|
|
|
ctx: &CompletionContext<'_>,
|
2022-06-20 17:41:04 +02:00
|
|
|
dot_access: &DotAccess,
|
|
|
|
import_assets: ImportAssets,
|
|
|
|
position: SyntaxNode,
|
|
|
|
potential_import_name: String,
|
|
|
|
) -> Option<()> {
|
2022-06-20 20:16:40 +02:00
|
|
|
let _p = profile::span("import_on_the_fly_method").detail(|| potential_import_name.clone());
|
2022-06-20 17:41:04 +02:00
|
|
|
|
|
|
|
if ImportScope::find_insert_use_container(&position, &ctx.sema).is_none() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
let user_input_lowercased = potential_import_name.to_lowercase();
|
|
|
|
|
|
|
|
import_assets
|
2022-09-20 17:39:17 +03:00
|
|
|
.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind, ctx.config.prefer_no_std)
|
2022-06-20 17:41:04 +02:00
|
|
|
.into_iter()
|
|
|
|
.filter(|import| {
|
|
|
|
!ctx.is_item_hidden(&import.item_to_import)
|
|
|
|
&& !ctx.is_item_hidden(&import.original_item)
|
|
|
|
})
|
|
|
|
.sorted_by_key(|located_import| {
|
|
|
|
compute_fuzzy_completion_order_key(&located_import.import_path, &user_input_lowercased)
|
|
|
|
})
|
|
|
|
.for_each(|import| match import.original_item {
|
|
|
|
ItemInNs::Values(hir::ModuleDef::Function(f)) => {
|
|
|
|
acc.add_method_with_import(ctx, dot_access, f, import);
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
});
|
|
|
|
Some(())
|
|
|
|
}
|
|
|
|
|
2022-07-20 15:02:08 +02:00
|
|
|
fn import_name(ctx: &CompletionContext<'_>) -> String {
|
2022-06-18 00:47:28 +02:00
|
|
|
let token_kind = ctx.token.kind();
|
|
|
|
if matches!(token_kind, T![.] | T![::]) {
|
|
|
|
String::new()
|
|
|
|
} else {
|
|
|
|
ctx.token.to_string()
|
|
|
|
}
|
2021-01-17 00:53:15 +02:00
|
|
|
}
|
|
|
|
|
2022-06-18 00:47:28 +02:00
|
|
|
fn import_assets_for_path(
|
2022-07-20 15:02:08 +02:00
|
|
|
ctx: &CompletionContext<'_>,
|
2022-06-18 00:47:28 +02:00
|
|
|
potential_import_name: &str,
|
|
|
|
qualifier: Option<ast::Path>,
|
|
|
|
) -> Option<ImportAssets> {
|
|
|
|
let fuzzy_name_length = potential_import_name.len();
|
|
|
|
let mut assets_for_path = ImportAssets::for_fuzzy_path(
|
|
|
|
ctx.module,
|
|
|
|
qualifier,
|
|
|
|
potential_import_name.to_owned(),
|
|
|
|
&ctx.sema,
|
|
|
|
ctx.token.parent()?,
|
|
|
|
)?;
|
|
|
|
if fuzzy_name_length < 3 {
|
|
|
|
cov_mark::hit!(flyimport_exact_on_short_path);
|
|
|
|
assets_for_path.path_fuzzy_name_to_exact(false);
|
2021-01-05 10:34:03 +02:00
|
|
|
}
|
2022-06-18 00:47:28 +02:00
|
|
|
Some(assets_for_path)
|
2021-01-05 10:34:03 +02:00
|
|
|
}
|
|
|
|
|
2022-06-18 00:47:28 +02:00
|
|
|
fn compute_fuzzy_completion_order_key(
|
2021-06-08 16:50:10 +02:00
|
|
|
proposed_mod_path: &hir::ModPath,
|
2021-01-16 19:33:36 +02:00
|
|
|
user_input_lowercased: &str,
|
|
|
|
) -> usize {
|
2021-03-08 22:19:44 +02:00
|
|
|
cov_mark::hit!(certain_fuzzy_order_test);
|
2021-02-25 01:06:31 +02:00
|
|
|
let import_name = match proposed_mod_path.segments().last() {
|
2021-11-04 18:12:05 +01:00
|
|
|
Some(name) => name.to_smol_str().to_lowercase(),
|
2021-01-16 19:33:36 +02:00
|
|
|
None => return usize::MAX,
|
|
|
|
};
|
2021-02-25 01:06:31 +02:00
|
|
|
match import_name.match_indices(user_input_lowercased).next() {
|
2021-01-16 19:33:36 +02:00
|
|
|
Some((first_matching_index, _)) => first_matching_index,
|
|
|
|
None => usize::MAX,
|
|
|
|
}
|
|
|
|
}
|