mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 14:51:48 +00:00
feat: Deprioritize completions of private but editable definitions
This commit is contained in:
parent
d7a544e69a
commit
5c41f5d165
12 changed files with 120 additions and 58 deletions
|
@ -18,7 +18,8 @@ fn render(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem>
|
|||
let mut item = CompletionItem::new(SymbolKind::Const, ctx.source_range(), name.clone());
|
||||
item.set_documentation(ctx.docs(const_))
|
||||
.set_deprecated(ctx.is_deprecated(const_) || ctx.is_deprecated_assoc_item(const_))
|
||||
.detail(detail);
|
||||
.detail(detail)
|
||||
.set_relevance(ctx.completion_relevance());
|
||||
|
||||
if let Some(actm) = const_.as_assoc_item(db) {
|
||||
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
|
||||
|
|
|
@ -23,7 +23,7 @@ pub(crate) fn render_variant(
|
|||
}
|
||||
|
||||
fn render(
|
||||
ctx @ RenderContext { completion }: RenderContext<'_>,
|
||||
ctx @ RenderContext { completion, .. }: RenderContext<'_>,
|
||||
local_name: Option<hir::Name>,
|
||||
variant: hir::Variant,
|
||||
path: Option<hir::ModPath>,
|
||||
|
@ -58,18 +58,18 @@ fn render(
|
|||
if variant_kind == hir::StructKind::Tuple {
|
||||
cov_mark::hit!(inserts_parens_for_tuple_enums);
|
||||
let params = Params::Anonymous(variant.fields(db).len());
|
||||
item.add_call_parens(ctx.completion, short_qualified_name, params);
|
||||
item.add_call_parens(completion, short_qualified_name, params);
|
||||
} else if qualified {
|
||||
item.lookup_by(short_qualified_name);
|
||||
}
|
||||
|
||||
let ty = variant.parent_enum(ctx.completion.db).ty(ctx.completion.db);
|
||||
let ty = variant.parent_enum(completion.db).ty(completion.db);
|
||||
item.set_relevance(CompletionRelevance {
|
||||
type_match: compute_type_match(ctx.completion, &ty),
|
||||
..CompletionRelevance::default()
|
||||
type_match: compute_type_match(completion, &ty),
|
||||
..ctx.completion_relevance()
|
||||
});
|
||||
|
||||
if let Some(ref_match) = compute_ref_match(ctx.completion, &ty) {
|
||||
if let Some(ref_match) = compute_ref_match(completion, &ty) {
|
||||
item.ref_match(ref_match);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ pub(crate) fn render_method(
|
|||
}
|
||||
|
||||
fn render(
|
||||
ctx @ RenderContext { completion }: RenderContext<'_>,
|
||||
ctx @ RenderContext { completion, .. }: RenderContext<'_>,
|
||||
local_name: Option<hir::Name>,
|
||||
func: hir::Function,
|
||||
func_type: FuncType,
|
||||
|
@ -75,7 +75,7 @@ fn render(
|
|||
type_match: compute_type_match(completion, &ret_type),
|
||||
exact_name_match: compute_exact_name_match(completion, &call),
|
||||
is_op_method,
|
||||
..CompletionRelevance::default()
|
||||
..ctx.completion_relevance()
|
||||
});
|
||||
|
||||
if let Some(ref_match) = compute_ref_match(completion, &ret_type) {
|
||||
|
|
|
@ -25,7 +25,7 @@ pub(crate) fn render_macro(
|
|||
}
|
||||
|
||||
fn render(
|
||||
ctx @ RenderContext { completion }: RenderContext<'_>,
|
||||
ctx @ RenderContext { completion, .. }: RenderContext<'_>,
|
||||
name: hir::Name,
|
||||
macro_: hir::MacroDef,
|
||||
import_to_add: Option<ImportEdit>,
|
||||
|
@ -53,7 +53,8 @@ fn render(
|
|||
);
|
||||
item.set_deprecated(ctx.is_deprecated(macro_))
|
||||
.set_detail(detail(&completion.sema, macro_))
|
||||
.set_documentation(docs);
|
||||
.set_documentation(docs)
|
||||
.set_relevance(ctx.completion_relevance());
|
||||
|
||||
if let Some(import_to_add) = import_to_add {
|
||||
item.add_import(import_to_add);
|
||||
|
|
|
@ -59,7 +59,10 @@ fn build_completion(
|
|||
def: impl HasAttrs + Copy,
|
||||
) -> CompletionItem {
|
||||
let mut item = CompletionItem::new(CompletionItemKind::Binding, ctx.source_range(), name);
|
||||
item.set_documentation(ctx.docs(def)).set_deprecated(ctx.is_deprecated(def)).detail(&pat);
|
||||
item.set_documentation(ctx.docs(def))
|
||||
.set_deprecated(ctx.is_deprecated(def))
|
||||
.detail(&pat)
|
||||
.set_relevance(ctx.completion_relevance());
|
||||
match ctx.snippet_cap() {
|
||||
Some(snippet_cap) => item.insert_snippet(snippet_cap, pat),
|
||||
None => item.insert_text(pat),
|
||||
|
|
|
@ -41,7 +41,10 @@ fn build_completion(
|
|||
ctx.source_range(),
|
||||
SmolStr::from_iter([&name, " {…}"]),
|
||||
);
|
||||
item.set_documentation(ctx.docs(def)).set_deprecated(ctx.is_deprecated(def)).detail(&literal);
|
||||
item.set_documentation(ctx.docs(def))
|
||||
.set_deprecated(ctx.is_deprecated(def))
|
||||
.detail(&literal)
|
||||
.set_relevance(ctx.completion_relevance());
|
||||
match ctx.snippet_cap() {
|
||||
Some(snippet_cap) => item.insert_snippet(snippet_cap, literal),
|
||||
None => item.insert_text(literal),
|
||||
|
|
|
@ -39,7 +39,8 @@ fn render(
|
|||
let mut item = CompletionItem::new(SymbolKind::TypeAlias, ctx.source_range(), name.clone());
|
||||
item.set_documentation(ctx.docs(type_alias))
|
||||
.set_deprecated(ctx.is_deprecated(type_alias) || ctx.is_deprecated_assoc_item(type_alias))
|
||||
.detail(detail);
|
||||
.detail(detail)
|
||||
.set_relevance(ctx.completion_relevance());
|
||||
|
||||
if let Some(actm) = type_alias.as_assoc_item(db) {
|
||||
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue