Make ModPath's representation private

This commit is contained in:
Jonas Schievink 2021-02-04 20:49:24 +01:00
parent 36191543a6
commit 5d99ba1d9a
18 changed files with 70 additions and 51 deletions

View file

@ -175,7 +175,7 @@ fn compute_fuzzy_completion_order_key(
user_input_lowercased: &str,
) -> usize {
mark::hit!(certain_fuzzy_order_test);
let proposed_import_name = match proposed_mod_path.segments.last() {
let proposed_import_name = match proposed_mod_path.segments().last() {
Some(name) => name.to_string().to_lowercase(),
None => return usize::MAX,
};

View file

@ -63,7 +63,7 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T
if let Some(path) = module.find_use_path(ctx.db, ModuleDef::from(variant)) {
// Variants with trivial paths are already added by the existing completion logic,
// so we should avoid adding these twice
if path.segments.len() > 1 {
if path.segments().len() > 1 {
acc.add_qualified_enum_variant(ctx, variant, path);
}
}

View file

@ -332,9 +332,9 @@ impl Builder {
label = format!("{} ({})", label, import_to_add.import_path);
} else {
let mut import_path_without_last_segment = import_to_add.import_path.to_owned();
let _ = import_path_without_last_segment.segments.pop();
let _ = import_path_without_last_segment.pop_segment();
if !import_path_without_last_segment.segments.is_empty() {
if !import_path_without_last_segment.segments().is_empty() {
lookup = lookup.or_else(|| Some(label.clone()));
insert_text = insert_text.or_else(|| Some(label.clone()));
label = format!("{}::{}", import_path_without_last_segment, label);

View file

@ -57,7 +57,7 @@ pub(crate) fn render_resolution_with_import<'a>(
ScopeDef::ModuleDef(ModuleDef::Function(f)) => f.name(ctx.completion.db).to_string(),
ScopeDef::ModuleDef(ModuleDef::Const(c)) => c.name(ctx.completion.db)?.to_string(),
ScopeDef::ModuleDef(ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db).to_string(),
_ => import_edit.import_path.segments.last()?.to_string(),
_ => import_edit.import_path.segments().last()?.to_string(),
};
Render::new(ctx).render_resolution(local_name, Some(import_edit), resolution).map(|mut item| {
item.completion_kind = CompletionKind::Magic;

View file

@ -45,8 +45,8 @@ impl<'a> EnumRender<'a> {
let (qualified_name, short_qualified_name) = match &path {
Some(path) => {
let full = path.to_string();
let short =
path.segments[path.segments.len().saturating_sub(2)..].iter().join("::");
let segments = path.segments();
let short = segments[segments.len().saturating_sub(2)..].iter().join("::");
(full, short)
}
None => (name.to_string(), name.to_string()),