mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Merge #10152
10152: feat: Add completion for raw identifiers r=matklad a=nabakin ![rust_analyzer_pr](https://user-images.githubusercontent.com/894305/132110362-c21b713d-acaf-4a6d-9749-ff812172cbce.gif) Adds support for valid Rust completion of raw identifiers. Previously, code completion of fields made via raw identifiers would not re-insert those raw identifiers, resulting in invalid Rust code. Now, code completion of fields made via raw identifiers do re-insert those raw identifiers, resulting in valid Rust code. The same is true for all code completion instances for fields and compatible Rust identifiers. Co-authored-by: Blake Wyatt <894305+nabakin@users.noreply.github.com>
This commit is contained in:
commit
cbc13ae6bd
1 changed files with 24 additions and 3 deletions
|
@ -16,7 +16,7 @@ use ide_db::{
|
||||||
helpers::{item_name, SnippetCap},
|
helpers::{item_name, SnippetCap},
|
||||||
RootDatabase, SymbolKind,
|
RootDatabase, SymbolKind,
|
||||||
};
|
};
|
||||||
use syntax::TextRange;
|
use syntax::{SyntaxKind, TextRange};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
context::{PathCompletionContext, PathKind},
|
context::{PathCompletionContext, PathKind},
|
||||||
|
@ -91,14 +91,18 @@ pub(crate) fn render_field(
|
||||||
);
|
);
|
||||||
item.set_relevance(CompletionRelevance {
|
item.set_relevance(CompletionRelevance {
|
||||||
type_match: compute_type_match(ctx.completion, ty),
|
type_match: compute_type_match(ctx.completion, ty),
|
||||||
exact_name_match: compute_exact_name_match(ctx.completion, &name),
|
exact_name_match: compute_exact_name_match(ctx.completion, name.as_str()),
|
||||||
..CompletionRelevance::default()
|
..CompletionRelevance::default()
|
||||||
});
|
});
|
||||||
item.kind(SymbolKind::Field)
|
item.kind(SymbolKind::Field)
|
||||||
.detail(ty.display(ctx.db()).to_string())
|
.detail(ty.display(ctx.db()).to_string())
|
||||||
.set_documentation(field.docs(ctx.db()))
|
.set_documentation(field.docs(ctx.db()))
|
||||||
.set_deprecated(is_deprecated)
|
.set_deprecated(is_deprecated)
|
||||||
.lookup_by(name);
|
.lookup_by(name.as_str());
|
||||||
|
let is_keyword = SyntaxKind::from_keyword(name.as_str()).is_some();
|
||||||
|
if is_keyword && !matches!(name.as_str(), "self" | "crate" | "super" | "Self") {
|
||||||
|
item.insert_text(String::from("r#") + name.as_str());
|
||||||
|
}
|
||||||
if let Some(_ref_match) = compute_ref_match(ctx.completion, ty) {
|
if let Some(_ref_match) = compute_ref_match(ctx.completion, ty) {
|
||||||
// FIXME
|
// FIXME
|
||||||
// For now we don't properly calculate the edits for ref match
|
// For now we don't properly calculate the edits for ref match
|
||||||
|
@ -821,6 +825,23 @@ struct ManualVtable { f: fn(u8, u8) }
|
||||||
fn main() -> ManualVtable {
|
fn main() -> ManualVtable {
|
||||||
ManualVtable { f: foo }
|
ManualVtable { f: foo }
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
check_edit(
|
||||||
|
"type",
|
||||||
|
r#"
|
||||||
|
struct RawIdentTable { r#type: u32 }
|
||||||
|
|
||||||
|
fn main() -> RawIdentTable {
|
||||||
|
RawIdentTable { t$0: 42 }
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
struct RawIdentTable { r#type: u32 }
|
||||||
|
|
||||||
|
fn main() -> RawIdentTable {
|
||||||
|
RawIdentTable { r#type: 42 }
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue